6.2 EXEC SQL WHENEVER

Table of Contents Previous Next


6 Error Handling : 6.2 EXEC SQL WHENEVER

Use the EXEC SQL WHENEVER directive to implement simple error handling for client applications compiled with ECPGPlus. The syntax of the directive is:
EXEC SQL WHENEVER condition action;
A SQLERROR condition exists when sqlca.sqlcode is less than zero.
A SQLWARNING condition exists when sqlca.sqlwarn[0] contains a 'W'.
A NOT FOUND condition exists when sqlca.sqlcode is ECPG_NOT_FOUND (when a query returns no data).
You can specify that the client application perform one of the following actions if it encounters one of the previous conditions:
Specify CONTINUE to instruct the client application to continue processing, ignoring the current condition. CONTINUE is the default action.
DO CONTINUE
An action of DO CONTINUE will generate a CONTINUE statement in the emitted C code that if it encounters the condition, skips the rest of the code in the loop and continues with the next iteration. You can only use it within a loop.
GOTO label
or
GO TO
label
Use a C goto statement to jump to the specified label.
Print an error message to stderr (standard error), using the sqlprint() function. The sqlprint() function prints sql error, followed by the contents of sqlca.sqlerrm.sqlerrmc.
Call exit(1) to signal an error, and terminate the program.
Execute the C break statement. Use this action in loops, or switch statements.
CALL name(args)
or
DO name(args)
Invoke the C function specified by the name parameter, using the parameters specified in the args parameter.
Please Note: The ECPGPlus compiler processes your program from top to bottom, even though the client application may not execute from top to bottom. The compiler directive is applied to each line in order, and remains in effect until the compiler encounters another directive.

6 Error Handling : 6.2 EXEC SQL WHENEVER

Table of Contents Previous Next