Certain predefined C and C++ data types correspond to the database manager column types. Only these C/C++ data types can be declared as host variables.
Table 30 shows the C/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.
Note: | There is no host variable support for the DATALINK data type in any of the DB2 host languages. |
Table 30. SQL Data Types Mapped to C/C++ Declarations
SQL Column Type(TNTA1) | C/C++ Data Type | SQL Column Type Description | ||
---|---|---|---|---|
SMALLINT (500 or 501) |
short short int sqlint16 | 16-bit signed integer | ||
INTEGER (496 or 497) |
long long int sqlint32(TNTA1A) | 32-bit signed integer | ||
BIGINT (492 or 493) |
long long long __int64 sqlint64(TNTA1B) | 64-bit signed integer | ||
REAL(TNTA2) (480 or 481) | float | Single-precision floating point | ||
DOUBLE(TNTA3) (480 or 481) | double | Double-precision floating point | ||
DECIMAL(p,s) (484 or 485) | No exact equivalent; use double | Packed decimal
(Consider using the CHAR and DECIMAL functions to manipulate packed decimal fields as character data.) | ||
CHAR(1) (452 or 453) | char | Single character | ||
CHAR(n) (452 or 453) | 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) (448 or 449) |
struct tag { short int; char[n] } 1<=n<=32 672 | Non null-terminated varying character string with 2-byte string length indicator | ||
Alternately use char[n+1] where n is large
enough to hold the data
1<=n<=32 672 | null-terminated variable-length character string
| |||
LONG VARCHAR (456 or 457) |
struct tag { short int; char[n] } 32 673<=n<=32 700 | Non null-terminated varying character string with 2-byte string length indicator | ||
CLOB(n) (408 or 409) |
sql type is clob(n) 1<=n<=2 147 483 647 | Non null-terminated varying character string with 4-byte string length indicator | ||
CLOB locator variable(TNTA4) (964 or 965) |
sql type is clob_locator | Identifies CLOB entities residing on the server | ||
CLOB file reference variable(TNTA4) (920 or 921) |
sql type is clob_file | Descriptor for file containing CLOB data | ||
BLOB(n) (404 or 405) |
sql type is blob(n) 1<=n<=2 147 483 647 | Non null-terminated varying binary string with 4-byte string length indicator | ||
BLOB locator variable(TNTA4) (960 or 961) |
sql type is blob_locator | Identifies BLOB entities on the server | ||
BLOB file reference variable(TNTA4) (916 or 917) |
sql type is blob_file | Descriptor for the file containing BLOB data | ||
DATE (384 or 385) | null-terminated character form | Allow at least 11 characters to accommodate the null-terminator. | ||
VARCHAR structured form | Allow at least 10 characters. | |||
TIME (388 or 389) | null-terminated character form | Allow at least 9 characters to accommodate the null-terminator. | ||
VARCHAR structured form | Allow at least 8 characters. | |||
TIMESTAMP (392 or 393) | null-terminated character form | Allow at least 27 characters to accommodate the null-terminator. | ||
VARCHAR structured form | Allow at least 26 characters. | |||
| ||||
GRAPHIC(1) (468 or 469) | sqldbchar | Single double-byte character | ||
GRAPHIC(n) (468 or 469) | 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) (464 or 465) |
struct tag { short int; sqldbchar[n] } 1<=n<=16 336 | Non null-terminated varying double-byte character string with 2-byte string length indicator | ||
Alternately 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
| |||
LONG VARGRAPHIC (472 or 473) |
struct tag { short int; sqldbchar[n] } 16 337<=n<=16 350 | Non null-terminated varying double-byte character string with 2-byte string length indicator | ||
| ||||
GRAPHIC(1) (468 or 469) | wchar_t |
| ||
GRAPHIC(n) (468 or 469) | 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) (464 or 465) |
struct tag { short int; wchar_t [n] } 1<=n<=16 336 | 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
| |||
LONG VARGRAPHIC (472 or 473) |
struct tag { short int; wchar_t [n] } 16 337<=n<=16 350 | Non null-terminated varying double-byte character string with 2-byte string length indicator | ||
| ||||
DBCLOB(n) (412 or 413) |
sql type is dbclob(n) 1<=n<=1 073 741 823 | Non null-terminated varying double-byte character string with 4-byte string length indicator | ||
DBCLOB locator variable(TNTA4) (968 or 969) |
sql type is dbclob_locator | Identifies DBCLOB entities residing on the server | ||
DBCLOB file reference variable(TNTA4) (924 or 925) |
sql type is dbclob_file | Descriptor for file containing DBCLOB data | ||
Notes:
|
The following is a sample SQL declare section with host variables declared for supported SQL data types.
EXEC SQL BEGIN DECLARE SECTION;
·
·
·
short age = 26; /* SQL type 500 */ short year; /* SQL type 500 */ sqlint32 salary; /* SQL type 496 */ sqlint32 deptno; /* SQL type 496 */ float bonus; /* SQL type 480 */ double wage; /* SQL type 480 */ char mi; /* SQL type 452 */ char name[6]; /* SQL type 460 */ struct { short len; char data[24]; } address; /* SQL type 448 */ struct { short len; char data[32695]; } voice; /* SQL type 456 */ sql type is clob(1m) chapter; /* SQL type 408 */ sql type is clob_locator chapter_locator; /* SQL type 964 */ sql type is clob_file chapter_file_ref; /* SQL type 920 */ sql type is blob(1m) video; /* SQL type 404 */ sql type is blob_locator video_locator; /* SQL type 960 */ sql type is blob_file video_file_ref; /* SQL type 916 */ sql type is dbclob(1m) tokyo_phone_dir; /* SQL type 412 */ sql type is dbclob_locator tokyo_phone_dir_lctr; /* SQL type 968 */ sql type is dbclob_file tokyo_phone_dir_flref; /* SQL type 924 */ struct { short len; sqldbchar data[100]; } vargraphic1; /* SQL type 464 */ /* Precompiled with WCHARTYPE NOCONVERT option */ struct { short len; wchar_t data[100]; } vargraphic2; /* SQL type 464 */ /* Precompiled with WCHARTYPE CONVERT option */ struct { short len; sqldbchar data[10000]; } long_vargraphic1; /* SQL type 472 */ /* Precompiled with WCHARTYPE NOCONVERT option */ struct { short len; wchar_t data[10000]; } long_vargraphic2; /* SQL type 472 */ /* Precompiled with WCHARTYPE CONVERT option */ sqldbchar graphic1[100]; /* SQL type 468 */ /* Precompiled with WCHARTYPE NOCONVERT option */ wchar_t graphic2[100]; /* SQL type 468 */ /* Precompiled with WCHARTYPE CONVERT option */ char date[11]; /* SQL type 384 */ char time[9]; /* SQL type 388 */ char timestamp[27]; /* SQL type 392 */ short wage_ind; /* Null indicator */
·
·
·
EXEC SQL END DECLARE SECTION;
The following are additional rules for supported C/C++ data types:
The standard C or C++ string type 460 should not be used for columns designated FOR BIT DATA. The database manager truncates this data type when a null character is encountered. Use either the VARCHAR (SQL type 448) or CLOB (SQL type 408) structures.