Database Reference
In-Depth Information
Actions
After specifying the condition, we need to specify the action. There are many
actions we can specify in the
WHENEVER
statement. These actions occur when one of
these,
SQLERROR
,
SQLWARNING
, or
NOT FOUND
, conditions are met. Let's consider the
following actions:
•
CONTINUE
: This action means do nothing and ignore the condition
•
GOTO label
: This action means to jump to the deined label (labels is a C
code label)
•
GO TO label
: This is a synonym of
GOTO
•
SQLPRINT
: This action prints the error message
•
STOP
: This action terminates the program using
EXIT
(1)
•
DOBREAK
: This action breaks the loop or
SWITCH
statement; it is done using
the C programming's
BREAK
statement
•
CALL name (args)
: This action calls the C function
•
DO name (args)
: This is a synonym of
CALL
Here is a detailed example of the preceding discussed conditions and actions
(the code branch and the code based on
WHENEVER
conditions).
First the code captures the
SQLERROR
condition and prints the error as follows:
EXEC SQL WHENEVER SQLERROR SQLPRINT;
After this code, capture
SQLERROR
again and jump to the C label
ERROR_LABEL
as follows:
EXEC SQL WHENEVER SQLERROR GOTO error_label;
Consider the following example, which uses the preceding discussed conditions
and actions:
/*----------------------------------------------------------------
*
*ecpg_error.pgc
*Communicating PostgreSQL Server using ECPG
*
*IDENTIFICATION
*ecpg_error.pgc
*
*----------------------------------------------------------------
*/