Product Documentation

c-treeDB API API for C

Previous Topic

Next Topic


c-treeDB API maintains extended field information that is not present in the DODA object, but is necessary for optimal FairCom DB SQL operation. Each DODA entry describes the field name, the field offset in the record buffer, the field type and length, but for optimal SQL operation we also need additional information such as the field precision, scale and if the field allows NULL values.

A field precision is the total number of digits necessary to represent the value, while the field scale is the number of digits to the left of the decimal point. For example CT_NUMBER fields have a precision of 32 and scale from 0 to 32. CT_INT4 fields have precision of 10 and scale of 0. A NULL value for a field indicates that the field has no value (i.e., no value was assigned to the field when the record was written to the table.)

A CTDB_ON_TABLE_GET_EXT_INFO callback is invoked after a FairCom DB data and index files are open and the CTDB_ON_TABLE_OPEN and CTDB_ON_TABLE_GET_SCHEMA, CTDB_ON_TABLE_GET_DODA and CTDB_ON_TABLE_GET_RECLEN callbacks have been invoked. This callback is also invoked after the c-treeDB API open table code has tried to load the extended field information resource.

You can use the CTDB_ON_TABLE_GET_EXT_INFO callback event to add new, or modify existing, extended field information kept by the table handle. See the example below to see how to modify the extended field information. The handle passed to this callback is always a table handle and you can safely typecast the table handle to a pCTDBTABLE structure pointer.

c-treeDB API C API Example

struct extinfo_tag


CTBOOL nonull; /* YES = no NULL values accepted */

COUNT fprec; /* field precision */

COUNT fscale; /* field scale */

} extinfo [] =


{YES, 10, 0}, /* "id", 0, CT_INT4, 4 */

{NO, 5, 0}, /* "who", 4, CT_INT2, 2 */

{NO, 8, 0}, /* "when", 8, CT_TIMES, 8 */

{NO, 0, 0} /* "text", 16, CT_STRING, 0 */


CTDBRET ctdbDECL OnTableGetExtInfo(CTHANDLE Handle)




if (!pTable)




NINT count = (pTable->fields) ? pTable->fields->count : 0;


for (i = 0; i < count; i++)


pCTDBFIELD pField = (pCTDBFIELD)pTable->fields->list[i];

if (pField)


pField->nonull = extinfo[i].nonull;

pField->fprec = extinfo[i].fprec;

pField->fscale = extinfo[i].fscale;




return Retval;