The c-treeDB API record manager has the following functions to read field data from the record buffer:
Function name |
Explanation |
---|---|
ctdbGetFieldAsBool |
Read field data as Boolean value |
ctdbGetFieldAsSigned |
Read field data as signed integer value |
ctdbGetFieldAsUnsigned |
Read field data as unsigned integer value |
ctdbGetFieldAsDate |
Read field data as date value |
ctdbGetFieldAsTime |
Read field data as time value |
ctdbGetFieldAsMoney |
Read field data as money value |
ctdbGetFieldAsFloat |
Read field data as double value |
ctdbGetFieldAsDateTime |
Read field data as time stamp value |
ctdbGetFieldAsString |
Read field data as string value |
ctdbGetFieldAsBinary |
Read field data as binary data |
ctdbGetFieldAsBlob |
Read field data as blob |
ctdbGetFieldAsBigint |
Read field data as signed 64-bit integer |
ctdbGetFieldAsCurrency |
Read field data as currency value |
ctdbGetFieldAsNumber |
Read field data as number (BCD) value |
/* display all field data on screen */
void DisplayData(CTHANDLE hRecord)
{
NINT count = ctdbGetTableFieldCount(hRecord);
NINT i;
TEXT str[256];
for (i = 0; i < count; i++)
{
ctdbGetFieldAsString(hRecord, i, str, sizeof(str));
printf("Field %d: %s\n", i, str);
}
}
The following functions should be used to write fields into the data record buffer:
Function name |
Explanation |
---|---|
ctdbSetFieldAsBool |
update field data as Boolean value |
ctdbSetFieldAsSigned |
update field data as signed integer value |
ctdbSetFieldAsUnsigned |
update field data as unsigned integer value |
ctdbSetFieldAsDate |
update field data as date value |
ctdbSetFieldAsTime |
update field data as time value |
ctdbSetFieldAsMoney |
update field data as money value |
ctdbSetFieldAsFloat |
update field data as double value |
ctdbSetFieldAsDateTime |
update field data as time stamp value |
ctdbSetFieldAsString |
update field data as string value |
ctdbSetFieldAsBinary |
update field data as binary data |
ctdbSetFieldAsBlob |
update field data as blob |
ctdbSetFieldAsBigint |
update field data as signed 64-bit integer |
ctdbSetFieldAsCurrency |
update field data as currency value |
ctdbSetFieldAsNumber |
update field data as number (BCD) value |
/* add new record */
void AddRecord(CTHANDLE hRecord, pTEXT name, pTEXT address, pTEXT phone)
{
ctdbClearRecord(hRecord);
ctdbSetFieldAsString(hRecord, 0, name);
ctdbSetFieldAsString(hRecord, 1, address);
ctdbSetFieldAsString(hRecord, 2, phone);
if (ctdbWriteRecord(hRecord) != CTDBRET_OK)
{
printf("Add record failed\n");
}
}
The ctdbSetFieldAs() functions will also clear the null bit flag for the updated field.
When you invoke one of the ctdbGetFieldAs() or ctdbSetFieldAs() functions, you pass the record handle, the field number and the data you want to read from or write to the data record buffer. The ctdbGetFieldAs() or ctdbSetFieldAs() function names specify the type of the data you are trying to read or write not the underlying field type.
If the type of the field you are trying to read from, or write to, is different than the type of the data specified by the ctdbGetFieldAs() or ctdbSetFieldAs() functions, the record manager will automatically convert the field data type to match the data type of the parameter of passed by one of the ctdbGetFieldAs() or ctdbSetFieldAs() function.
For example, if you are writing a report generator application that displays the fields of a record on screen, you can read all fields in the record buffer with ctdbGetFieldAsString() and the record manager will convert the different field types to string. Boolean field type is converted as "True" or "False", numeric values are converted to string and dates and times use the session wide default date and time formats.