XML Data Type Values and Conversions - ODBC Driver for Teradata

ODBC Driver for Teradata® User Guide

Product
ODBC Driver for Teradata
Release Number
17.10
Published
October 2021
Language
English (United States)
Last Update
2021-11-02
dita:mapPath
wxs1608578396899.ditamap
dita:ditavalPath
nkw1500504256726.ditaval
dita:id
B035-2526
lifecycle
previous
Product Category
Teradata Tools and Utilities

ODBC Driver for Teradata supports conversions of XML values to and from both ODBC Character C types (SQL_C_CHAR and SQL_C_WCHAR) and the Binary C type SQL_C_BINARY.

XML data type values retrieved from the database may be complete XML documents, but also non-well-formed text entities, including XML document fragments, such as sequences or atomic values. XML data type values inserted into the database must be XML documents (well-formed).

Teradata recommends converting XML to or from SQL_C_BINARY or SQL_C_WCHAR because it eliminates conversion to a non-Unicode code page used by the application, which can result in conversion errors. The default ODBC C type for SQL_TD_XML is SQL_C_BINARY. SQL_TD_XML values represented as ODBC C types are listed below.

XML Represented As Description
SQL_C_BINARY The value is a sequence of characters encoded in UTF8 regardless of any encoding declaration in the XML text.
SQL_C_CHAR The value is a sequence of characters encoded in the application code page regardless of any encoding declaration in the XML text.
SQL_C_WCHAR The value is a sequence of characters encoded in the Unicode encoding in effect for the application (UTF8 or UTF16 for Linux/Unix. UTF16 for Windows, UTF32 for Apple macOS). The encoding is independent of any encoding declaration in the XML text.

For a given XML document, the recommended ODBC C type for working with the document in ODBC depends on the XML document encoding as determined by the XML declaration in the document. Recommended ODBC C types for XML document encoding are listed below.

XML Document Encoding Declaration Recommended ODBC C Type For Working With The Document in an ODBC Application
Windows Linux/Unix Apple macOS
UTF8 SQL_C_BINARY or SQL_C_WCHAR.

Note that when using SQL_C_WCHAR, the encoding will be UTF16.

SQL_C_BINARY or SQL_C_WCHAR SQL_C_BINARY or SQL_C_WCHAR
UTF16 SQL_C_WCHAR SQL_C_WCHAR with UTF16 Unicode encoding as described in Unicode Character Types. SQL_C_WCHAR
Other SQL_C_CHAR using application code page matching document encoding. SQL_C_CHAR using an application code page matching the XML document encoding. SAL_C_CHAR with locale LC_TYPE setting matching the document encoding.