SQL to C data conversion examples

The SQL data types you can convert to C data types are character, graphic, numeric, binary, date, time, timestamp, ROWID, and XML data.

The following table shows example SQL to C data conversions and the SQLSTATE values that are associated with these conversions.

Table 1. SQL to C data conversion examples
SQL data type SQL data value C data type cbValueMax rgbValue SQLSTATE
SQL_CHAR abcdef SQL_C_CHAR 7 abcdef\01 000002
SQL_CHAR abcdef SQL_C_CHAR 6 abcde\0 1 01004
SQL_DECIMAL 1234.56 SQL_C_CHAR 8 1234.56\0 1 000002
SQL_DECIMAL 1234.56 SQL_C_CHAR 5 1234\0 1 01004
SQL_DECIMAL 1234.56 SQL_C_CHAR 4 --- 22003
SQL_DECIMAL 1234.56 SQL_C_FLOAT Ignored 1234.56 000002
SQL_DECIMAL 1234.56 SQL_C_SHORT Ignored 1234 01004
SQL_TYPE_DATE 1992-12-31 SQL_C_CHAR 11 1992-12-31\0 1 000002
SQL_TYPE_DATE 1992-12-31 SQL_C_CHAR 10 --- 22003
SQL_TYPE_DATE 1992-12-31 SQL_C_TYPE_TIMESTAMP Ignored 1992,12,31, 0,0,0,03 000002
SQL_TYPE_TIMESTAMP 1992-12-31 23:45:55.12 SQL_C_CHAR 23 1992-12-31 23:45:55.12\0 1 000002
SQL_TYPE_TIMESTAMP 1992-12-31 23:45:55.12 SQL_C_CHAR 22 1992-12-31 23:45:55.1\0 1 01004
SQL_TYPE_TIMESTAMP 1992-12-31 23:45:55.12 SQL_C_CHAR 18 --- 22003
Notes:
  1. "\0" represents a nul-termination character.
  2. SQLSTATE 00000 is not returned by SQLGetDiagRec(), rather it is indicated when the function returns SQL_SUCCESS.
  3. The numbers in this list are the numbers stored in the fields of the TIMESTAMP_STRUCT structure.