Create a Table

4 views
Skip to first unread message

rob_parkhill

unread,
Sep 25, 2008, 9:31:21 PM9/25/08
to DataFaucet ORM
Ike,

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(); //??

insterter=??

</cfscript>

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.

Rob

Isaac Dealey

unread,
Sep 25, 2008, 9:58:10 PM9/25/08
to dataf...@googlegroups.com


--
[ ike ] founder - DataFaucet ORM

phone: 781.769.0723

http://www.datafaucet.com


Isaac Dealey

unread,
Sep 25, 2008, 10:18:45 PM9/25/08
to dataf...@googlegroups.com
Sorry about that... hit send before I composed the reply. :)

> 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.

rob_parkhill

unread,
Sep 25, 2008, 10:19:37 PM9/25/08
to DataFaucet ORM
Ike,

So i found the example in the docs, that requires the DDL. I have
written what I want to happen (I hope), but the custom <cf_ddl> tag is
not in my onTap install?

Where can I get the custom Tag from?

Rob

Isaac Dealey

unread,
Sep 25, 2008, 10:32:06 PM9/25/08
to dataf...@googlegroups.com
> So i found the example in the docs, that requires the DDL. I have
> written what I want to happen (I hope), but the custom <cf_ddl> tag is
> not in my onTap install?

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

rob_parkhill

unread,
Sep 25, 2008, 10:33:06 PM9/25/08
to DataFaucet ORM
Ike,

It seems like that worked. The docs say to use the cf_ddl tag as
opposed to the <cfmodule> way. I suggest changing the docs... :)

Rob

Isaac Dealey

unread,
Sep 25, 2008, 11:31:24 PM9/25/08
to dataf...@googlegroups.com
> It seems like that worked. The docs say to use the cf_ddl tag as
> opposed to the <cfmodule> way. I suggest changing the docs... :)

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.

Reply all
Reply to author
Forward
0 new messages