Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 17 » SQL Anywhere Server - SQL Reference » SQL statements » Alphabetical list of SQL statements

WHENEVER statement [ESQL]

Specifies error handling in Embedded SQL programs.

Syntax
WHENEVER { 
SQLERROR 
| SQLWARNING 
| NOTFOUND }
GOTO 
   label 
   | STOP 
   | CONTINUE 
   | { C-code; }
label :  identifier
Remarks

The WHENEVER statement is used to trap errors, warnings and exceptional conditions encountered by the database when processing SQL statements. The statement can be put anywhere in an Embedded SQL program and does not generate any code. The preprocessor will generate code following each successive SQL statement. The error action remains in effect for all Embedded SQL statements from the source line of the WHENEVER statement until the next WHENEVER statement with the same error condition, or the end of the source file.

Note The error conditions are in effect based on positioning in the C language source file, not based on when the statements are executed.

The default action is CONTINUE.

This statement is provided for convenience in simple programs. Most of the time, checking the sqlcode field of the SQLCA (SQLCODE) directly is the easiest way to check error conditions. In this case, the WHENEVER statement would not be used. In fact, all the WHENEVER statement does is cause the preprocessor to generate an if ( SQLCODE ) test after each statement.

Privileges

None.

Side effects

None.

Standards
  • ANSI/ISO SQL Standard

    An exception condition declaration made with the WHENEVER statement is a Core Feature. The standard uses the keyword SQLEXCEPTION rather than SQLERROR. The ability to directly include C code in the WHENEVER statement, rather than merely a statement label, is not in the standard. The action STOP is also not in the standard.

Example

EXEC SQL WHENEVER NOTFOUND GOTO done;
EXEC SQL WHENEVER SQLERROR
   {
      PrintError( &sqlca );
      return( FALSE );
   };