SQLCODE and SQLSTATE
SQLCODE and SQLSTATE are variables in which the DBMS returns ANSI/ISO Entry-92-compliant status codes indicating the results of the last SQL statement that was executed.
SQLCODE Variable
SQLCODE is an integer variable in which the DBMS returns the status of the last SQL statement executed. For details about the requirements for declaring the SQLCODE variable in embedded programs, see the Ingres Embedded SQL Companion Guide.
Note: The ANSI Entry SQL-92 specification describes SQLCODE as a deprecated feature and recommends using the SQLSTATE variable.
Values Returned by SQLCODE
The values returned in the standalone SQLCODE variable are the same as those returned in the sqlcode member of the SQLCA structure. The value of SQLCODE is meaningful only in the context of a session.
The values returned in SQLCODE are listed in the following table:
SQLSTATE Variable
The SQLSTATE variable is a 5-character string in which the DBMS Server 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 Ingres Embedded SQL Companion Guide.
Note: If queries are executed while connected (through an Enterprise Access product) to a DBMS server 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, use one of the other error-checking methods.
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 example illustrates 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: 11/09/2022