In addition to creating new files under the FairCom DB SQL, it is possible to use existing c-tree Plus files under the FairCom DB SQL.
Table Definition Requirements
Note: There is an incompatibility between the use of CT_ARRAY in the current c-tree Plus ODBC Driver and the use of CT_ARRAY in c-treeDB API and c-FairCom DB SQL, including the FairCom DB SQL ODBC Driver.
Note: When c-tree updates a variable-length record, the record offset for the record may change if the updated record size is larger than the original record. In this particular case, the ROWID for this ROW will not be unique, as required by the SQL standard.
Index Definition Requirements
There is one noticeable exception to this rule for segments on string fields that are exactly 1 byte less than the string size. In this scenario, when importing the index, the -z option identifies the situation and makes SQL aware and capable of using the index.
Example: If a field is deleted from the table, and this field is part of an index segment that spans over several fields, c-treeDB API may not know how to adjust the index segment length after the field is deleted from the table. The resulting index definition may not be correct. Tables with unusual characteristics may also not work correctly and the altered table may inherit c-treeDB API characteristics that will prevent them from working in the original application.
Adding DODAs to Existing Files
To use FairCom DB SQL with existing ISAM files that do not already have DODAs, add a DODA to each file. This is most easily done with a developer-created utility that opens each file and calls PutDODA() to insert the required resource into that file. The utility should:
A DODA is a data object definition array. Each element of the array is comprised of a structure of type DATOBJ. Only three of the first four fields of the DATOBJ are required for c-tree Plus.
DATOBJ is defined as follows:
typedef struct {
pTEXT fsymb; /* ptr to symbol name */
pTEXT fadr; /* adr of field in record buffer */
UCOUNT ftype; /* type indicator */
UCOUNT flen; /* field length */
...
} DATOBJ;
Given a data record with the structure:
struct {
TEXT zipcode[10]; /* Zip code */
LONG ssn; /* social security # */
TEXT name[50]; /* name */
} DATA_FORMAT;
The corresponding DODA would be defined as:
DATOBJ doda[] = {
{"ZipCode",NULL,CT_FSTRING,10},
{"SocialSecurity",NULL,CT_INT4},
{"Name",NULL,CT_STRING,50}
};
Note: The two string fields show the difference between fixed-length and variable-length strings. zipcode, CT_FSTRING, takes up a fixed space in the record (10 bytes) and does not require a NULL to terminate the string. name, CT_STRING, takes up a variable amount of space up to a maximum of 50 bytes and is NULL terminated.
Available field types are described in “Record Schema - Field Types” in the c-tree Plus Programmer’s Reference Guide.
PutDODA() assigns the contents of a data object definition array (DODA) to data file datno, which must be opened in ctEXCLUSIVE mode. DODA points to the beginning of the DODA as described above. The numfld parameter indicates how many data fields are in the DODA, three in the example above. PutDoda() has the following syntax:
COUNT PUTDODA(COUNT datno,pDATOBJ doda,UCOUNT numfld)
See the PutDODA() function description in the c-tree Plus Function Reference Guide and “Record Schemas” in the c-tree Plus Programmer’s Reference Guide for additional details. Contact your nearest FairCom office for assistance if needed.