Progress
Embedded SQL-92
Guide and Reference
Branching Under Exceptions
The main advantage of the WHENEVER statement is its capability to branch under exceptions. The syntax for the WHENEVER statement shows how you specify branching in response to an exception condition:
These are the exception conditions for which you can specify branching:
NOT FOUND
The exception
NOT FOUND
is set whenSQLCODE
is set toSQL_NOT_FOUND
.SQLERROR
The exception
SQLERROR
is set whenSQLCODE
is set to negative.SQLWARNING
The exception
SQLWARNING
is set when SQLWARN[0] is set to 'W'.GOTO | GO TO host_language_label
Specifying the
GOTO
host_language_label orGO TO
host_language_label causes control to pass to the statement at that label.STOP
STOP
terminates the program.CONTINUE
EXAMPLE
CONTINUE
ignores the SQLCA status and control passes to the next statement in the program.The following code fragment uses the WHENEVER statement for exception handling in an ESQL program that deletes a row:
You should specify CONTINUE in the WHENEVER statement in the exception handling code. This prevents the WHENEVER statement from passing control to the same label, which results in a program loop if any of the SQL statements within the label fail.
Use either CONTINUE or GOTO with the WHENEVER statement, rather than STOP. Although STOP is valid, using it terminates the program without any final reporting.
Handle the SQL_NOT_FOUND Condition
When you issue a FETCH operation and there are no more rows to be fetched, the database sets SQL_NOT_FOUND in the SQLCA. When your application evaluates the SQLCA and finds SQL_NOT_FOUND, your application should close the cursor.
An UPDATE or DELETE operation can return the SQL_NOT_FOUND when no rows are updated or deleted because there are no rows to satisfy the conditions in the WHERE clause.
Using WHENEVER with Explicit Error Checking
In combination with the WHENEVER statement, your application can explicitly evaluate the SQLCA.
EXAMPLEThe code fragment in the next example illustrates explicitly evaluating the SQLCA:
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |