DataMgr Build 1 Documentation: Seed Data

Seed Data

You can also have DataMgr populate a table with data as it creates it (or ensure that some data always exists in a table). This is also done via the loadXml() method.

Here is an example of ensuring that DataMgr creates data as it creates a table:

<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>
  <data table="Records">
    <row RecordVal="Red" isValueable="true" />
    <row RecordVal="Blue" />
    <row RecordVal="Green" />
  </data>
</tables>

You can add the permanentRows attribute to the data element to have DataMgr ensure that the included values always exist in the database (further examples will only show the data element).

<data table="Records" permanentRows="true">
  <row RecordVal="Red" isValueable="true" />
  <row RecordVal="Blue" />
  <row RecordVal="Green" />
</data>

Since you can also have field names that might not be valid attributes in an XML element, DataMgr has a field element for more flexibility.

<data table="Records">
  <row RecordVal="Red">
    <field name="isValueable" value="true" />
  </row>
  <row RecordVal="Blue" />
  <row RecordVal="Green" />
</data>

As you can see it can be used even though other fields might be defined as attributes in the row element.

You can also get values from other tables.

<data table="Products">
  <row ProdName="Car">
    <field name="catid" reltable="Categories" relfield="catid" CategoryName="Transportation" />
  </row>
</data>

The above example would set the "catid" field to the value of the "catid" field in the Categories table where the "CategoryName" field of that table equals "Transportation" (NULL if no such value can be found).

In the case that the related field can't be used as an attribute in an element, you can use the relfield element.

<data table="Products">
  <row ProdName="Car">
    <field name="catid" reltable="Categories" relfield="catid">
      <relfield name="CategoryName" value="Transportation" />
    </field>
  </row>
</data>

As you can see, this provides you great flexibility to populate data in your tables.