Data types for procedures, functions, and methods in C and C++ embedded SQL applications
There is a mapping between C and C++ and Db2® data types. When you
are writing your embedded SQL application, you must be aware of this mapping to ensure that you do
not have unexpected data type conversions or data truncation.
The following table lists the supported mappings between SQL data types and C and C++ data types for procedures, UDFs, and methods.
SQL Column Type1 | C and C++ Data Type | SQL Column Type Description |
---|---|---|
SMALLINT
(500 or 501) |
short | 16-bit signed integer |
INTEGER
(496 or 497) |
sqlint32 | 32-bit signed integer |
BIGINT
(492 or 493) |
sqlint64 | 64-bit signed integer |
REAL
(480 or 481) |
float | Single-precision floating point |
DOUBLE
(480 or 481) |
double | Double-precision floating point |
DECIMAL(p,s)
(484 or 485) |
Not supported | To pass a decimal value, define the parameter to be of a data type castable from DECIMAL (for example CHAR or DOUBLE) and explicitly cast the argument to this type. |
CHAR(n)
(452 or 453) |
char[n+1] where n is large enough to
hold the data 1<=n<=254
|
Fixed-length, null-terminated character string |
CHAR(n) FOR BIT DATA
(452 or 453) |
char[n+1] where n is large enough to
hold the data 1<=n<=254
|
Fixed-length character string |
VARCHAR(n)
(448 or 449) (460 or 461) |
char[n+1] where n is large enough to
hold the data 1<=n<=32 672
|
Null-terminated varying length string |
VARCHAR(n) FOR BIT DATA
(448 or 449) |
struct {
sqluint16 length; char[n] } 1<=n<=32 672 |
Not null-terminated varying length character string |
LONG VARCHAR2
(456 or 457) |
struct {
sqluint16 length; char[n] } 32 673<=n<=32 700 |
Not null-terminated varying length character string |
CLOB(n)
(408 or 409) |
struct {
sqluint32 length; char data[n]; } 1<=n<=2 147 483 647 |
Not null-terminated varying length character string with 4-byte string length indicator |
BINARY(n)
(912 or 913) |
char[n+1] where n is large enough to hold the data
1<=n<=254
|
Fixed-length binary string |
VARBINARY(n)
(908 or 909) |
struct {
sqluint16 length; char[n] } 1<=n<=32 672 |
Not null-terminated varying length binary string |
BLOB(n)
(404 or 405) |
struct {
sqluint32 length; char data[n]; } 1<=n<=2 147 483 647 |
Not null-terminated varying binary string with 4-byte string length indicator |
DATE
(384 or 385) |
char[11] | Null-terminated character form |
TIME
(388 or 389) |
char[9] | Null-terminated character form |
TIMESTAMP(p)
(392 or 393) |
char[p+21] where p is large enough to
hold the data 0<=p<=12
|
Null-terminated character form |
XML
(988/989) |
Not supported
|
This descriptor type value (988/989) will be defined to be used in the SQLDA for describe, and to indicate XML Data (in its serialized form). Existing character and binary types (including LOBs and LOB file reference types) can also be used to fetch and insert the data (dynamic SQL only) |
Note: The following data types are only available in
the DBCS or EUC environment when precompiled with the WCHARTYPE NOCONVERT
option.
SQL Column Type1 | C and C++ Data Type | SQL Column Type Description |
---|---|---|
GRAPHIC(n)
(468 or 469) |
sqldbchar[n+1] where n is large enough
to hold the data 1<=n<=127
|
Fixed-length, null-terminated double-byte character string |
VARGRAPHIC(n)
(400® or 401) |
sqldbchar[n+1] where n is large enough
to hold the data 1<=n<=16 336
|
Not null-terminated, variable-length double-byte character string |
LONG VARGRAPHIC2
(472 or 473) |
struct {
sqluint16 length; sqldbchar[n] } 16 337<=n<=16 350 |
Not null-terminated, variable-length double-byte character string |
DBCLOB(n)
(412 or 413) |
struct {
sqluint32 length; sqldbchar data[n]; } 1<=n<=1 073 741 823 |
Not null-terminated varying length character string with 4-byte string length indicator |
Note:
|