Return Status and Conditions

In Mimer SQL, status information is returned in the SQLCODE and SQLSTATE variables.

The SQLSTATE variable must be declared as a 5-character long string (excluding any terminating null byte), and the declaration of SQLSTATE must be made between BEGIN DECLARE SECTION and END DECLARE SECTION. The SQLSTATE variable together with the GET DIAGNOSTICS statement will provide the application with information about the most recently executed SQL statement.

The SQLCODE variable must be declared as integer. If neither an SQLSTATE nor an SQLCODE variable is declared between BEGIN DECLARE SECTION and END DECLARE SECTION, Mimer SQL will assume the existence of an SQLCODE variable. (I.e. declared somewhere outside the declare section, but still within scope.)

There are three different types of conditions in Mimer SQL; NOT FOUND, SQLEXCEPTION and SQLWARNING (see the WHENEVER).

The NOT FOUND condition is returned by setting SQLSTATE to No data ('02000'), or by setting SQLCODE to +100. This is referred to as “a NOT FOUND condition code is returned” in this manual.

SQLEXCEPTION’s are returned using an error code in SQLSTATE, or a negative value in SQLCODE. This is referred to as “an error code is returned” in this manual.

SQLWARNING’s are returned by setting either a Success with warning -code in SQLSTATE, or a value > 0 in SQLCODE. This is referred to as “a warning flag is set” in this manual.

More detailed information about certain operations can be obtained by the GET DIAGNOSTICS statement described in GET DIAGNOSTICS.

SQLSTATE Return Codes

SQLSTATE contains a 5 character long return code string that indicates status of an SQL statement. These return codes follows the established standards. Observe that not all standardized SQLSTATE return codes are used by Mimer SQL.

The SQLSTATE values consists of two fields: the class, which is the first two characters of the string, and the subclass, which is the terminating three characters of the string.

For a full list of SQLSTATE values returned by Mimer SQL, see Mimer SQL Programmer's Manual, List of SQLSTATE Values.

SQLCODE Return Codes

The values of SQLCODE are the same as the values for the native Mimer SQL return codes, as described in the Mimer SQL Programmer's Manual, Native Mimer SQL Return Codes.