The SQLCA diagnostic record

The SQLCA variable is a predefined record containing SQL statement execution information.

The SQLCA record definition

The SQLCA record is defined as follows:

DEFINE SQLCA RECORD
  SQLCODE INTEGER,
  SQLERRM VARCHAR(71),
  SQLERRP CHAR(7),
  SQLERRD ARRAY[6] OF INTEGER,
  SQLAWARN CHAR(7)
END RECORD
  1. SQLCODE contains the SQL execution code ( 0 = OK, 100 = not row found, <0 = error ).
  2. SQLERRM contains the error message parameter.
  3. SQLERRP is not used at this time.
  4. SQLERRD[1] is not used at this time.
  5. SQLERRD[2] contains the last SERIAL or the native SQL error code.
  6. SQLERRD[3] contains the number of rows processed in the last statement (server dependent).
  7. SQLERRD[4] contains the estimated CPU cost for the query (server dependent).
  8. SQLERRD[5] contains the offset of the error in the SQL statement text (server dependent).
  9. SQLERRD[6] contains the ROWID of the last row that was processed (server dependent).
  10. SQLAWARN contains the ANSI warning represented by a W character at a given position in the string.
  11. SQLAWARN[1] is set to W when any of the other warning characters have been set to W.
  12. SQLAWARN[2-7] have specific meanings, see database server documentation for more details.

Usage

The "SQLCA" acronym stands for the SQL Communication Area variable.

The SQLCA record can be used to get an SQL execution diagnostic. Error and warning information can be found in this structure.

The SQLCA record is filled after each SQL statement execution.

SQLCA is not designed to be modified by user code. It must be used as a read-only record.

Portability

SQLCA.SQLCODE will be set to a specific IBM® Informix® SQL error code, provided that the database driver can convert the native SQL error to an IBM Informix SQL error. In case of error, SQLCA.SQLERRD[2] will hold the native SQL error produced by the database server.

Other SQLCA record members are specific to IBM Informix databases. For example, after inserting a row in a table with a SERIAL column, SQLCA.SQLERRD[2] will contain the new generated serial number. After an SQL error occurred, SQLCA.SQLERRD[2] will contain the native SQL error. Furthermore, the SQLCA.SQLERRD[3] member may be set with the number of processed rows, as long as the database client supports this feature. Other SQLCA.SQLERRD[n] members must be considered as non portable.

Example

MAIN
  WHENEVER ERROR CONTINUE
  DATABASE stores 
  SELECT COUNT(*) FROM foo   -- Table should not exist!
  DISPLAY SQLCA.SQLCODE, SQLCA.SQLERRD[2]
END MAIN