Certain predefined C and C++ data types correspond to DB2® database column types. Only these C and C++ data types can be declared as host variables.
The following tables show the C and C++ equivalent of each column type. When the precompiler finds a host variable declaration, it determines the appropriate SQL type value. The database manager uses this value to convert the data exchanged between the application and itself.
SQL Column Type1 | C and C++ Data Type | SQL Column Type Description |
---|---|---|
SMALLINT |
short |
16-bit signed integer |
INTEGER |
int |
32-bit signed integer |
BIGINT |
long long |
64-bit signed integer |
REAL5 |
float | Single-precision floating point |
DOUBLE6 |
double | Double-precision floating point |
DECIMAL(p,s) |
No exact equivalent; use double | Packed decimal (Consider using the CHAR and DECIMAL functions to manipulate packed decimal fields as character data.) |
CHAR(1) |
char | Single character |
CHAR(n) |
No exact equivalent; use char[n+1] where
n is large enough to hold the data 1<=n<=254 |
Fixed-length character string |
VARCHAR(n) |
struct tag { |
Non null-terminated varying character string
with 2-byte string length indicator. Note: A
host variable structure of the following form is always treated as
a VARCHAR host variable and cannot be declared:
|
Alternatively, use char[n+1] where n
is large enough to hold the data 1<=n<=32 672 |
Null-terminated variable-length character string
Note: Assigned an SQL type of 460/461.
|
|
LONG VARCHAR8 |
struct tag { |
Non null-terminated varying character string with 2-byte string length indicator |
CLOB(n) |
sql type is |
Non null-terminated varying character string with 4-byte string length indicator |
CLOB locator variable7 |
sql type is |
Identifies CLOB entities residing on the server |
CLOB file reference variable7 |
sql type is |
Descriptor for file containing CLOB data |
BLOB(n) |
sql type is |
Non null-terminated varying binary string with 4-byte string length indicator |
BLOB locator variable7 |
sql type is |
Identifies BLOB entities on the server |
BLOB file reference variable7 |
sql type is |
Descriptor for the file containing BLOB data |
DATE |
Null-terminated character form | Allow at least 11 characters to accommodate the null-terminator |
VARCHAR structured form | Allow at least 10 characters | |
TIME |
Null-terminated character form | Allow at least 9 characters to accommodate the null-terminator |
VARCHAR structured form | Allow at least 8 characters | |
TIMESTAMP(p) |
Null-terminated character form | Allow 20- 33 characters to accommodate for the null-terminator |
VARCHAR structured form | Allow 19-32 characters. |
|
XML8 |
struct { |
XML value |
BINARY |
unsigned char myBinField[4]; |
Binary data |
VARBINARY |
struct |
Varbinary data |
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(1) |
sqldbchar | Single double-byte character |
GRAPHIC(n) |
No exact equivalent; use sqldbchar[n+1] where n is large
enough to hold the data 1<=n<=127 |
Fixed-length double-byte character string |
VARGRAPHIC(n) |
struct tag { |
Non null-terminated varying double-byte character string with 2-byte string length indicator |
Alternatively use sqldbchar[n+1] where
n is large enough to hold the data 1<=n<=16 336 |
Null-terminated variable-length double-byte
character string Note: Assigned an SQL type of 400/401.
|
|
LONG VARGRAPHIC8 |
struct tag { |
Non null-terminated varying double-byte character string with 2-byte string length indicator |
The following data types are only available in the DBCS or EUC environment when precompiled with the WCHARTYPE CONVERT option.
SQL Column Type1 | C and C++ Data Type | SQL Column Type Description |
---|---|---|
GRAPHIC(1) |
wchar_t |
|
GRAPHIC(n) |
No exact equivalent; use wchar_t [n+1] where n is large
enough to hold the data 1<=n<=127 |
Fixed-length double-byte character string |
VARGRAPHIC(n) |
struct tag { |
Non null-terminated varying double-byte character string with 2-byte string length indicator |
Alternately use char[n+1] where n is
large enough to hold the data 1<=n<=16 336 |
Null-terminated variable-length double-byte
character string Note: Assigned an SQL type of 400/401.
|
|
LONG VARGRAPHIC8 |
struct tag { |
Non null-terminated varying double-byte character string with 2-byte string length indicator |
The following data types are only available in the DBCS or EUC environment.
SQL Column Type1 | C and C++ Data Type | SQL Column Type Description |
---|---|---|
DBCLOB(n) |
sql type is |
Non null-terminated varying double-byte character string with 4-byte string length indicator |
DBCLOB locator variable7 |
sql type is |
Identifies DBCLOB entities residing on the server |
DBCLOB file reference |
sql type is |
Descriptor for file containing DBCLOB data |
Note:
|