UNIX/Linux - ODBC Driver for Teradata

ODBC Driver for Teradata® User Guide

Product
ODBC Driver for Teradata
Release Number
16.20
Published
August 2020
Language
English (United States)
Last Update
2020-08-25
dita:mapPath
fxv1527114222338.ditamap
dita:ditavalPath
Audience_PDF_product_legacy_odbc_include.ditaval
dita:id
B035-2526
lifecycle
previous
Product Category
Teradata Tools and Utilities

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:

  1. Define SQLWCHARSHORT. For example, add the following to your code:

    #define SQLWCHARSHORT

    SQLCHARSHORT changes definitions of SQL_WCHAR from char* to short * and must be defined before ODBC include files are specified.
  2. 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);