Retrieving data type information
- Last Updated: November 20, 2024
- 1 minute read
- Hybrid Data Pipeline
- Version 5.0
- Documentation
At times, you might need to get information about the data types that are
supported by the cloud data store, 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. See ODBC driver troubleshooting for details about
ODBC Test.
On 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.
void ODBC_GetTypeInfo(SQLHANDLE hstmt, SQLSMALLINT dataType)
{
RETCODE rc;
// There are 19 columns returned by SQLGetTypeInfo.
// This example displays the first 3.
// Check the ODBC 3.x specification for more information.
// Variables to hold the data from each column
char typeName[30];
short sqlDataType;
SQLINTEGER columnSize;
SQLLEN strlenTypeName,
strlenSqlDataType,
strlenColumnSize;
rc = SQLGetTypeInfo(hstmt, dataType);
if (rc == SQL_SUCCESS) {
// Bind the columns returned by the SQLGetTypeInfo result set.
rc = SQLBindCol(hstmt, 1, SQL_C_CHAR, &typeName,
sizeof(typeName), &strlenTypeName);
rc = SQLBindCol(hstmt, 2, SQL_C_SHORT, &sqlDataType,
sizeof(sqlDataType), &strlenSqlDataType);
rc = SQLBindCol(hstmt, 3, SQL_C_LONG, &columnSize,
sizeof(columnSize), &strlenColumnSize);
// Print column headings
printf ("TypeName DataType ColumnSize\n");
printf ("-------------------- ---------- ----------\n");
do {
// Fetch the results from executing SQLGetTypeInfo
rc = SQLFetch(hstmt);
if (rc == SQL_ERROR) {
// Procedure to retrieve errors from the SQLGetTypeInfo function
ODBC_GetDiagRec(SQL_HANDLE_STMT, hstmt);
break;
}
// Print the results
if ((rc == SQL_SUCCESS) || (rc == SQL_SUCCESS_WITH_INFO)) {
printf ("%-30s %10i %10u\n", typeName, sqlDataType, columnSize);
}
} while (rc != SQL_NO_DATA);
}
}