Product Documentation

c-treeDB API API for C

Previous Topic

Next Topic


Add a new index segment to an index (given the table handle, field name, and index number).


CTHANDLE ctdbAddSegmentByName(CTHANDLE Handle, NINT IndexNbr,

pTEXT FieldName, CTSEG_MODE SegMode)


ctdbAddSegmentByName() adds a new index segment to an index, specifying the field by giving the table handle and the field name and specifying the index by giving its number. The operation of adding a segment to the index links the specified index with the specified field in the specified table. When a segment is added with this function, the segment is defined based on an individual full field of a table, using what is known as a record schema. In other words, instead of using a byte offset into the record structure and a length, all you need to do is specify the field of interest and what table it’s in. See the FairCom DB documentation for further information on record schemas.

Use ctdbAddSegmentByNbr() to add a new index segment given the field and index number. Use ctdbAddSegment() to add a new index segment given the index handle. Use ctdbAddSegmentEx() to add a new extended index segment.

ctdbAddSegmentByName() does the segment handle allocation. After the segments, indexes, and fields have been defined, the table can be created or altered with ctdbCreateTable() or ctdbAlterTable(). Segment handle deallocation is automatically handled by ctdbCloseTable() and ctdbCloseAll().

  • Handle [in] the table handle.
  • IndexNbr [in] the index number. The first index is number 0.
  • FieldName [in] the field name.
  • SegMode [in] the Index segment mode. The valid values for the segment modes are: CTSEG_SCHSEG, CTSEG_USCHSEG, CTSEG_VSCHSEG, CTSEG_UVSCHSEG, CTSEG_SCHSRL, described in c-treeDB API definitions. If used with a different segment mode, this call will return error 4047, meaning invalid segment mode. ctdbAddSegmentEx() accepts any segment mode.


ctdbAddSegmentByName() returns the segment handle on success, or NULL on failure


ctdbAddField(pMyTable, "Name", CT_FSTRING, 32);

ctdbAddField(pMyTable, "Balance", CT_SFLOAT, 4);

ctdbAddIndex(pMyTable, "iName", CTINDEX_FIXED, NO, NO);

ctdbAddSegmentByName(pMyTable, 0, "Name", CTSEG_USCHSEG);

RetVal = ctdbCreateTable(pMyTable, "Table1", CTCREATE_NORMAL);

See also

ctdbAddSegmentEx(), ctdbAddSegmentByNbr(), ctdbAddSegment()