Product Documentation

c-treeDB API API for C

Previous Topic

Next Topic

ctdbAddSegmentEx

Add a new extended index segment to an index, using a byte offset into the record structure and a length.

Declaration

CTHANDLE ctdbAddSegmentEx(CTHANDLE Handle, NINT offset, NINT length,

CTSEG_MODE SegMode)

Description

ctdbAddSegmentEx() adds a new extended index segment given the index handle and the segment offset. A segment is extended if it is based on the segment offset. The operation of adding a segment links the index with the field in the table. To add a segment with this function, the segment may be defined based on partial individual fields, using offsets to indicate the segment beginning and extension.

Note: The offset should account for the fields that are created automatically (unless disabled): $DELFLD$ (4 bytes to account for a deleted record), $NULFLD$ (for each user defined field, c-treeDB API uses 1 bit to indicate if a null value in the field is valid - the size will be adjusted to the next byte), and $ROWID$ (8 bytes to account for the automatic auto-increment record - see the discussion on ROWID in Hidden fields). This variation makes it difficult to predict the correct offset of each user defined offset. FairCom strongly recommends the use of the regular functions (ctdbAddSegment(), ctdbAddSegmentByName() or ctdbAddSegmentByNbr()). The use of the extended segments may even prevent the use of advanced c-treeDB API functions like ctdbAlterTable(). If, for any reason, it is mandatory to use this function, try to follow the example below.

ctdbAddSegmentEx() 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().

Use ctdbIsExtSegment() to verify if the segment mode is one of the extended modes.

  • Handle [in] - the index handle.
  • offset [in] - the absolute byte offset.
  • length [in] - the segment length in bytes.
  • SegMode [in] - the Index segment mode. The valid values for the segment modes are listed in c-treeDB API definitions. Notice that ctdbAddSegmentEx() does work with Absolute byte offset segments.

Returns

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

Example


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

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

ctdbCreateTable(pMyTable,"Table1",CTCREATE_NORMAL);

ctdbOpenTable(pMyTable1, "MyTable3", CTOPEN_EXCLUSIVE);


pMyRec1 = ctdbAllocRecord(pMyTable1);

ctdbFirstRecord(pMyRec1);

fld_offset = ctdbGetFieldOffset(pMyRec1, 0);


pMyIndex = ctdbAddIndex(pMyTable1, "MyTable2", 0, 1, 1);

pMyIseg = ctdbAddSegmentEx(pMyIndex, fld_offset, 32, CTSEG_UREGSEG);

ctdbAlterTable(pMyTable1, 0);

See also

ctdbAllocSegment(), ctdbAddSegment(), ctdbInsSegmentEx(), ctdbAddSegmentByName(), ctdbAddSegmentByNbr(), ctdbGetFieldOffset(), ctdbIsExtSegment()

TOCIndex