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-18
Using the GET DIAGNOSTICS Statement
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}
The statement-info is defined as:
target = stmt-item-name [,target = stmt-item-name]...
The condition-info is defined as:
EXCEPTION condition-number
target = condtn-item-name [,target = condtn-item-name]...
The target is a host variable that receives the requested diagnostics information.
target must have the same data type as the stmt-item-name or condtn-item-
name you are requesting. The condition-number specifies the number of an
exception condition. It can be a literal or host variable with exact numeric data type.
Getting Statement and Condition Items
The next example uses the GET DIAGNOSTICS statement to display condition
information after an INSERT statement. The first GET DIAGNOSTICS obtains the
number of condition items. The second GET DIAGNOSTICS loops through the
individual condition items and prints information for each condition.
See Statement Items-GET DIAGNOSTICS and Condition Items-GET DIAGNOSTICS
in the SQL/MX Reference Manual.
You can retrieve the message text of the exception condition for SQLSTATE and
SQLCODE. To provide a log of exception conditions, you can write the SQLSTATE and
SQLCODE values, along with the message text, to a file for future reference.










