| By Steve Bryant | Article Rating: |
|
| May 13, 2007 06:30 PM EDT | Reads: |
12,051 |
Steve Bryant's ColdFusion Blog
I've written in the past about using DataMgr to make sure that the tables and columns you need exist. I have been asked a few times this week about making sure that those newly created tables are automatically loaded with data.
If you don't know how to have DataMgr create the tables and columns you need, you can watch the "Synchronize Database Structure" presentation now.
To review, in order to have DataMgr create tables and columns in DataMgr, pass XML to the loadXML() method of DataMgr (you can view the CFC doc for syntax).
For example, the following XML:
<tables>
<table name="Examples">
<field ColumnName="SampleID" CF_DataType="CF_SQL_INTEGER" PrimaryKey="true" Increment="true" />
<field ColumnName="SampleName" CF_DataType="CF_SQL_VARCHAR" Length="50" />
<field ColumnName="SampleDescription" CF_DataType="CF_SQL_LONGVARCHAR" />
<field ColumnName="MyDate" CF_DataType="CF_SQL_DATE" />
</table>
</tables>
This would create the "Examples" table with the fields as detailed above.
In order to create this table with two rows of data, you could use the following XML.
<tables>
<table name="Examples">
<field ColumnName="SampleID" CF_DataType="CF_SQL_INTEGER" PrimaryKey="true" Increment="true" />
<field ColumnName="SampleName" CF_DataType="CF_SQL_VARCHAR" Length="50" />
<field ColumnName="SampleDescription" CF_DataType="CF_SQL_LONGVARCHAR" />
<field ColumnName="MyDate" CF_DataType="CF_SQL_DATE" />
</table>
<data table="Examples">
<row SampleName="Bob" SampleDescription="This is the description of Bob." />
<row SampleName="Coca-Cola" SampleDescription="Taste tests show this isn't as popular as Pepsi, but ads make people think it tastes better." />
</data>
</tables>
DataMgr will also let you use column names that are not normally valid in most databases. For example, you could have a column named "Sample Name" (with a space). The above XML format will not, of course, support that column name. DataMgr can support it with a slightly more verbose syntax.
<tables>
<table name="Examples">
<field ColumnName="SampleID" CF_DataType="CF_SQL_INTEGER" PrimaryKey="true" Increment="true" />
<field ColumnName="Sample Name" CF_DataType="CF_SQL_VARCHAR" Length="50" />
<field ColumnName="SampleDescription" CF_DataType="CF_SQL_LONGVARCHAR" />
<field ColumnName="MyDate" CF_DataType="CF_SQL_DATE" />
</table>
<data table="Examples">
<row>
<field name="Sample Name" value="Bob" />
<field name="SampleDescription" value="This is the description of Bob." />
</row>
<row>
<field name="Sample Name" value="Coca-Cola" />
<field name="SampleDescription" value="Taste tests show this isn't as popular as Pepsi, but ads make people think it tastes better." />
</row>
</data>
</tables>
It is also possible that you might have some data that you want to ensure will always be available in the table (even if it isn't empty). To do that, you can use the "permanentRows" attribute:
<tables>
<table name="categories">
<field ColumnName="CatID" CF_DataType="CF_SQL_INTEGER" PrimaryKey="true" Increment="true" />
<field ColumnName="CatName" CF_DataType="CF_SQL_VARCHAR" Length="50" />
</table>
<data table="categories" permanentRows="true">
<row CatName="Coats" />
<row CatName="Shoes" />
</data>
</tables>
DataMgr will use this data to ensure that the categories of "Coats" and "Shoes" always exist (but without adding duplicates).
You may also want to include relational data (products for Coats and Shoes, for example):
<tables>
<table name="categories">
<field ColumnName="CatID" CF_DataType="CF_SQL_INTEGER" PrimaryKey="true" Increment="true" />
<field ColumnName="CatName" CF_DataType="CF_SQL_VARCHAR" Length="50" />
</table>
<table name="products">
<field ColumnName="Prod" CF_DataType="CF_SQL_INTEGER" PrimaryKey="true" Increment="true" />
<field ColumnName="CatID" CF_DataType="CF_SQL_INTEGER" />
<field ColumnName="ProdName" CF_DataType="CF_SQL_VARCHAR" Length="50" />
</table>
<data table="categories" permanentRows="true">
<row CatName="Coats" />
<row CatName="Shoes" />
</data>
<data table="products">
<row ProdName="Air Jordan's">
<field name="CatID" reltable="categories" relfield="CatID" CatName="Shoes" />
</row>
<row ProdName="The Ambassador">
<field name="CatID" reltable="categories" relfield="CatID" CatName="Coats" />
</row>
</data>
</tables>
In the above example, I related the data by one field: "CatName", but I could have used multiple fields if I wanted. If the CatName field was an invalid field name, like "Cat Name", the above syntax would fail. So, the final example covers that unfortunate situation:
<tables>
<table name="categories">
<field ColumnName="CatID" CF_DataType="CF_SQL_INTEGER" PrimaryKey="true" Increment="true" />
<field ColumnName="Cat Name" CF_DataType="CF_SQL_VARCHAR" Length="50" />
</table>
<table name="products">
<field ColumnName="Prod" CF_DataType="CF_SQL_INTEGER" PrimaryKey="true" Increment="true" />
<field ColumnName="CatID" CF_DataType="CF_SQL_INTEGER" />
<field ColumnName="ProdName" CF_DataType="CF_SQL_VARCHAR" Length="50" />
</table>
<data table="categories">
<row>
<field name="Cat Name" value="Coats" />
</row>
<row>
<field name="Cat Name" value="Shoes" />
</row>
</data>
<data table="products">
<row ProdName="Air Jordan's">
<field name="CatID" reltable="categories" relfield="CatID">
<relfield name="Cat Name" value="Shoes" />
</field>
</row>
<row ProdName="The Ambassador">
<field name="CatID" reltable="categories" relfield="CatID">
<relfield name="Cat Name" value="Coats" />
</field>
</row>
</data>
</tables>
Keep in mind, that the first example will cover most situations. The options are available, however, to have DataMgr ensure that the table structure and data that you need for your application are available.
I know that many of my recent entries have been covering features new to the upcoming DataMgr 2 . This isn't one of them. You can use this functionality right now.
Feel free to download DataMgr as use it for any purpose.
Published May 13, 2007 Reads 12,051
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Steve Bryant
Steve Bryant is the founder and CEO of Bryant Web Consulting LLC (www.bryantwebconsulting.com) and teaches ColdFusion at Breakaway Interactive (www.breakawayinteractive.com). He got his BA in philosophy at Oklahoma State University. Steve, one of the top ColdFusion developers in the country, still has no idea how that led to a career in Web development. Steve blogs at steve.coldfusionjournal.com as one of CFDJ's published bloggers.
![]() |
SYS-CON Australia News Desk 10/30/06 05:46:15 PM EST | |||
I've written in the past about using DataMgr to make sure that the tables and columns you need exist. I have been asked a few times this week about making sure that those newly created tables are automatically loaded with data. If you don't know how to have DataMgr create the tables and columns you need, you can watch the 'Synchronize Database Structure' presentation now. |
||||
![]() |
Enterprise Open Source News Desk 10/30/06 04:05:45 PM EST | |||
I've written in the past about using DataMgr to make sure that the tables and columns you need exist. I have been asked a few times this week about making sure that those newly created tables are automatically loaded with data. If you don't know how to have DataMgr create the tables and columns you need, you can watch the 'Synchronize Database Structure' presentation now. |
||||
- Kindle 2 vs Nook
- Cloud Computing on Gartner's Top 10 List and SYS-CON Events' 2010 Calendar
- Confessions of a Ulitzer Addict
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Moving Your RIA Apps into the Cloud: Seven Challenges
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Windows 7 – Microsoft’s First Step to the Cloud
- Ulitzer Provides a Powerful Social Journalism Platform
- Jill Tummler Singer, Deputy CIO of CIA, Keynotes at GovIT Expo
- Open Source Mobile Cloud Sync and Push Email
- Kindle 2 vs Nook
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing on Gartner's Top 10 List and SYS-CON Events' 2010 Calendar
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- US Post Office Hops a Ride on NetSuite’s Cloud
- Moving Your RIA Apps into the Cloud: Seven Challenges
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Building a Drag-and-Drop Shopping Cart with AJAX
- What Is AJAX?
- Google Maps! AJAX-Style Web Development Using ASP.NET
- Flashback to January 2006: Exclusive SYS-CON.TV Interviews on "OpenAjax Alliance" Announcement
- AJAXWorld Conference & Expo to Take Place October 2-4, 2006, at the Santa Clara Convention Center, California
- AJAX Sponsor Webcasts Are Now Available at AJAXWorld Website
- How and Why AJAX, Not Java, Became the Favored Technology for Rich Internet Applications
- "Real-World AJAX" One-Day Seminar Arrives in Silicon Valley
- AJAXWorld University Announces AJAX Developer Bootcamp
- AJAX Support In JadeLiquid WebRenderer v3.1
- Where Are RIA Technologies Headed in 2008?
- Struts Validations Framework Using AJAX






































