Previous Topic

Next Topic

Creating a new Table

Some specific steps must be taken when creating a new table using the c-treeDB API:

  • Allocate a new table handle by calling ctdbAllocTable()
  • Add fields to the table by calling ctdbAddField()
  • Optionally add indices and index segments to the table by calling ctdbAddIndex() to add indices and ctdbAddSegment() to add index segments
  • Optionally, change any of the default table properties
  • Create the table by calling ctdbCreateTable()

The code fragment below creates a new table, with two fields and no indices. Please note that error checking was omitted:

/* allocate a new table handle */
hTable = ctdbAllocTable(hDatabase);
/* add a field
ctdbAddField(hTable, “Field1”, CT_INTEGER, 4);
/* add another field */
ctdbAddField(hTable, “Field1”, CT_CHAR, 30);
/* create the table */
ctdbCreateTable(hTable, “MyTable”, CTCREATE_NORMAL);

"Working with Tables" describes in detail the process of creating a table.