C to SQL conversion for character data

You can convert the C data types, SQL_C_CHAR and SQL_C_WCHAR, to SQL data types.

The data length for the SQL_C_WCHAR data type is the number of bytes of UCS-2 Unicode data.

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

Table 1. Conversion of character C data to SQL data
fSqlType Test SQLSTATE
  • SQL_CHAR
  • SQL_VARCHAR
  • SQL_LONGVARCHAR
  • SQL_CLOB
Data length <= Column length 000001
Data length > Column length 01004
  • SQL_DECIMAL
  • SQL_NUMERIC
  • SQL_SMALLINT
  • SQL_INTEGER
  • SQL_BIGINT
  • SQL_REAL
  • SQL_FLOAT
  • SQL_DOUBLE
  • SQL_DECFLOAT
Data converted without truncation 000001
Data converted with truncation, but without loss of significant digits 01004
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 (Data length) < Column length N/A
(Data length) >= Column length 01004
Data value is not a hexadecimal value 22005
SQL_ROWID Data length <= Column length 000001
Data length > Column length 01004
SQL_TYPE_DATE Data value is a valid date 000001
Data value is not a valid date 22008
SQL_TYPE_TIME Data value is a valid time 000001
Data value is not a valid time 22008
Data value is a valid timestamp; time portion is nonzero 010041
SQL_TYPE_TIMESTAMP Data value is a valid timestamp 000001
Data value is not a valid timestamp. 22008
Data value is a valid timestamp; fractional seconds portion is nonzero 01004
  • SQL_GRAPHIC
  • SQL_VARGRAPHIC
  • SQL_LONGVARGRAPHIC
  • SQL_DBCLOB
Data length / 2 <= Column length 000001
Data length / 2 < Column length 01004
SQL_XML None 000001
Note:
  1. SQLSTATE 00000 is not returned by SQLGetDiagRec(), rather it is indicated when the function returns SQL_SUCCESS.