SQL to C data conversion

To convert SQL data types to C data types, you need to know the arguments: fCType , cbValueMax, rgbValue, and pcbValue. The SQLSTATE for each conversion outcome isreturned.

For each SQL data conversion type, a table lists conversion information. Each column in these tables lists the following information:
  • The first column of the table lists the legal input values of the fCType argument in SQLBindCol() and SQLGetData().
  • The second column lists the outcomes of a test, often using the cbValueMax argument specified in SQLBindCol() or SQLGetData(), which the driver performs to determine if it can convert the data.
  • The third and fourth columns list the values (for each outcome) of the rgbValue and pcbValue arguments specified in the SQLBindCol() or SQLGetData() after the driver has attempted to convert the data.
  • The last column lists the SQLSTATE returned for each outcome by SQLFetch(), SQLExtendedFetch(), or SQLGetData().

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 nul-termination character. If rgbValue is a null pointer, SQLBindCol() or SQLGetData() returns SQLSTATE HY009 (Invalid argument value).

In the following tables:
Data length
The total length, in bytes, of the data after it has been converted to the specified C data type (excluding the nul-termination character if the data was converted to a string). This is true even if data is truncated before it is returned to the application.
Significant digits
The minus sign (if needed) and the digits to the left of the decimal point.
Display size
The total number of bytes needed to display data in the character format.