15.10 - SQL Column Attributes - ODBC Driver for Teradata

ODBC Driver for Teradata User Guide

prodname
ODBC Driver for Teradata
vrm_release
15.10
category
User Guide
featnum
B035-2509-035K

SQLColAttribute supports several Teradata ODBC driver-defined column attributes as the FieldIdentifier argument. Additionally, using SQL_COLUMN_NAME returns the Teradata TITLE (if available) instead of the name because this makes most report writers work more sensibly.

When using SQLColAttribute to obtain driver-defined attribute values the type of the attribute must be specified in the BufferLength argument. In addition, SQLColAttribute returns the value through one of two pointers depending on the type: Integer information is returned in *NumericAttributePtr as a SQLLEN value; all other formats of information are returned in *CharacterAttributePtr. The pointer not being used for a particular attribute should be set to NULL in the call. For example, to obtain the value of the attribute SQL_DESC_TD_ODBC_TYPE:

rc = SQLColAttribute(hstmt, colno, SQL_DESC_TD_ODBC_TYPE, NULL, SQL_IS_SMALLINT, NULL, &NumAttrPtr);

The pointer used for each of the attributes defined by the Teradata ODBC driver is indicated in the list below.

Driver-defined FieldIdentifier values are:

  • SQL_COLUMN_ACTIVITY_TYPE: an integer that specifies the kind of SQL statement executed. Value is returned in NumericAttributePtr.
  • SQL_COLUMN_COST_ESTIMATE: an integer with a cost estimate for running the SQL statement. The value returned represents the time estimate in seconds. Value is returned in NumericAttributePtr.
  • SQL_COLUMN_FORMAT: returns the Teradata FORMAT clause associated with the column. Value is returned in CharacterAttributePtr.
  • SQL_COLUMN_ACTUAL_NAME: the name associated with the result column. This FieldIdentifier value is necessary because the meaning of SQL_COLUMN_NAME has changed. Value is returned in CharacterAttributePtr.
  • SQL_COLUMN_CHARACTER_SET is an integer containing the character set of the column. Value is returned in NumericAttributePtr.
  • SQL_COLUMN_EXPORT_WIDTH is an integer containing the database export width for character columns. Value is returned in NumericAttributePtr.
  • SQL_COLUMN_EXPORT_WIDTH_ADJ is an integer containing the database export width adjustment for character columns. Value is returned in NumericAttributePtr.
  • SQL_COLUMN_EXPORT_BYTES is an integer containing the number of bytes that the database provides for a character column. Value is returned in NumericAttributePtr.
  • SQL_DESC_TD_ODBC_TYPE is an SQLSMALLINT that contains the Teradata ODBC-specific SQL data type code. If multiple database types have the same standard ODBC SQL type, then the Teradata ODBC-specific SQL data type code can be used to distinguish between the types. Value is returned in NumericAttributePtr.
  • For additional information about these attributes, see “SQL Descriptor Fields” on page 103.

    When Making SQLColAttribute Calls

    For an ANSI application (that is, compiled without UNICODE defined), the Driver Manager on the UNIX OS will not convert:

  • SQLColAttribute calls into SQLColAttributeW calls in ODBC Driver for Teradata
  • Output parameters from UTF-8 back to the application code page
  • Because of this, the output parameters from SQLColAttribute are delivered back to the ANSI application in the internal character set used by the driver. If the internal character set is different from the application code page, the application receives data back from SQLColAttribute in a different character set from what was expected.

    This is a problem if, for example, an ANSI application using ISO 8859-1 requests non-ASCII meta data (such as a column name with Danish characters) and the session character set is UTF-8. The application gets the column name back in UTF-8. In general, if an ANSI application uses a Unicode session character set, it gets data back from SQLColAttribute in UTF-8, regardless of the application code page.

    To avoid this problem, use the old SQLColAttributes function (with an 's' at the end).