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 a valid timestamp2 000001
Data value is not a valid date or timestamp 22008
SQL_TYPE_TIME Data value is a valid time 000001
Data value is not a valid time or timestamp 22008
Data value is a valid timestamp3 000001
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 truncated 01004
Data value is valid timestamp; time zone portion is nonzero. 01004
SQL_TYPE_TIMESTAMP_WITH_TIMEZONE Data value is a valid timestamp with time zone 000001
Data value is not a valid timestamp with time zone 22008
Data value is a valid timestamp, and time zone fields are not specified4 000001
Data value is a valid timestamp with time zone; fractional seconds truncated 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.
  2. Only the date portion of the timestamp is considered.
  3. Only the time portion of the timestamp is considered.
  4. The time zone component of TIMESTAMP is set based on either CLIENTTIMEZONE, SESSIONTIMEZONE, or the current system time zone of the machine the application is running.