4.3.8 ctdbAddSegmentEx
Add a new extended index segment
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 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 Section 3.3.2.4 "Hidden fields" on page 3-32). 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 functions like ctdbAlterTable. If, for any reason, it is mandatory to use this function, try to follow the example below.ctdbAddSegmentEx does the segment allocation. After the segments, indices, and fields have been defined, the table can be created or altered with ctdbCreateTable or ctdbAlterTable.
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 Section 4.1 "c-treeDB definitions" on page 4-1. Notice that ctdbAddSegmentEx does work with Absolute byte offset segments.
Returns
ctdbAddSegmentEx returns the segment handle on success, or NULL on failure
Example
pMyField1 = ctdbAddField(pMyTable, "Name", CT_FSTRING,32);pMyField2 = 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
|
FairCom Corporation www.faircom.com |