The SQLSTATE variable
The SQLSTATE variable is a five-character string that the database server sets after it executes each SQL statement.
The header file, sqlca.h, declares SQLSTATE as a global variable. Since the preprocessor automatically includes sqlca.h in the program, you do not need to declare SQLSTATE.
- The database server stores the exception value in the RETURNED_SQLSTATE field of the diagnostics area.
- copies the value of the RETURNED_SQLSTATE field to the global SQLSTATE variable.
EXEC SQL get diagnostics exception 1 :SQLSTATE = RETURNED_SQLSTATE;
The value in SQLSTATE is the status
of the most-recently executed SQL statement before the GET DIAGNOSTICS
statement executed. If the database server encounters an error when
it executes the GET DIAGNOSTICS statement, it sets SQLSTATE to "IX001"
and
sets SQLCODE (and sqlca.sqlcode) to the value of the
error number that corresponds to the error; the contents of the diagnostics
area are undefined.
- The INFORMIX_SQLCODE field of the diagnostics area
- The SQLCODE variable