Product Documentation

c-treeDB API for C++ - Developers Guide

Previous Topic

Next Topic

Reading and writing field data to a record buffer

The c-treeDB CTRecord class has the following methods to read field data from the record buffer:

Function name

Explanation

GetFieldAsBool

Read field data as Boolean value

GetFieldAsSigned

Read field data as signed integer value

GetFieldAsUnsigned

Read field data as unsigned integer value

GetFieldAsDate

Read field data as date value

GetFieldAsTime

Read field data as time value

GetFieldAsMoney

Read field data as money value

GetFieldAsFloat

Read field data as double value

GetFieldAsDateTime

Read field data as time stamp value

GetFieldAsString

Read field data as string value

GetFieldAsBinary

Read field data as binary data

GetFieldAsBlob

Read field data as blob

GetFieldAsBigint

Read field data as signed 64 bit integer

GetFieldAsCurrency

Read field data as currency value

GetFieldAsNumber

Read field data as number (BCD) value

// display all field data on screen

void DisplayData(CTTable &ATable, CTRecord &ARecord)

{

NINT count = ATable.GetFieldCount();

NINT i;

CTString str;

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

{

ARecord.GetFieldAsString(i, str);

printf("Field %d: %s\n", i, str.c_str());

}

}

The following functions should be used to write fields into the data record buffer:

Function

Explanation

SetFieldAsBool

update field data as Boolean value

SetFieldAsSigned

update field data as signed integer value

SetFieldAsUnsigned

update field data as unsigned integer value

SetFieldAsDate

update field data as date value

SetFieldAsTime

update field data as time value

SetFieldAsMoney

update field data as money value

SetFieldAsFloat

update field data as double value

SetFieldAsDateTime

update field data as time stamp value

SetFieldAsString

update field data as string value

SetFieldAsBinary

update field data as binary data

SetFieldAsBlob

update field data as blob

SetFieldAsBigint

update field data as signed 64 bit integer

SetFieldAsCurrency

update field data as currency value

SetFieldAsNumber

Read field data as number (BCD) value

// add new record

void AddRecord(CTRecord &ARecord, const CTString& name, const CTString& address, const CTString& phone)

{

// clear the record buffer

ARecord.Clear();


// populate the record buffer with field data

ARecord.SetFieldAsString(0, name);

ARecord.SetFieldAsString(1, address);

ARecord.SetFieldAsString(2, phone);


// add the new record

ARecord.Write();

}

The SetFieldAs...() methods will also clear the null bit flag for the updated field.

When you invoke one of the GetFieldAs...() or SetFieldAs...() methods, you pass the field number or field name and the data you want to read from or write to the data record buffer.

If the type of the field you are trying to read from, or write to, is different to the type of the data specified by the GetFieldAs...() or SetFieldAs...() methods, the record manager will automatically convert the field data type to match the data type of the parameter of passed by one of the GetFieldAs...() or SetFieldAs...() method.

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 GetFieldAsString() 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.

TOCIndex