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

Introduction
HP NonStop SQL/MX Programming Manual for C and COBOL523627-004
1-10
Using GET DIAGNOSTICS
Example
...
EXEC SQL WHENEVER NOT FOUND PERFORM ROW-NOT-FOUND-7000 END-EXEC.
...
EXEC SQL SELECT ... END-EXEC.
...
If the SELECT statement results in an SQLSTATE value of 02000 (no data) condition,
the named error routine is executed.
Using GET DIAGNOSTICS
After the execution of an SQL statement, NonStop SQL/MX places information on
exception conditions into the diagnostics area. The diagnostics area has a size limit,
which is a positive integer that specifies the maximum number of conditions placed into
the area during the execution of the statement. You can access the information in the
diagnostics area by using the GET DIAGNOSTICS statement.
Example
EXEC SQL GET DIAGNOSTICS :num = NUMBER,
:cmdfnc = COMMAND_FUNCTION;
...
for (i = 1; i <= num; i++) {
EXEC SQL GET DIAGNOSTICS EXCEPTION :i
:hv_sqlstate = RETURNED_SQLSTATE,
:hv_msgtext = MESSAGE_TEXT,
...;
};
The first GET DIAGNOSTICS statement returns the number of conditions in the
condition information area and the character string that identifies which SQL statement
executed. The second GET DIAGNOSTICS statement returns the value of SQLSTATE
and the corresponding message text, among other condition information.
See also Section 13, Exception Handling and Error Conditions.
Ensuring Data Consistency
Your application can use the TMF product to ensure the consistency of an SQL/MX
database against concurrent access and system failure.
A TMF transaction—a set of database changes that must be completed as a group—is
the basic recovery unit of NonStop SQL/MX. The typical order of events within a
transaction is:
1. The transaction is started.
2. Database changes are made.
3. Database changes are committed.
COBOL
C