WHENEVER Statement
The WHENEVER statement tells the preprocessor to generate code that checks the value of SQLCODE or SQLSTATE for a specified condition after each SQL request. The WHENEVER statement has the following syntax:
When using SQLCODE, specify the SQLERROR condition so the preprocessor generates code that checks for a negative value in SQLCODE. Specify the NOT FOUND condition so the preprocessor generates code that checks for a value of +100 in SQLCODE (no row satisfies the SQL request). For more information, see the "Error Handling" section.
You can specify an action for the SQLERROR or NOT FOUND condition. The target of a GOTO action (label) is a standard C Language label name. The program branches to this label when it detects the specified condition. For the SQLERROR and NOT FOUND conditions, the default action is CONTINUE, which causes the program to ignore the condition and continue with the next statement.
The specified condition and action remains in effect until you specify another WHENEVER statement for the same condition. Any new action overrides the previous one. However, you can explicitly test the value of SQLCODE or SQLSTATE in a C statement at any point in your program without affecting the current WHENEVER statement specifications.
In this example, the WHENEVER statement signals the preprocessor to generate code that transfers program control to err when an SQL error condition occurs.
In the following example, the program continues execution whenever no record is found to satisfy an SQL request, such as a searched SELECT or cursor FETCH.
The parameter values of
sqlcdbind()
depend on the variables declared in an SQL declare section. Table 2–4 lists the parameter values of sqlcdbind for the three possible conditions.
If SQLSTATE is declared in an SQL declare section but SQLCODE is not, the preprocessor generates the following from the WHENEVER SQL ERROR statement:
In either of the other conditions listed in Table 2–4, the preprocessor generates the following:
If SQLSTATE is declared in an SQL declare section but SQLCODE is not, the preprocessor generates the following from the WHENEVER NOT FOUND statement:
In either of the other conditions listed in Table 2–4, the preprocessor generates the following:
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |