> I want to use DF to create a table. What are the commands?
>
> I know I need the following:
>
> <cfscript>
> // get the datasource
> ds = request.DataFaucet.getDatasource();
> // get the statement object
> inserter = ds.createtable(); //??
Actually the syntax for creating tables is different. It uses an XML
syntax rather than the functions that are used for the other stuff... I
know, I'm fickle. :) There are samples of the syntax for creating tables,
views, etc. on the "Data Definition Language" page of the docs. But very
basically, it looks like this:
<ddl>
<create name="mytable"><!--- type="table" is default --->
<!--- give it a primary key --->
<col name="mytableid" type="varchar(35)" key="1" />
<!--- give it more columns --->
<col name="columnname" type="nvarchar(50)" required="true" />
</create>
</ddl>
Note that it's "required", not "nullable" -- that way you're not doing
the double-negative disco. :)
Once you have your XML you can either execute it via the datasource like
this:
<cfset ds.parseDDL(myDDL) />
Or there's a custom tag you can use to write the XML inline like this:
<cfmodule template="/datafaucet/ddl.cfm">
<ddl>
<create name="mytable"><!--- type="table" is default --->
<!--- give it a primary key --->
<col name="mytableid" type="varchar(35)" key="1" />
<!--- give it more columns --->
<col name="columnname" type="nvarchar(50)" required="true" />
</create>
</ddl>
</cfmodule>
Here's the doc page on the site:
http://www.datafaucet.com/ddl.cfm
> and yes, this is for what you think it is. I figured I needed to
> create a table. and I thought that I would post it to the DF group so
> that the answer is available for all.
That'd be great. ;) The documentation for DDL is probably a little weak
right now, so that's a good area to shore up.
It's not technically necessary to have the custom tag, since you can use
the Datasource.parseDDL() method directly. But if you want to use the
tag from within the onTap framework either you can use cfmodule and the
/datafaucet mapping
<cfmodule template="/datafaucet/ddl.cfm">...</cfmodule>
Or you can put the tag in your custom tags directories... If you put it
in the /_tap/_customtags/ directory you'll need to add the code for
handling the framework's documentation to keep it from breaking the
custom tag docs. Alternatively I think you can put it in
/_tap/_customtags/local/ if you don't want to mess with the
documentation stuff. I'm not certain I'm remembering that path correctly,
but I believe it's defined in /_tap/_config/mappings/config.cfc
Yeah that's actually a ColdFusion thing rather than a DataFaucet thing
specifically... There's actually even a third way to access custom tags
in CF via the cfimport tag:
<cf:import prefix="df" taglib="/datafaucet" />
<df:ddl>
...
</df:ddl>
All three ways work. I just chose one syntax in particular for the
documentation rather than rehash the CF docs.