The WHENEVER statement specifies the action (CONTINUE, GOTO, or CALL) to be taken when one of three possible SQLCODE conditions is met following the execution of an Embedded SQL statement.
WHENEVER {SQLWARNING | SQLERROR | NOT FOUND} {CONTINUE | GOTO stmt_label | CALL function()}
SQLCODE conditions have the following values.
Condition | Value | Example |
---|---|---|
No error | 0 | |
NOT FOUND | 100 | Fetch past end of results |
SQLWARNING | +1 | Data truncation on output |
SQLERROR | < 0 (negative) | Constraint violation |
For more information about how to handle specific error conditions programmatically using SQLSTATE values, see SQLSTATE Messages.
The following SQLCODE values are revised in ESQL/C version 6.5 and are carried to version 7.0.
Condition | New value | Previous value |
---|---|---|
Singleton SELECT statement returns more than 1 row | -1 | 1 |
NULL value returns, but no indicator variable declared | -1 | 0 |
Second attempt to open cursor without corresponding close while CLOSE_ON_COMMIT is in force | -1 | 0 |
Server error encountered on cursor open | -nnn..., where nnn is a server message number | -19521 |
WHENEVER statement actions are related to the position of statements in the source code, not in the run sequence. The default is CONTINUE for all conditions.
EXEC SQL WHENEVER sqlerror GOTO displayca;
.
.
.
EXEC SQL WHENEVER sqlerror CALL error_funct(param);
Using the WHENEVER Statement | Advanced Programming |