UTF16/UTF32 Encoded Unicode Strings: The following paragraph from the Unicode section of Chapter 17, “Programming Considerations,” of Microsoft ODBC 3.0 Programmer's Reference states the ultimate rule regarding the specification of length arguments in Unicode functions:
“Unicode functions that always return or take strings or length arguments are passed as count of-characters. For functions that return length information for server data, the display size and precision are described in number of characters. When a length (transfer size of the data) could refer to string or non-string data, the length is described in octet lengths. For example, SQLGetInfoW will still take the length as count-of-bytes, but SQLExecDirectW will use count-of-characters.”
- UTF8 Encoded Unicode Strings on a UNIX System: UTF8 is the default Unicode encoding for ODBC applications running on a UNIX system. All string length arguments to ODBC interface functions should be specified as count of bytes.
Many ODBC interface functions expect string arguments that specify the length of character string input and output values. While some functions expect Unicode arguments to specify such lengths in bytes, others expect lengths to be specified as character counts. This varies by platform and Unicode encoding.