Product Documentation

c-treeDB API API for C

Previous Topic

Next Topic


Set field as CTSTRING type value.


CTDBRET ctdbSetFieldAsString(CTHANDLE Handle, NINT FieldNbr,



ctdbSetFieldAsString() sets a field as CTSTRING type value. To set a CT_BOOL field, the value being set must be equal to "TRUE" or "FALSE", case insensitive, otherwise, the function will return CTDBRET_CANTCONVERT (4042). Use ctdbGetFieldAsString() to retrieve a field as CTSTRING.

  • Handle [in] the record handle.
  • FieldNbr [in] the field number to be set. To retrieve the field number given the field name, use ctdbGetFieldNumberByName().
  • Value [in] the CTSTRING value to set to the field.

Beginning with V12.5, this function will fail with CTDBRET_TOOBIG(4043) if the input value exceeds the field length.

Truncation of Values (behavior before V12.5)

The SetFieldAs family of functions behave differently for fixed-length fields vs. variable-length fields:

Variable-length Fields - If the value passed to the SetFieldAs function exceeds the size of the field, it will be stored in the field in its entirety without truncation. Variable-length fields are allowed to exceed the declared field size. If truncation is desired, it will be necessary to check the size of the value and truncate it before passing it to the function. Because SQL cannot handle string fields that are longer than the set limit, your application will need logic to enforce the limit if the table will be opened with SQL.

Fixed-length Fields - If the value passed to the SetFieldAs function exceeds the size of the field, it will be truncated to the length of the field. The following types of fields are truncated at the c-treeDB API level:

  • SQL type: CHAR


ctdbSetFieldAsString() returns CTDBRET_OK if successful, or the c-tree error code on failure. Error CTDBRET_CANTCONVERT (4042) indicate Value can't be converted to the specified field type.

See also

ctdbAllocRecord(), ctdbGetFieldAsString(), ctdbGetFieldNumber()