SQL/MX 3.2 Programming Manual for C and COBOL (H06.25+, J06.14+)

Exception Handling and Error Conditions
HP NonStop SQL/MX Release 3.2 Programming Manual for C and COBOL663854-002
13-2
Declaring SQLSTATE
Declaring SQLSTATE
In a C program, declare SQLSTATE as a char array of 6 bytes (char[6]), within the
Declare section. In a COBOL program, declare SQLSTATE of type PIC (5) within the
Declare section.
Examples
In a C program, you must include an extra character for the null terminator. Declare
SQLSTATE within the Declare section:
EXEC SQL BEGIN DECLARE SECTION;
char SQLSTATE[6];
...
EXEC SQL END DECLARE SECTION;
In a COBOL program, declare SQLSTATE within the Declare Section:
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 SQLSTATE PIC X(5).
...
EXEC SQL END DECLARE SECTION END-EXEC.
SQL:1999 SQLSTATE Values
The SQLSTATE variable is a five-character string with two parts. The first part is a
two-character class code, and the second part is a three-character subclass code.
An SQLSTATE value of 00000 indicates successful completion. In C programs,
declare SQLSTATE as type CHAR, with a length of six characters to allow for the null
terminator.
Table 13-1 lists the SQL:1999 SQLSTATE class and subclass values that are
implemented in NonStop SQL/MX.
Table 13-1. SQL:1999 SQLSTATE Class and Subclass Values (page 1 of 2)
Condition Class Subcondition Subclass
Successful completion 00 (No subclass) 000
Warning 01 (No subclass) 000
String data, right truncation 004
Privilege not revoked 006
Privilege not granted 007
No data 02 (No subclass) 000
Dynamic SQL error 07 (No subclass) 000
Invalid descriptor count 008
Invalid descriptor index 009
Feature not supported 0A (No subclass) 000
Cardinality violation 21 (No subclass) 000
C
COBOL