HPlogo ALLBASE/SQL FORTRAN Application Programming Guide: HP 3000 MPE/iX Computer Systems > Chapter 3 Embedding SQL Commands

Implicit Status Checking

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

You can use the WHENEVER command, as at 6 in Figure 3-1, to have ALLBASE/SQL examine SQLCA values and cause a specific action to be taken. The WHENEVER command is a preprocessor directive that specifies the action to be taken for each subsequent SQL command, if an error or warning condition occurs during execution of the SQL command.

   EXEC SQL WHENEVER SQLERROR GOTO 500

   		     |        |

   		     |        |

   		     |        |

   		     |        the action

   		     |

   		     the condition

Preprocessor-generated statements for each WHENEVER command are embedded into the preprocessed code after each subsequent SQL command found in the program's source code. Because of this, you must either end each program unit which contains a WHENEVER condition GOTO label statement with a WHENEVER condition CONTINUE statement, or have a label in each subsequent program unit in the preprocessed source code which corresponds to the appropriate WHENEVER condition GOTO label statement. If no label exists and a WHENEVER condition CONTINUE statement is not entered, an error will occur at compile time.

For example, if execution of the SELECT command at 8 or the SQLEXPLAIN command at 10, illustrated earlier in this chapter, were to cause an error condition, ALLBASE/SQL would take no special action because the WHENEVER command shown at 6 precedes both the SELECT and the SQLEXPLAIN commands in the source listing.

If, however, the WHENEVER SQLERROR CONTINUE statement was not entered and an error occurred at 8, there would be a compile time error as there is no label 500 in Subroutine QueryTable. The WHENEVER SQLERROR CONTINUE command at 6 turns off the implicit status checking of the command that appears earlier in the source listing:

   EXEC SQL WHENEVER SQLERROR GOTO 500

This WHENEVER command specifies where to pass control when an error occurs during execution of the CONNECT, BEGIN WORK, COMMIT WORK, or COMMIT WORK RELEASE commands.

Although you can use a WHENEVER command to have ALLBASE/SQL examine the values in certain fields of the SQLCA, you can also examine the values yourself, as discussed under "Explicit Status Checking" later in this chapter.

Feedback to webmaster