SQL/MX 3.1 Programming Manual for C and COBOL (H06.23+, J06.12+)
Exception Handling and Error Conditions
HP NonStop SQL/MX Release 3.1 Programming Manual for C and COBOL—663854-001
13-17
Accessing and Using the Diagnostics Area
...
EXEC SQL BEGIN DECLARE SECTION;
char SQLSTATE[6];
...
EXEC SQL END DECLARE SECTION;
...
EXEC SQL WHENEVER SQLERROR CALL sql_error;
...
EXEC SQL OPEN get_by_partnum;
EXEC SQL FETCH get_by_partnum
INTO :hv_partnum,:hv_partdesc,:hv_price,:hv_qty_available;
...
while (strcmp(SQLSTATE, SQLSTATE_OK) == 0) {
if ( hv_qty_available < 1000 )
EXEC SQL UPDATE parts
SET qty_available = qty_available + 100
WHERE CURRENT OF get_by_partnum;
...
EXEC SQL FETCH get_by_partnum
INTO :hv_partnum,:hv_partdesc,:hv_price,:hv_qty_available;
}
...
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










