Product Documentation

c-treeDB API API for C

Previous Topic

Next Topic

Reading UTF-16 Field Data

The ctdbGetFieldAsUTF16() function enables applications using the c-treeDB API C API to read data from Unicode field types.

CTDBRET ctdbGetFieldAsUTF16(CTHANDLE Handle, NINT FieldNbr, pWCHAR pValue, VRLEN size);

ctdbGetFieldAsUTF16() retrieves the field data as a Unicode UTF-16 string. If the underlying field type is not one of the Unicode field types, the data is converted to UTF-16 string. Handle is a record handle, FieldNbr is the number of the field, pValue is a pointer to a wide (UTF-16) string buffer and size indicates the size in bytes of the string area. ctdbGetFieldAsUTF16() returns CTDBRET_OK on success.

Previous Topic

Next Topic

Reading UTF-16 C Example

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

{

CTDBRET eRet;

WCHAR WStr[32];

TEXT s[64];

CTSIGNED t;

if ((eRet = ctdbGetFieldAsUTF16(hRecord, 0, WStr, sizeof(WStr))) != CTDBRET_OK)

{

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

goto Exit;

}

if ((eRet = (CTDBRET)ctdb_u16TOu8(WStr, s, sizeof(s))) != CTDBRET_OK)

{

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

goto Exit;

}

if (strcmp(s, str) != 0)

{

printf("UNICODE field contents not the same written");

eRet = CTDBRET_DIFFERENT;

goto Exit;

}

if ((eRet = ctdbGetFieldAsSigned(hRecord, 1, &t)) != CTDBRET_OK)

{

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

goto Exit;

}

if ((NINT)t != val)

{

printf("integer field contents not the same written");

eRet = CTDBRET_DIFFERENT;

goto Exit;

}

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

{

if (eRet == INOT_ERR)

eRet = CTDBRET_OK;

else

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

}

Exit:

return eRet;

}

TOCIndex