Product Documentation

FairCom DB API for C

Previous Topic

Next Topic

ctdbSetFieldAsUTF16

Sets the field with a Unicode UTF-16 string.

Declaration

CTDBRET ctdbSetFieldAsUTF16(CTHANDLE Handle, NINT FieldNbr, pWCHAR pValue);

Description

ctdbSetFieldAsUTF16() sets the field with a Unicode UTF-16 string. If the underlying field type is not one of the Unicode field types, the UTF-16 string is converted to the appropriate type before the data is stored in the field.

  • Handle is a record handle.
  • FieldNbr is the field number.
  • pValue is the wide (UTF-16) string buffer.

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 FairCom DB API level:

  • SQL type: CHAR
  • CTDB types: CT_FSTRING, CT_FPSTRING, CT_F2STRING, CT_F4STRING

Return

Value

Symbolic Constant

Explanation

0

CTDBRET_OK

No error occurred.

See Appendix A for a complete listing of valid c-tree Plus error values.

Example

CTDBRET AddData(CTHANDLE hRecord, pTEXT str, NINT val)

{

CTDBRET eRet;

WCHAR WStr[32];

if ((eRet = ctdbClearRecord(hRecord)) != CTDBRET_OK)

{

printf("ctdbClearRecord failed with error %d", eRet);

goto Exit;

}

if ((eRet = (CTDBRET)ctdb_u8TOu16(str, WStr, sizeof(WStr))) != CTDBRET_OK)

{

printf("ctdb_u8TOu16 failed with error %d", eRet);

goto Exit;

}

if ((eRet = ctdbSetFieldAsUTF16(hRecord, 0, WStr)) != CTDBRET_OK)

{

printf("ctdbSetFieldAsUTF16 failed with error %d", eRet);

goto Exit;

}

if ((eRet = ctdbSetFieldAsSigned(hRecord, 1, (CTSIGNED)val)) != CTDBRET_OK)

{

printf("ctdbSetFieldAsSigned failed with error %d", eRet);

goto Exit;

}

if ((eRet = ctdbWriteRecord(hRecord)) != CTDBRET_OK)

{

printf("ctdbWriteRecord failed with error %d", eRet);

goto Exit;

}

Exit:

return eRet;

}

SEE ALSO

ctdbGetFieldAsUTF16()

TOCIndex