Data conversion
DB2® ODBC manages the transfer and any required conversion of data between the application and the database server. However, not all data conversions are supported.
Before the data transfer actually takes place, the source, target, or both data types are indicated when calling SQLBindParameter(), SQLBindCol(), or SQLGetData(). These functions use symbolic type names shown to identify the data types involved in the data transfer.
SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_DOUBLE,
SQL_DECIMAL, 5, 3, double_ptr, NULL);
The functions mentioned in the previous paragraph can be used to convert data to other types, but not all data conversions are supported or make sense. Table 1 shows all the conversions that DB2 ODBC supports.
| SQL symbolic data type | Default C symbolic data type | Additional C symbolic data types |
|---|---|---|
| SQL_BIGINT | SQL_C_BIGINT |
|
| SQL_BINARY | SQL_C_BINARY |
|
| SQL_BLOB | SQL_C_BINARY | SQL_C_CHAR1 SQL_C_WCHAR2 SQL_C_BLOB_LOCATOR3 |
| SQL_CHAR | SQL_C_CHAR1 |
|
| SQL_CLOB | SQL_C_CHAR1 | SQL_C_WCHAR2 SQL_C_BINARY SQL_C_CLOB_LOCATOR3 |
| SQL_DBCLOB | SQL_C_DBCHAR |
|
| SQL_DECFLOAT | SQL_C_CHAR1 |
|
| SQL_DECIMAL | SQL_C_CHAR1 |
|
| SQL_DOUBLE | SQL_C_DOUBLE |
|
| SQL_FLOAT | SQL_C_DOUBLE |
|
| SQL_GRAPHIC | SQL_C_DBCHAR or SQL_C_WCHAR4 | SQL_C_CHAR1 |
| SQL_INTEGER | SQL_C_LONG |
|
| SQL_LONGVARBINARY | SQL_C_BINARY | SQL_C_CHAR SQL_C_WCHAR |
| SQL_LONGVARCHAR | SQL_C_CHAR1 |
|
| SQL_LONGVARGRAPHIC | SQL_C_DBCHAR or SQL_C_WCHAR4 | SQL_C_CHAR1 |
| SQL_NUMERIC5 | SQL_C_CHAR1 |
|
| SQL_REAL | SQL_C_FLOAT |
|
| SQL_ROWID | SQL_C_CHAR | SQL_C_WCHAR |
| SQL_SMALLINT | SQL_C_SHORT |
|
| SQL_TYPE_DATE | SQL_C_TYPE_DATE |
|
| SQL_TYPE_TIME | SQL_C_TYPE_TIME |
|
| SQL_TYPE_TIMESTAMP | SQL_C_TYPE_TIMESTAMP |
|
| SQL_VARBINARY | SQL_C_BINARY | SQL_C_CHAR SQL_C_WCHAR |
| SQL_VARCHAR | SQL_C_CHAR1 |
|
| SQL_VARGRAPHIC | SQL_C_DBCHAR or SQL_C_WCHAR4 | SQL_C_CHAR1 |
| SQL_XML | SQL_C_BINARY |
|
Notes:
|
||
| Symbolic C data type | Symbolic SQL data types that use this C data type as a default | Additional symbolic SQL data types |
|---|---|---|
| SQL_C_BIGINT | SQL_BIGINT |
|
| SQL_C_CHAR1 |
|
|
| SQL_C_WCHAR3 |
|
|
| SQL_C_LONG | SQL_INTEGER |
|
| SQL_C_SHORT | SQL_SMALLINT |
|
| SQL_C_TINYINT | No SQL data types use SQL_C_TINYINT in a default conversion. |
|
| SQL_C_FLOAT | SQL_REAL |
|
| SQL_C_DOUBLE | SQL_DOUBLE SQL_FLOAT |
|
| SQL_C_DECIMAL64 | No SQL data types use SQL_C_DECIMAL64 in a default conversion. |
|
| SQL_C_DECIMAL128 | No SQL data types use SQL_C_DECIMAL128 in a default conversion. |
|
| SQL_C_TYPE_DATE | SQL_TYPE_DATE |
|
| SQL_C_TYPE_TIME | SQL_TYPE_TIME |
|
| SQL_C_TYPE_TIMESTAMP | SQL_TYPE_TIMESTAMP |
|
| SQL_C_BINARY |
|
|
SQL_C_BINARYXML![]() |
No SQL types use SQL_C_BINARYXML in a default conversion![]() |
SQL_XML![]() |
| SQL_C_BIT | No SQL types use SQL_C_BIT in a default conversion. |
|
| SQL_C_DBCHAR | SQL_DBCLOB SQL_GRAPHIC5 SQL_LONGVARGRAPHIC5 SQL_VARGRAPHIC5 | SQL_XML |
| SQL_C_CLOB_LOCATOR | No SQL data types use SQL_C_CLOB_LOCATOR in a default conversion. | SQL_CLOB |
| SQL_C_BLOB_LOCATOR | No SQL data types use SQL_C_BLOB_LOCATOR in a default conversion. | SQL_BLOB |
| SQL_C_DBCLOB_LOCATOR | No SQL data types use SQL_C_DBCLOB_LOCATOR in a default conversion. | SQL_DBCLOB |
Notes:
|
||
Limits on precision, and scale, as well as truncation and rounding rules are the same as those for DB2 for z/OS, with the following exception; truncation of values to the right of the decimal point for numeric values returns a truncation warning, whereas truncation to the left of the decimal point returns an error. In cases of error, the application should call SQLGetDiagRec() to obtain the SQLSTATE and additional information about the failure. When moving and converting floating point data values between the application and DB2 ODBC, no correspondence is guaranteed to be exact as the values can change in precision and scale.
SQL_C_BINARYXML