Fields are what hold the actual record data for each row in a table. Whereas a record could be considered a "row" in a table, a field could be considered a "column" in a table, or a "cell" in a record. The fields are defined at the time of the table creation.
Fields are added to the record definition in the order they are declared. The c-treeDB API also includes a set of functions that will allow a field to be inserted at a certain place in the record definition and fields can also be deleted from the record definition.
Each filed will have a file type (e.g., CT_INTEGER and CT_CHAR in the example below). For more information, see Field Types.
CTTable::AddField() method will add a new field to the end of the record definition.
// create a new table object
CTTable ATable(ADatabase);
// add two fields to the table record definition
ATAble.AddField("Field1", CT_INTEGER, 4);
ATable.AddField("Field2", CT_CHAR, 30);
// create the table
ATable.Create("MyTable", CTCREATE_NORMAL);
CTTable::InsField() inserts a new field before a given field that has already been defined. CTTable::InsField() overloaded methods allow you to specify a field index or a field name to identify the position on the record definition that the new field will be inserted. The first field is number 0, the second field is number 1 and so on.
// create a new table object
CTTable ATable(ADatabase);
// add two fields to the table record definition
ATable.AddField( "Field1", CT_INTEGER, 4);
ATable.AddField( "Field2", CT_CHAR, 30);
ATable.InsField("Field2", "Field3", CT_BOOL, 1);
// create the table
ATable.Create("MyTable", CTCREATE_NORMAL);
CTTable::DelField() deletes a field from the record definition. CTTable::DelField() overloaded methods allow the user to specify a field index or a field name to identify the field to delete. The first field is number 0, the second field is number 1, and so on.
// create a new table object
CTTable ATable(ADatabase);
// add two fields to the table record definition
ATable.AddField( "Field1", CT_INTEGER, 4);
ATable.AddField( "Field2", CT_CHAR, 30);
// delete field2 from record definition
ATable.DelField("Field2");
// create the table
ATable.Create("MyTable", CTCREATE_NORMAL);