Was this helpful?
The SQLSTATE Variable
The SQLSTATE variable is a 5‑character string in which OpenSQL returns the status of the last SQL statement executed. The values returned in SQLSTATE are specified in the ANSI/ISO Entry SQL‑92 standard. For details about the requirements for declaring the SQLSTATE variable in embedded programs, see the Embedded SQL Companion Guide.
If queries are executed while connected to a DBMS that does not support SQLSTATE, SQLSTATE is set to '5000K' (meaning “SQLSTATE not available”). This result does not necessarily mean that an error occurred. To check the results of the query, one of the other error‑checking methods must be used. SQLSTATE is not available within database procedures. However, a routine that directly executes a database procedure can check SQLSTATE to determine the result of the procedure call.
The following is a brief example illustrating the use of SQLSTATE in an embedded program:
exec sql begin declare section;

 character     SQLSTATE(5)

exec sql end declare section;

exec sql connect mydatabase;

if SQLSTATE <> "00000" print 'Error on connection!'
Last modified date: 08/14/2024