After all fields and indexes have been defined and the table properties set, it is time to create the table by calling CTTable::Create() method. CTTable::Create() method take as parameters the table name and the create mode.
// allocate a new table handle
CTTable ATable(ADatabase);
// add two fields to the table record definition
ATable.AddField("Field1", CT_INTEGER, 4);
ATable.AddField("Field2", CT_CHAR, 30);
// add index 0 - the first index
ATable.AddIndex("MyIndex1", CTINDEX_FIXED, YES, NO);
// add index 0 segments
ATable.AddSegment("MyIndex1", "Field1", CTSEG_SCHSEG);
// add index 1 - the second index
ATable.AddIndex("MyIndex2", CTINDEX_FIXED, NO, NO);
// add index 1 segments
ATable.AddSegment("MyIndex2", "Field2", CTSEG_SCHSEG);
ATable.AddSegment("MyIndex2", "Field1", CTSEG_SCHSEG);
// create the table
try
{
ATable.Create("MyTable", CTCREATE_NORMAL);
}
catch (CTException &err)
{
printf("Create table failed with error %d\n", err.GetErrorCode());
}
The table create modes are a combination of the following valid modes. You can specify mode than one create mode by OR-ing the following constants:
The table below lists the table create modes that are to be used with the ctdbCreateTable() function, and are returned by the ctdbGetTableCreateMode() function.
c-treeDB Table |
c-treeDB .NET |
|
---|---|---|
CTCREATE_NORMAL |
NORMAL_CREATE |
Normal table creation. Use this mode when no other create mode apply. |
CTCREATE_INSERTONLY |
INSERTONLY_CREATE |
This mode creates an "integration table" with only input and read privileges. Integration tables are used for audit trails because updates and deletions are not allowed. |
CTCREATE_PREIMG |
PREIMG_CREATE |
This mode implements transaction processing for a table but does not support automatic file recovery. Files with CTCREATE_PREIMG mode do not take any space in the system transaction logs. |
CTCREATE_TRNLOG |
TRNLOG_CREATE |
With this mode you will get the full benefit of transaction processing, including both atomicity and automatic recovery. If you are not sure of what mode to use, and you do want to use transaction processing, then use this mode. |
CTCREATE_WRITETHRU |
WRITETHRU_CREATE |
This mode forces the operating system to flush all disk cache buffers when a data write occurs. Setting this mode can slow performance of the file handler. On the other hand, it is an important feature to use if you want to ensure that all data writes are put to the disk immediately. It is particularly important if you are in an operating environment where the system crashes a lot, and you are not using transactions. However, this mode does not guarantee that operating system buffers will be flushed as expected. |
CTCREATE_CHECKLOCK |
CHECKLOCK_CREATE |
Tables created with this mode requires a record lock before a record can be updated. If a lock is not obtained, the error code DADV_ERR is returned. |
CTCREATE_NORECBYT |
NORECBYT_CREATE |
Create the table without the RECBYT index. |
CTCREATE_NOROWID |
NOROWID_CREATE |
Create the table without the ROWID index. |
CTCREATE_CHECKREAD |
CHECKREAD_CREATE |
Tables create with this mode requires a record lock as records are read. Obtain at least a read lock on a record before it can be read, otherwise the function will return error code DADV_ERR. |
CTCREATE_HUGEFILE |
HUGEFILE_CREATE |
Create the table with huge file support. With this mode on, tables will support 8-byte addresses for file offsets. |
CTCREATE_NODELFLD |
NODELFLD_CREATE |
This mode indicates that the table is to be created without the $DELFLD$ field support. |
CTCREATE_NONULFLD |
NONULFLD_CREATE |
This mode indicates that the table is to be created without the $NULFLD$ field support. |
CTCREATE_COMPRESS |
COMPRESS_CREATE |
Creates tables with data compression support. When this mode is used, c-treeDB automatically creates the file as variable-length. |
CTCREATE_FLEXREC |
CREATE_FLEXREC |
In V11.5 and later: Create the table with Hot Alter Table support. |