| By Steve Bryant | Article Rating: |
|
| May 13, 2007 06:30 PM EDT | Reads: |
12,036 |
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,036
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. |
||||
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Adobe Reader Sued
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Adobe Flex Developer Earns $100K in New York City
- Adobe LiveCycle Enterprise Suite 2 for Cloud Computing
- Adobe Cans Another 9% of its Workforce
- Adobe Betas Target RIAs and Cloud Computing
- Adobe MAX 2009 Online
- Thinking of Flex in London
- Moyea DVD4Web Converter V2.0 Converts DVD to FLV Fast and Synchronously with Watermarks
- Adobe & Salesforce Cut Cloud Deal
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Eval JavaScript in a Global Context
- Fig Leaf Software to Exhibit at Government IT Conference & Expo
- Is Microsoft as Free as Open Source?
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Adobe Reader Sued
- The Planet Named “Bronze Sponsor” of Cloud Computing Expo
- Microsoft Expression Web Has Got Game
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Bruce Chizen Joins Voyager Capital as Venture Partner
- My Top Seven Wishes From Adobe MAX 2009
- Adobe Flex Developer Earns $100K in New York City
- The Next Programming Models, RIAs and Composite Applications
- Where Are RIA Technologies Headed in 2008?
- Constructing an Application with Flash Forms from the Ground Up
- AJAX World RIA Conference & Expo Kicks Off in New York City
- CFEclipse: The Developer's IDE, Eclipse For ColdFusion
- Personal Branding Checklist
- Adobe Flex 2: Advanced DataGrid
- Has the Technology Bounceback Begun?
- Building a Zip Code Proximity Search with ColdFusion
- i-Technology Viewpoint: We Need Not More Frameworks, But Better Programmers
- The Asynchronous CFML Gateway
- Web Services Using ColdFusion and Apache CXF





































