The definition of each of the fields comprising a record can be stored in the data file itself if the data file has not disabled RESOURCE support. The advantage of storing the schema is that applications can use this information without any outside information. Further, c-tree can use field numbers to specify key segments if the schema is stored in the file, enabling flexible key segment definitions.
An application can store the schema in a file directly by use of the PutDODA() function. A DODA is a data object definition array. Each element of the array is comprised of a structure of type DATOBJ which is typedefed in ctport.h. Only three of the first four fields of the DATOBJ are required for the PutDODA() call. 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 in bytes */
...
} DATOBJ;
Given a data record with 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: zipcode is considered to take up a fixed space in the record, CT_FSTRING, while name takes up a variable amount of space, CT_STRING, up to a maximum of 50 bytes.
Notes when using a DATOBJ with the r-tree Report Generator
{NULL,NULL,0,0,-1}
A DODA in this form can be used by PutDODA(), however, the terminating entry shown above is not counted as one of the fields unless accounted for in the last parameter of the PutDODA() function. See PutDODA for details.