SQL programming / SQL basics |
The SQLCA variable is a predefined record containing SQL statement execution information.
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
SQLCA stands for the SQL Communication Area variable.
The SQLCA 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.
SQLCA.SQLCODE will be set to a specific IBM® Informix® SQL error code, if 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] contains the new generated serial number. After an SQL error, SQLCA.SQLERRD[2] contains the native SQL error. The SQLCA.SQLERRD[3] member may be set with the number of processed rows, if the database client provides the API. Other SQLCA.SQLERRD[n] members must be considered as not portable.
MAIN WHENEVER ERROR CONTINUE DATABASE stores SELECT COUNT(*) FROM foo -- Table should not exist! DISPLAY SQLCA.SQLCODE, SQLCA.SQLERRD[2] END MAIN