|Subscribe to DataMgr|
|Visit this group|
You can use DataMgr to have your code ensure that it has the database structure that it needs. This is much easier and more flexible than the creation of SQL scripts. DataMgr will only add tables that are missing and can add any missing columns to existing tables. Instead of writing SQL script to encompass every new installation or upgrade, DataMgr will compare the existing database structure to the one you need and add tables and columns as needed.
In order to tell DataMgr about your database structure, you can use an XML format for that purpose and pass it into the loadXml method. You can find the XML Schema for that format here:
You can also use the getXML() method to see the XML that would be used to define a table that DataMgr has in memory.
DataMgr defines data types using the same values that you would find in cfqueryparam. This helps DataMgr use cfqueryparam as well as ensuring that it is database-agnostic. DataMgr has an internal mapping to map CF_SQL_TYPE to a database data type (defined in the CFC for that database to make it easy to add a new database).
To define a database schema in DataMgr, use the loadXML method. It has three arguments:
Here is a very brief example:
<tables> <table name="Records"> <field ColumnName="RecordID" CF_DataType="CF_SQL_INTEGER" PrimaryKey="true" Increment="true" /> <field ColumnName="RecordVal" CF_DataType="CF_SQL_VARCHAR" Length="80" /> <field ColumnName="RecordDescrip" CF_DataType="CF_SQL_LONGVARCHAR" /> <field ColumnName="isValueable" CF_DataType="CF_SQL_BIT" Default="false" /> </table> </tables>
As you can see, DataMgr will let you define primary keys as well as define an autonumber field (which will be handled by an implementation specific to the database being used). Several other data types are available in DataMgr as well.
Note that you can also define field individually using the setColumn() method if you don't want to use the XML approach (argument names match the attributes of the field tag in the XML).