C and C++ embedded SQL applications can use the WHENEVER condition DO action statement to take a specified action when an exception condition occurs.
>>-EXEC SQL WHENEVER--+-SQLERROR---+--DO--+-BREAK-----------+-->< +-SQLWARNING-+ +-CONTINUE--------+ '-NOT FOUND--' '-function-name()-'
The function name resolution takes place during the compilation of a C and C++ embedded SQL application. The DB2® precompiler does not resolve the function name.
void sqlError(void)
{
switch (sqlca.sqlcode)
{
case -999: // some SQLCODE code
printf ("Error related to -999 occurred\n");
break;
case -888: // some SQLCODE code
printf ("Error related to -888 occurred\n");
break;
default:
printf ("Unknown error occurred\n");
break;
}
exit(-3);
}
int func1() // DO function-name
...
EXEC SQL WHENEVER NOT FOUND DO sqlError();
...
while(sqlca.sqlcode == SQL_RC_OK)
{
// some application logic
}
...
}
int func2() // DO BREAK
{
...
EXEC SQL WHENEVER SQLWARNING DO BREAK;
...
while(...)
{
// some application logic
}
// Causes the next sequential instruction of the source program
// to be executed. Basically voids effect of previous WHENEVER.
EXEC SQL WHENEVER SQLWARNING CONTINUE;
...
}
int func3() // DO CONTINUE
{
...
EXEC SQL WHENEVER NOT FOUND DO CONTINUE;
...
while(...)
{
// some application logic
}
...
}