On a UNIX system, there is no distinct C/C++ type for UTF8 encoded Unicode strings. Strings of type char are commonly used to represent character strings encoded in UTF8, but care must be used when applying string manipulation functions, specifically with respect to lengths of strings that can be measured in bytes and characters.
Most UNIX system implementations also have a type wchar_t, but it is usually a 32-bit type used for fixed length character encodings such as UTF32, and not UTF8. For such systems, another approach is to use wchar_t internally within the application, and then convert strings of that type to UTF8 and back whenever they are passed to external interfaces such as ODBC Driver for Teradata.
Whenever possible, the SQLWCHAR ODBC character type should be used for Unicode strings instead of the wchar_t type, since SQLWCHAR and wchar_t are not the same on all operating systems.
On a UNIX system, Unicode encoding for strings and data passed to ODBC Driver for Teradata can be changed from the default UTF8 to UTF16 as follows:
- Define SQLWCHARSHORT. For example, add the following to your code:
#define SQLWCHARSHORTSQLCHARSHORT changes definitions of SQL_WCHAR from char* to short * and must be defined before ODBC include files are specified.
- Set the SQL_ATTR_APP_UNICODE_TYPE environment attribute to SQL_DD_CP_UTF16. For example, add the following to your code:
// Specify the unicode encoding for the application. SQL calls and // data are both affected. No other environment variables or // connection options (including DSN options) are needed. rc = SQLSetEnvAttr (m_henv, SQL_ATTR_APP_UNICODE_TYPE, (void *) SQL_DD_CP_UTF16, SQL_IS_INTEGER);