SQL to C conversion for character data

The character SQL data types that you can convert to C data types are SQL_CHAR, SQL_VARCHAR, SQL_LONGVARCHAR, and SQL_CLOB.

The following table shows information about converting character SQL data to C data.

Table 1. Converting character SQL data to C data
fCType Test rgbValue pcbValue SQLSTATE
  • SQL_C_CHAR
  • SQL_C_WCHAR
Data length < cbValueMax Data Data length (in bytes)1 000002
Data length >= cbValueMax Truncated data Data length (in bytes) 01004
SQL_C_BINARY Data length <= cbValueMax Data Data length (in bytes) 000002
Data length > cbValueMax Truncated data Data length (in bytes) 01004
  • SQL_C_DECIMAL64
  • SQL_C_DECIMAL128
Data converted without truncation Data Data length (in bytes) 000001
Data is not a number Untouched Data length (in bytes) 220053
  • SQL_C_SHORT
  • SQL_C_LONG
  • SQL_C_BIGINT
  • SQL_C_FLOAT
  • SQL_C_DOUBLE
  • SQL_C_TINYINT
  • SQL_C_BIT
Data converted without truncation3 Data Size (in bytes) of the C data type 000002
Data converted with truncation, but without loss of significant digits3 Data Size (in bytes) of the C data type 01004
Conversion of data would result in loss of significant digits3 Untouched Size (in bytes) of the C data type 22003
Data is not a number3 Untouched Size (in bytes) of the C data type 22005
SQL_C_TYPE_DATE Data value is a valid date3 Data 64 000002
Data value is not a valid date3 Untouched 64 22008
SQL_C_TYPE_TIME Data value is a valid time3 Data 64 000002
Data value is not a valid time3 Untouched 64 22008
SQL_C_TYPE_TIMESTAMP Data value is a valid timestamp3 Data 164 000002
Data value is not a valid timestamp3 Untouched 164 22008
SQL_C_TYPE_TIMESTAMP_EXT Data value is a valid timestamp3 Data 204 000002
Data value is not a valid timestamp3 Untouched 204 22008
Notes:
  1. For the SQL_C_WCHAR data type, the data length is the number of bytes of UCS-2 Unicode data.
  2. SQLSTATE 00000 is not returned by SQLGetDiagRec(), rather it is indicated when the function returns SQL_SUCCESS.
  3. The value of cbValueMax is ignored for this conversion. The driver assumes that the size of rgbValue is the size of the C data type.
  4. This is the size of the corresponding C data type.