ctdbInsField
Declaration
CTHANDLE ctdbInsField(CTHANDLE Handle, NINT Index, pTEXT FieldName,
CTDBTYPE FieldType, VRLEN FieldLength)
Description
ctdbInsField() inserts a new field into a table before the field number given by the Index parameter. This is implemented as follows: the field that is currently at position Index, and any fields "above" it (with higher field numbers than Index) will be shifted upwards (have one added to their field numbers). This frees up position Index, which will then be occupied by the new field. See the code below for an example. This function handles the field handle allocation. Field handle deallocation is automatically handled by ctdbCloseTable() and ctdbCloseAll(). Use ctdbInsFieldByName() to insert a field in a table in a position specified by name. Use ctdbAddField() to add a field to the end of the table. Use ctdbDelField() and ctdbDelFieldByName() to delete fields from a table. ctdbInsField() does the field handle allocation. After the segments, indexes, and fields have been defined, the table can be created or altered with ctdbCreateTable() or ctdbAlterTable().
Returns
ctdbInsField() returns a field handle on success, or NULL on failure.
Example
/* allocate a new table handle */
CTHANDLE hTable = ctdbAllocTable(hDatabase);
/* add two fields to the table record definition */
ctdbAddField(hTable, "FirstField", CT_INTEGER, 4); /* This is field #0 */
ctdbAddField(hTable, "SecondField", CT_CHAR, 30); /* This is field #1 (for now!) */
/* insert a field into the location previously occupied by field #1 ("SecondField") */
ctdbInsField(hTable, 1, "ThirdField", CT_BOOL, 1);
/* create the table */
ctdbCreateTable(hTable, "MyTable", CTCREATE_NORMAL);
The fields in the table are now as follows: Field #0="FirstField". Field #1="ThirdField". Field #2="SecondField".
See also
ctdbAllocTable(), ctdbAddField(), ctdbInsFieldByName(), ctdbDelField(), ctdbDelFieldByName(), ctdbMoveField()