SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)

Exception Handling and Error Conditions
HP NonStop SQL/MX Programming Manual for C and COBOL523627-004
13-13
Accessing and Using the Diagnostics Area
return 0;
} /* end main */
...
void sql_error() {
EXEC SQL BEGIN DECLARE SECTION;
char SQLSTATE[6];
long hv_num;
unsigned short i;
char hv_sqlstate[6];
VARCHAR hv_msgtxt[129];
EXEC SQL END DECLARE SECTION;
EXEC SQL GET DIAGNOSTICS
:hv_num = NUMBER;
for (i = 1; i <= hv_num; i++) {
EXEC SQL GET DIAGNOSTICS EXCEPTION :i
:hv_sqlstate = RETURNED_SQLSTATE,
:hv_msgtxt = MESSAGE_TEXT;
...
}
} /* end sql_error */
Accessing and Using the Diagnostics Area
NonStop SQL/MX stores completion and exception information in the diagnostics area.
At the beginning of the execution of an SQL statement, the diagnostics area is
emptied. When the statement executes, NonStop SQL/MX places information on
completion or exception conditions in this area.
A transaction has a diagnostics area limit, which is a positive integer that specifies the
maximum number of conditions that can be placed in the diagnostics area during
execution of an SQL statement within the transaction. Use the SET TRANSACTION
statement to set the size of the diagnostics area.
To access the information in the diagnostics area, use the GET DIAGNOSTICS
statement. The diagnostics area consists of:
Statement information: Header area consisting of information on the SQL
statement as a whole.
Condition information: Detail area about each error, warning, or completion code
that appeared during the execution of an SQL statement.
NonStop SQL/MX automatically allocates the diagnostics area in a program. You are
not required to explicitly allocate it yourself.
For a description of the statement and condition items and the syntax, see the GET
DIAGNOSTICS statement in the SQL/MX Reference Manual.
Using the GET DIAGNOSTICS Statement
Use this general syntax:
GET DIAGNOSTICS {statement-info | condition-info}