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()
call
binds a parameter marker that corresponds to an SQL data type of DECIMAL(5,3)
to an application's C buffer type of double: SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_DOUBLE,
SQL_DECIMAL, 5, 3, double_ptr, NULL);
Supported data conversions lists the data conversions that Db2 ODBC supports.
- D
- The conversion is supported and this is the default conversion for the SQL data type.
- X
- All IBM® databases support the conversion.
- blank
- No IBM databases supports the conversion.
SQL
data type |
S
Q L _ C _ C H A R |
S
Q L _ C _ W C H A R |
S
Q L _ C _ B I N A R Y X M L |
S
Q L _ C _ D B C H A R |
S
Q L _ C _ B I T |
S
Q L _ C _ T I N Y I N T |
S
Q L _ C _ S H O R T |
S
Q L _ C _ L O N G |
S
Q L _ C _ B I G I N T |
S
Q L _ C _ S B I G I N T |
S
Q L _ C _ F L O A T |
S
Q L _ C _ D O U B L E |
S
Q L _ C _ D E C I M A L 6 4 |
S
Q L _ C _ D E C I M A L 1 2 8 |
S
Q L _ C _ T Y P E _ D A T E |
S
Q L _ C _ T Y P E _ T I M E |
S
Q L _ C _ T Y P E _ T I M E S T A M P |
S
Q L _ C _ T Y P E _ T I M E S T A M P _ E X T |
S
Q L _ C _ T Y P E _ T I M E S T A M P _ E X T _ T Z |
S
Q L _ C _ B I N A R Y |
S
Q L _ C _ C L O B _ L O C A T O R |
S
Q L _ C _ B L O B _ L O C A T O R |
S
Q L _ C _ D B C L O B _ L O C A T O R |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
SQL_CHAR
|
D1
|
X2
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
|||||
SQL_
VARCHAR |
D1
|
X2
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
|||||
SQL_
LONG VARCHAR |
D1
|
X2
|
X
|
X
|
X
|
||||||||||||||||||
SQL_
BINARY |
X1
|
X2
|
D
|
||||||||||||||||||||
SQL_
VARBINARY |
X1
|
X2
|
D
|
||||||||||||||||||||
SQL_
LONG VARBINARY |
X1
|
X2
|
D
|
||||||||||||||||||||
SQL_
GRAPHIC4 |
X1
|
D2
|
D
|
||||||||||||||||||||
SQL_
VARGRAPHIC4 |
X1
|
D2
|
D
|
||||||||||||||||||||
SQL_
LONG VARGRAPHIC4 |
X1
|
D2
|
D
|
||||||||||||||||||||
SQL_CLOB
|
D1
|
X2
|
X
|
X3
|
|||||||||||||||||||
SQL_BLOB
|
X1
|
X2
|
D
|
X3
|
|||||||||||||||||||
SQL_DBCLOB
|
X1
|
X2
|
D
|
X3
|
|||||||||||||||||||
SQL_
CLOB_ LOCATOR |
X1
|
X2
|
X
|
D3
|
|||||||||||||||||||
SQL_
BLOB_ LOCATOR |
X1
|
X2
|
X
|
D3
|
|||||||||||||||||||
SQL_
DBCLOB_ LOCATOR |
X1
|
X2
|
X
|
D3
|
|||||||||||||||||||
SQL_NUMERIC5
|
D1
|
X2
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
||||||||||
SQL_DECIMAL
|
D1
|
X2
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
||||||||||
SQL_DECFLOAT
|
D1
|
X2
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
|||||||||||
SQL_INTEGER
|
X1
|
X2
|
X
|
X
|
X
|
X
|
D
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
|||||||||
SQL_
SMALLINT |
X1
|
X2
|
X
|
X
|
D
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
||||||||||
SQL_FLOAT
|
X1
|
X2
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
D
|
X
|
X
|
X
|
||||||||||
SQL_DOUBLE
|
X1
|
X2
|
X
|
X
|
X
|
X
|
X
|
X
|
X
|
D
|
X
|
X
|
X
|
||||||||||
SQL_REAL
|
X1
|
X2
|
X
|
X
|
X
|
X
|
X
|
X
|
D
|
X
|
X
|
X
|
X
|
||||||||||
SQL_BIGINT
|
X1
|
X2
|
X
|
X
|
X
|
X
|
D
|
D
|
X
|
X
|
X
|
X
|
|||||||||||
SQL_
TYPE_DATE |
X1
|
X2
|
D
|
X
|
X
|
X
|
X
|
||||||||||||||||
SQL_
TYPE_TIME |
X1
|
X2
|
D
|
X
|
X
|
X
|
X
|
||||||||||||||||
SQL_
TYPE_ TIMESTAMP |
X1
|
X2
|
X
|
X
|
D
|
D
|
X
|
X
|
|||||||||||||||
SQL_
TYPE_ TIMESTAMP_WITH_ZONE |
X1
|
X2
|
X
|
X
|
X
|
X
|
D
|
||||||||||||||||
SQL_ROWID
|
D1
|
||||||||||||||||||||||
SQL_XML
|
X1
|
X2
|
X
|
X
|
D
|
- You must bind data to the SQL_C_CHAR data type for Unicode UTF-8 data.
- You must bind data with the SQL_C_WCHAR data type for Unicode UCS-2 data.
- Data is not converted to LOB locator types; locators represent a data value.
-
The default C data type conversion for this SQL data type depends upon the encoding scheme your application uses. If your application uses UCS-2 Unicode encoding, the default conversion is to SQL_C_WCHAR. For all other encoding schemes, the default conversion is to SQL_C_DBCHAR.
- NUMERIC is a synonym for DECIMAL on Db2 for z/OS®, Db2 server for VSE and VM, and Db2 for Linux®, UNIX, and Windows.
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.