C and SQL data types
Db2 ODBC defines a set of SQL symbolic data types. Each SQL symbolic data type has a corresponding default C data type.
These data types represent the combination of the ODBC
3.0 minimum, core, and extended data types. Db2 ODBC supports the following additional data
types:
- SQL_GRAPHIC
- SQL_VARGRAPHIC
- SQL_LONGVARGRAPHIC
Table 1 lists each
of the SQL data types, with its corresponding symbolic name, and the
default C symbolic name. The table contains the following columns:
- SQL data type
- This column contains the SQL data types as they would appear in an SQL CREATE DDL statement. The SQL data types are dependent on the database server.
- Symbolic SQL data type
- This column contains SQL symbolic names that are defined (in sqlcli1.h) as an integer value. These values are used by various functions to identify the SQL data types listed in the first column.
- Default C symbolic data type
- This column contains C symbolic
names, also defined as integer values. These values are used in various
function arguments to identify the C data type as shown in Table 2. The symbolic names are used by
various functions (such as
SQLBindParameter()
,SQLGetData()
, andSQLBindCol()
calls) to indicate the C data types of the application variables. Instead of explicitly identifying the C data type when calling these functions, SQL_C_DEFAULT can be specified instead, and Db2 ODBC assumes a default C data type based on the SQL data type of the parameter or column, as shown by this table. For example, the default C data type of SQL_DECIMAL is SQL_C_CHAR.
SQL data type | Symbolic SQL data type | Default symbolic C data type |
---|---|---|
BIGINT | SQL_BIGINT | SQL_C_BIGINT |
BINARY | SQL_BINARY | SQL_C_BINARY |
BLOB | SQL_BLOB | SQL_C_BINARY |
BLOB LOCATOR1 | SQL_BLOB_LOCATOR | SQL_C_BLOB_LOCATOR |
CHAR | SQL_CHAR | SQL_C_CHAR |
CHAR FOR BIT DATA 6 | SQL_BINARY | SQL_C_BINARY |
CLOB | SQL_CLOB | SQL_C_CHAR |
CLOB LOCATOR | SQL_CLOB_LOCATOR | SQL_C_CLOB_LOCATOR |
DATE | SQL_TYPE_DATE2 | SQL_C_TYPE_DATE |
DBCLOB | SQL_DBCLOB | SQL_C_DBCHAR |
DBCLOB LOCATOR1 | SQL_DBCLOB_LOCATOR | SQL_C_DBCLOB_LOCATOR |
DECFLOAT(16) or DECFLOAT(34) | SQL_DECFLOAT | SQL_C_CHAR |
DECIMAL | SQL_DECIMAL | SQL_C_CHAR |
DOUBLE | SQL_DOUBLE | SQL_C_DOUBLE |
FLOAT | SQL_FLOAT | SQL_C_DOUBLE |
GRAPHIC | SQL_GRAPHIC | SQL_C_DBCHAR or SQL_C_WCHAR4 |
INTEGER | SQL_INTEGER | SQL_C_LONG |
LONG VARCHAR5 | SQL_LONGVARCHAR | SQL_C_CHAR |
LONG VARCHAR FOR BIT DATA5,6 | SQL_LONGVARBINARY | SQL_C_BINARY |
LONG VARGRAPHIC5 | SQL_LONGVARGRAPHIC | SQL_C_DBCHAR or SQL_C_WCHAR4 |
NUMERIC7 | SQL_NUMERIC7 | SQL_C_CHAR |
REAL | SQL_REAL | SQL_C_FLOAT |
ROWID | SQL_ROWID | SQL_C_CHAR |
SMALLINT | SQL_SMALLINT | SQL_C_SHORT |
TIME | SQL_TYPE_TIME2 | SQL_C_TYPE_TIME |
TIMESTAMP | SQL_TYPE_TIMESTAMP2 | SQL_C_TYPE_TIMESTAMP
SQL_C_TYPE_TIMESTAMP_EXT3 |
![]() ![]() |
![]() ![]() |
![]() SQL_C_TYPE_TIMESTAMP_EXT_TZ8
![]() |
VARBINARY | SQL_VARBINARY | SQL_C_BINARY |
VARCHAR | SQL_VARCHAR | SQL_C_CHAR |
VARCHAR FOR BIT DATA6 | SQL_VARBINARY | SQL_C_BINARY |
VARGRAPHIC | SQL_VARGRAPHIC | SQL_C_DBCHAR or SQL_C_WCHAR4 |
XML | SQL_XML | SQL_C_BINARY |
Notes:
Additional information:
|
Table 2 shows the generic
C type definitions for each symbolic C type. The table contains
the following columns:
- C symbolic data type
- This column contains C symbolic names, defined as integer values. These values are used in various function arguments to identify the C data type shown in the last column.
- C type
- This column contains C-defined types, which are defined in sqlcli1.h using a C typedef statement. The values in this column should be used to declare all Db2 ODBC related variables and arguments, in order to make the application more portable.
- Base C type
- This column is shown for reference only. All variables and arguments should be defined using the symbolic types in the previous column. Some of the values are C structures that are described in Table 3.
C symbolic data type | C type | Base C type |
---|---|---|
SQL_C_BIGINT | SQLBIGINT | long long int |
SQL_C_CHAR | SQLCHAR | Unsigned char |
SQL_C_BIT | SQLCHAR | Unsigned char or char (Value 1 or 0) |
SQL_C_TINYINT | SQLSCHAR | Signed char (Range -128 to 127) |
SQL_C_SHORT | SQLSMALLINT | Short int |
SQL_C_LONG | SQLINTEGER | Long int (31-bit) or int (64-bit)1 |
SQL_C_DOUBLE | SQLDOUBLE | Double |
SQL_C_FLOAT | SQLREAL | Float |
SQL_C_DECIMAL64 | SQLDECIMAL64 | See Table 3 |
SQL_C_DECIMAL128 | SQLDECIMAL128 | See Table 3 |
SQL_C_TYPE_DATE2 | DATE_STRUCT | See Table 3 |
SQL_C_TYPE_TIMESTAMP2 | TIMESTAMP_STRUCT | See Table 3 |
SQL_C_TYPE_TIMESTAMP_EXT2 | TIMESTAMP_STRUCT_EXT | See Table 3 |
SQL_C_TYPE_TIMESTAMP_EXT_TZ
2 |
TIMESTAMP_STRUCT_EXT_TZ | See Table 3 |
SQL_C_CLOB_LOCATOR | SQLINTEGER | Long int (31-bit) or int (64-bit)1 |
SQL_C_BINARY | SQLCHAR | Unsigned char |
SQL_C_BINARYXML | SQLCHAR | Unsigned char |
SQL_C_BLOB_LOCATOR | SQLINTEGER | Long int (31-bit) or int (64-bit)1 |
SQL_C_DBCHAR | SQLDBCHAR | Unsigned short |
SQL_C_DBCLOB_LOCATOR | SQLINTEGER | Long int (31-bit) or int (64-bit)1 |
SQL_C_WCHAR | SQLWCHAR | wchar_t (31-bit) or unsigned short (64-bit)1 |
Note:
|
The following table lists the C data types with their associated structures for date, time, timestamp, and decimal floating point.
C type | Generic structure |
---|---|
DATE_STRUCT |
|
TIME_STRUCT |
|
TIMESTAMP_STRUCT |
|
TIMESTAMP_STRUCT_EXT |
|
![]() ![]() |
![]()
![]() |
SQLDECIMAL64 |
|
SQLDECIMAL128 |
|