Product Documentation

c-treeDB API for C++ - Developers Guide

Previous Topic

Next Topic

CTField::SetFieldDefaultValue

Sets the field default value.

Declaration

void CTField::SetFieldDefaultValue(const CTString& value);

void CTField::SetFieldDefaultValue(pTEXT value, VRLEN length);

Description

  • value is a string with the default value. No checks are made to make sure the default value matches the correct field type. The caller is responsible for passing the appropriate value.
  • length is the length of string. You must pass a proper length of the string.

CTField::SetFieldDefaultValue() sets the field default value. The default value of a field is used during an alter table operation when a full table rebuild is performed. During a full alter table rebuild, and after the old record buffer data is moved to the new record buffer, the new record buffer is scanned and if a NULL field is found and that NULL field has a default value, the default value is copied to the field buffer.

The field default value is kept as a string representation of the data. It is recommended that numeric data should be converted to string using one of the rich set of c-treeDB data conversion functions.

Date values should be converted to string using the default date type value. The default date type value can be retrieved by calling CTField::GetFieldDefaultDateType() method. By default, the date type is CTDATE_MDCY.

Time values should be converted to string using the default time type value. The default time type value can be retrieved by calling CTField::GetFieldDefaultTimeType() function. By default, the time type is CTTIME_HMS.

Time stamp values should be converted to string using the default date type and time type values as described above.

Return

void

Example


// set the default value of country field */

try

{

CTField hField = hTable.GetField("country"));

hField.SetFieldDefaultValue("USA");

}

catch (CTException &err)

{

printf("SetFieldDefaultValue failed\n");

}

See Also

SetFieldDefaultValue(), GetFieldDefaultValue(), ClearFieldDefaultValue(), IsFieldDefaultValueSet(), ClearAllFieldDefaultValue(), SetFieldDefaultDateTimeType(), GetFieldDefaultDateType(), GetFieldDefaultTimeType()

TOCIndex