For a given C data type:
Note: | Data is sent to the data source only if the SQLSTATE is 00000 (Success). |
The tables list the conversions defined by ODBC to be valid for a given SQL data type.
If the fSqlType argument in SQLBindParameter() or SQLSetParam() contains a value not shown in the table for a given C data type, SQLSTATE 07006 is returned (Restricted data type attribute violation).
If the fSqlType argument contains a value shown in the table but which specifies a conversion not supported by the driver, SQLBindParameter() or SQLSetParam() returns SQLSTATE HYC00 (Driver not capable).
If the rgbValue and pcbValue arguments specified in SQLBindParameter() or SQLSetParam() are both null pointers, that function returns SQLSTATE HY009 (Invalid argument value).
The character C data type is:
Table 206. Converting Character C Data to SQL Data
fSQLType | Test | SQLSTATE | ||
---|---|---|---|---|
SQL_CHAR SQL_VARCHAR SQL_LONGVARCHAR SQL_CLOB | Length of data <= Column length | 00000 | ||
Length of data > Column length | 22001 | |||
SQL_DECIMAL SQL_NUMERIC SQL_SMALLINT SQL_INTEGER SQL_REAL SQL_FLOAT SQL_DOUBLE | Data converted without truncation | 00000 | ||
Data converted with truncation, but without loss of significant digits | 22001 | |||
Conversion of data would result in loss of significant digits | 22003 | |||
Data value is not a numeric value | 22005 | |||
SQL_BINARY SQL_VARBINARY SQL_LONGVARBINARY SQL_BLOB | (Length of data) < Column length | N/A | ||
(Length of data) >= Column length | 22001 | |||
Data value is not a hexadecimal value | 22005 | |||
SQL_DATE | Data value is a valid date | 00000 | ||
Data value is not a valid date | 22007 | |||
SQL_TIME | Data value is a valid time | 00000 | ||
Data value is not a valid time | 22007 | |||
SQL_TIMESTAMP | Data value is a valid timestamp | 00000 | ||
Data value is not a valid timestamp | 22007 | |||
SQL_GRAPHIC SQL_VARGRAPHIC SQL_LONGVARGRAPHIC SQL_DBCLOB | Length of data / 2 <= Column length | 00000 | ||
Length of data / 2 < Column length | 22001 | |||
|
The numeric C data types are:
Table 207. Converting Numeric C Data to SQL Data
fSQLType | Test | SQLSTATE | ||
---|---|---|---|---|
SQL_DECIMAL SQL_NUMERIC SQL_SMALLINT SQL_INTEGER SQL_REAL SQL_FLOAT SQL_DOUBLE | Data converted without truncation | 00000 | ||
Data converted with truncation, but without loss of significant digits | 22001 | |||
Conversion of data would result in loss of significant digits | 22003 | |||
SQL_CHAR SQL_VARCHAR | Data converted without truncation. | 00000 | ||
Conversion of data would result in loss of significant digits. | 22003 | |||
|
The binary C data type is:
Table 208. Converting Binary C Data to SQL Data
fSQLType | Test | SQLSTATE |
---|---|---|
SQL_CHAR SQL_VARCHAR SQL_LONGVARCHAR SQL_CLOB | Length of data <= Column length | N/A |
Length of data > Column length | 22001 | |
SQL_BINARY SQL_VARBINARY SQL_LONGVARBINARY SQL_BLOB | Length of data <= Column length | N/A |
Length of data > Column length | 22001 |
The Double Byte C data type is:
Table 209. Converting DBCHAR C Data to SQL Data
fSQLType | Test | SQLSTATE |
---|---|---|
SQL_CHAR SQL_VARCHAR SQL_LONGVARCHAR SQL_CLOB | Length of data <= Column length x 2 | N/A |
Length of data > Column length x 2 | 22001 | |
SQL_BINARY SQL_VARBINARY SQL_LONGVARBINARY SQL_BLOB | Length of data <= Column length x 2 | N/A |
Length of data > Column length x 2 | 22001 |
The date C data type is:
Table 210. Converting Date C Data to SQL Data
fSQLType | Test | SQLSTATE | ||||
---|---|---|---|---|---|---|
SQL_CHAR SQL_VARCHAR | Column length >= 10 | 00000 | ||||
Column length < 10 | 22003 | |||||
SQL_DATE | Data value is a valid date | 00000 | ||||
Data value is not a valid date | 22007 | |||||
SQL_TIMESTAMP a | Data value is a valid date | 00000 | ||||
Data value is not a valid date | 22007 | |||||
|
The time C data type is:
Table 211. Converting Time C Data to SQL Data
fSQLType | Test | SQLSTATE | ||||
---|---|---|---|---|---|---|
SQL_CHAR SQL_VARCHAR | Column length >= 8 | 00000 | ||||
Column length < 8 | 22003 | |||||
SQL_TIME | Data value is a valid time | 00000 | ||||
Data value is not a valid time | 22007 | |||||
SQL_TIMESTAMP a | Data value is a valid time | 00000 | ||||
Data value is not a valid time | 22007 | |||||
|
The timestamp C data type is:
Table 212. Converting Timestamp C Data to SQL Data
fSQLType | Test | SQLSTATE | ||
---|---|---|---|---|
SQL_CHAR SQL_VARCHAR | Column length >= Display size | 00000 | ||
19 <= Column length < Display size a | 22001 | |||
Column length < 19 | 22003 | |||
SQL_DATE | Data value is a valid date b | 22001 | ||
Data value is not a valid date | 22007 | |||
SQL_TIME | Data value is a valid time c | 22001 | ||
Data value is not a valid time | 22007 | |||
SQL_TIMESTAMP | Data value is a valid timestamp | 00000 | ||
Data value is not a valid timestamp | 22007 | |||
SQLSTATE 00000 is not returned by SQLError(), rather it is indicated when the function returns SQL_SUCCESS. |
Table 213. C to SQL Data Conversion Examples
C Data Type | C Data Value | SQL Data Type | Column length | SQL Data Value | SQL STATE | ||
---|---|---|---|---|---|---|---|
SQL_C_CHAR | abcdef\0 | SQL_CHAR | 6 | abcdef | 00000 | ||
SQL_C_CHAR | abcdef\0 | SQL_CHAR | 5 | abcde | 22001 | ||
SQL_C_CHAR | 1234.56\0 | SQL_DECIMAL | 6 | 1234.56 | 00000 | ||
SQL_C_CHAR | 1234.56\0 | SQL_DECIMAL | 5 | 1234.5 | 22001 | ||
SQL_C_CHAR | 1234.56\0 | SQL_DECIMAL | 3 | --- | 22003 | ||
SQL_C_FLOAT | 1234.56 | SQL_FLOAT |
not applicable | 1234.56 | 00000 | ||
SQL_C_FLOAT | 1234.56 | SQL_INTEGER |
not applicable | 1234 | 22001 | ||
|