At times, you might need to get information about the data types that are supported by the data source, for example, precision and scale. You can use the ODBC function SQLGetTypeInfo to do this.
On Windows, you can use ODBC Test to call SQLGetTypeInfo against the ODBC data source to return the data type information. Refer to
Chapter 1 “Diagnostic Tools” in the
DataDirect Connect Series for ODBC Troubleshooting Guide for details about ODBC Test.
On UNIX, Linux, or Windows, an application can call SQLGetTypeInfo. Here is an example of a C function that calls SQLGetTypeInfo and retrieves the information in the form of a SQL result set.
unsigned long columnSize;
SQLINTEGER strlenTypeName,
rc = SQLGetTypeInfo(hstmt, dataType);
rc = SQLBindCol(hstmt, 1, SQL_C_CHAR, &typeName,
(SDWORD)sizeof(typeName), &strlenTypeName);
rc = SQLBindCol(hstmt, 2, SQL_C_SHORT, &sqlDataType,
(SDWORD)sizeof(sqlDataType), &strlenSqlDataType);
rc = SQLBindCol(hstmt, 3, SQL_C_LONG, &columnSize,
(SDWORD)sizeof(columnSize), &strlenColumnSize);
printf ("TypeName DataType ColumnSize\n");
printf ("-------------------- ---------- ----------\n");
ODBC_GetDiagRec(SQL_HANDLE_STMT, hstmt);
if ((rc == SQL_SUCCESS) || (rc == SQL_SUCCESS_WITH_INFO)) {
} while (rc != SQL_NO_DATA);