For a given SQL data type:
The tables list the conversions defined by ODBC to be valid for a given SQL data type.
If the fCType argument in SQLBindCol() or SQLGetData() contains a value not shown in the table for a given SQL data type, SQLFetch(), or SQLGetData() returns the SQLSTATE 07006 (Restricted data type attribute violation).
If the fCType argument contains a value shown in the table but which specifies a conversion not supported by the driver, SQLFetch(), or SQLGetData() returns SQLSTATE HYC00 (Driver not capable).
Though it is not shown in the tables, the pcbValue argument contains SQL_NULL_DATA when the SQL data value is NULL. For an explanation of the use of pcbValue when multiple calls are made to retrieve data, see SQLGetData().
When SQL data is converted to character C data, the character count returned in pcbValue does not include the null termination byte. If rgbValue is a null pointer, SQLBindCol() or SQLGetData() returns SQLSTATE HY009 (Invalid argument value).
In the following tables:
The character SQL data types are:
Table 198. Converting Character SQL Data to C Data
fCType | Test | rgbValue | pcbValue | SQLSTATE | ||
---|---|---|---|---|---|---|
SQL_C_CHAR | Length of data < cbValueMax | Data | Length of data | 00000 | ||
Length of data >= cbValueMax | Truncated data | Length of data | 01004 | |||
SQL_C_BINARY | Length of data <= cbValueMax | Data | Length of data | 00000 | ||
Length of data > cbValueMax | Truncated data | Length of data | 01004 | |||
SQL_C_SHORT SQL_C_LONG SQL_C_FLOAT SQL_C_FLOAT SQL_C_TINYINT SQL_C_BIT SQL_C_UBIGINT SQL_C_SBIGINT SQL_C_NUMERIC c | Data converted without truncation a | Data | Size of the C data type |
00000 | ||
Data converted with truncation, but without loss of significant digits a | Data | Size of the C data type | 01004 | |||
Conversion of data would result in loss of significant digitsa | Untouched | Size of the C data type | 22003 | |||
Data is not a number a | Untouched | Size of the C data type | 22005 | |||
SQL_C_DATE | Data value is a valid date a | Data | 6 b | 00000 | ||
Data value is not a valid date a | Untouched | 6 b | 22007 | |||
SQL_C_TIME | Data value is a valid time a | Data | 6 b | 00000 | ||
Data value is not a valid time a | Untouched | 6 b | 22007 | |||
SQL_C_TIMESTAMP | Data value is a valid timestamp a | Data | 16 b | 00000 | ||
Data value is not a valid timestamp a | Untouched | 16 b | 22007 | |||
SQLSTATE 00000 is not returned by SQLError(), rather it is indicated when the function returns SQL_SUCCESS. |
The graphic SQL data types are:
Table 199. Converting Graphic SQL Data to C Data
fCType | Test | rgbValue | pcbValue | SQLSTATE | ||
---|---|---|---|---|---|---|
SQL_C_CHAR | Number of double byte characters * 2 <= cbValueMax | Data | Length of data(octects) | 00000 | ||
Number of double byte characters * 2 > cbValueMax | Truncated data, to the nearest even byte that is less than cbValueMax. | Length of data(octects) | 01004 | |||
SQL_C_DBCHAR | Number of double byte characters * 2 < cbValueMax | Data | Length of data(octects) | 00000 | ||
Number of double byte characters * 2 >= cbValueMax | Truncated data, to the nearest even byte that is less than cbValueMax. | Length of data(octects) | 01004 | |||
|
The numeric SQL data types are:
Table 200. Converting Numeric SQL Data to C Data
fCType | Test | rgbValue | pcbValue | SQLSTATE | ||
---|---|---|---|---|---|---|
SQL_C_CHAR | Display size < cbValueMax | Data | Length of data | 00000 | ||
Number of significant digits < cbValueMax | Truncated data | Length of data | 01004 | |||
Number of significant digits >= cbValueMax | Untouched | Length of data | 22003 | |||
SQL_C_SHORT SQL_C_LONG SQL_C_FLOAT SQL_C_DOUBLE SQL_C_TINYINT SQL_C_BIT SQL_C_UBIGINT SQL_C_SBIGINT SQL_C_NUMERIC b | Data converted without truncation a | Data | Size of the C data type | 00000 | ||
Data converted with truncation, but without loss of significant digits a | Truncated data | Size of the C data type | 01004 | |||
Conversion of data would result in loss of significant digits a | Untouched | Size of the C data type | 22003 | |||
SQLSTATE 00000 is not returned by SQLError(), rather it is indicated when the function returns SQL_SUCCESS. |
The binary SQL data types are:
Table 201. Converting Binary SQL Data to C Data
fCType | Test | rgbValue | pcbValue | SQLSTATE |
---|---|---|---|---|
SQL_C_CHAR | (Length of data) < cbValueMax | Data | Length of data | N/A |
(Length of data) >= cbValueMax | Truncated data | Length of data | 01004 | |
SQL_C_BINARY | Length of data <= cbValueMax | Data | Length of data | N/A |
Length of data > cbValueMax | Truncated data | Length of data | 01004 |
The date SQL data type is:
Table 202. Converting Date SQL Data to C Data
fCType | Test | rgbValue | pcbValue | SQLSTATE | ||
---|---|---|---|---|---|---|
SQL_C_CHAR | cbValueMax >= 11 | Data | 10 | 00000 | ||
cbValueMax < 11 | Untouched | 10 | 22003 | |||
SQL_C_DATE | None a | Data | 6 b | 00000 | ||
SQL_C_TIMESTAMP | None a | Data c | 16 b | 00000 | ||
SQLSTATE 00000 is not returned by SQLError(), rather it is indicated when the function returns SQL_SUCCESS. |
When the date SQL data type is converted to the character C data type, the resulting string is in the "yyyy-mm-dd" format.
The time SQL data type is:
Table 203. Converting Time SQL Data to C Data
fCType | Test | rgbValue | pcbValue | SQLSTATE | ||
---|---|---|---|---|---|---|
SQL_C_CHAR | cbValueMax >= 9 | Data | 8 | 00000 | ||
cbValueMax < 9 | Untouched | 8 | 22003 | |||
SQL_C_TIME | None a | Data | 6 b | 00000 | ||
SQL_C_TIMESTAMP | None a | Data c | 16 b | 00000 | ||
SQLSTATE 00000 is not returned by SQLError(), rather it is indicated when the function returns SQL_SUCCESS. |
When the time SQL data type is converted to the character C data type, the resulting string is in the "hh:mm:ss" format.
The timestamp SQL data type is:
Table 204. Converting Timestamp SQL Data to C Data
fCType | Test | rgbValue | pcbValue | SQLSTATE | ||
---|---|---|---|---|---|---|
SQL_C_CHAR | Display size < cbValueMax | Data | Length of data | 00000 | ||
19 <= cbValueMax <= Display size | Truncated Data b | Length of data | 01004 | |||
cbValueMax < 19 | Untouched | Length of data | 22003 | |||
SQL_C_DATE | None a | Truncated data c | 6 e | 01004 | ||
SQL_C_TIME | None a | Truncated data d | 6 e | 01004 | ||
SQL_C_TIMESTAMP | None a | Data | 16 e | 00000 | ||
SQLSTATE 00000 is not returned by SQLError(), rather it is indicated when the function returns SQL_SUCCESS. |
When the timestamp SQL data type is converted to the character C data type, the resulting string is in the "yyyy-mm-dd hh:mm:ss[.fff[fff]]" format (regardless of the precision of the timestamp SQL data type).
Table 205. SQL to C Data Conversion Examples
SQL Data Type | SQL Data Value | C Data Type | cbValue Max | rgbValue | SQL STATE | ||
---|---|---|---|---|---|---|---|
SQL_CHAR | abcdef | SQL_C_CHAR | 7 | abcdef\0 a | 00000 | ||
SQL_CHAR | abcdef | SQL_C_CHAR | 6 | abcde\0 a | 01004 | ||
SQL_DECIMAL | 1234.56 | SQL_C_CHAR | 8 | 1234.56\0 a | 00000 | ||
SQL_DECIMAL | 1234.56 | SQL_C_CHAR | 5 | 1234\0 a | 01004 | ||
SQL_DECIMAL | 1234.56 | SQL_C_CHAR | 4 | --- | 22003 | ||
SQL_DECIMAL | 1234.56 | SQL_C_FLOAT | ignored | 1234.56 | 00000 | ||
SQL_DECIMAL | 1234.56 | SQL_C_SHORT | ignored | 1234 | 01004 | ||
SQL_DATE | 1992-12-31 | SQL_C_CHAR | 11 | 1992-12-31\0 a | 00000 | ||
SQL_DATE | 1992-12-31 | SQL_C_CHAR | 10 | --- | 22003 | ||
SQL_DATE | 1992-12-31 | SQL_C_ TIMESTAMP | ignored | 1992,12,31, 0,0,0,0 b | 00000 | ||
SQL_TIMESTAMP | 1992-12-31 23:45:55.12 | SQL_C_CHAR | 23 | 1992-12-31 23:45:55.12\0 a | 00000 | ||
SQL_TIMESTAMP | 1992-12-31 23:45:55.12 | SQL_C_CHAR | 22 | 1992-12-31 23:45:55.1\0 a | 01004 | ||
SQL_TIMESTAMP | 1992-12-31 23:45:55.12 | SQL_C_CHAR | 18 | --- | 22003 | ||
SQLSTATE 00000 is not returned by SQLError(), rather it is indicated when the function returns SQL_SUCCESS. |