The WHENEVER statement must appear before the SQL statements you want to 
affect. Otherwise, the precompiler does not know that additional error handling 
code should be generated for the executable SQL statements. You can have any 
combination of the three basic forms active at any time. The order in which you 
declare the three forms is not significant.
To avoid an infinite looping situation, ensure that you undo the WHENEVER 
handling before any SQL statements are executed inside the handler. You can do 
this using the WHENEVER SQLERROR CONTINUE statement.
Declaring the SQLCA for error handling
You can declare the SQLCA in your application program so that the database 
manager can return information to your application. When you preprocess your 
program, the database manager inserts host language variable declarations in 
place of the INCLUDE SQLCA statement. The system communicates with your 
program using the variables for warning flags, error codes, and diagnostic 
information.
After executing each SQL statement, the system returns a return code in both 
SQLCODE and SQLSTATE. SQLCODE is an integer value that summarizes the 
execution of the statement, and SQLSTATE is a character field that provides 
common error codes across IBM's relational database products. SQLSTATE 
also conforms to the ISO/ANS SQL92 and FIPS 127 2 standard.
Note that if SQLCODE is less than 0, it means an error has occurred and the 
statement has not been processed. If the SQLCODE is greater than 0, it means a 
warning has been issued, but the statement is still processed.
For a DB2 application written in C or C++, if the application is made up of multiple 
source files, only one of the files should include the EXEC SQL INCLUDE 
SQLCA statement to avoid multiple definitions of the SQLCA. The remaining 
source files should use the following lines:
#include "sqlca.h"
extern struct sqlca sqlca;
Condition handling in DB2 stored procedure
Although the content of this book is based on MySQL Version 4, and stored 
procedure support is advertised for Version 5 of MySQL, it seems appropriate to 
include a few examples of DB2 condition handling. For detailed information on 
condition handlers you may refer to DB2 UDB manual 
Application Development 
Guide: Programming Server Applications, 
SC09 4827.
The general form of a handler declaration is:
   DECLARE     + CONTINUE +     HANDLER   FOR   condition      >
 Chapter 7. Application porting 
219






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

san diego web hosting

 

Our partners: PHP: Hypertext Preprocessor Cheap Web Hosting JSP Web Hosting Ontario Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Java Hosting Cheapest Hosting

Visionwebhosting.net Business web hosting division of Vision Web Hosting Inc.. All rights reserved