Domanda

In oracle pro *c/c++

EXEC SQL WHENEVER SQLERROR DO break;

What this statement actually do? This inserts the break statement at all the following exec sql statements?

How to limit the scope of do break?

È stato utile?

Soluzione

From the documentation:

DO BREAK

An actual "break" statement is placed in your program. Use this action in loops. When the WHENEVER condition is met, your program exits the loop it is inside.

So whenever an error is encountered, a break will be issued, which won't mean much outside a loop. If you want to reset the behaviour after a particular statement, issue EXEC SQL WHENEVER SQLERROR CONTINUE; to reset to the default error handling behaviour:

CONTINUE

Your program continues to run with the next statement if possible. This is the default action, equivalent to not using the WHENEVER directive. You can use it to turn off condition checking.

Effectively you can sandwich a statement between two WHENEVER directives to make it apply only to that statement.

Altri suggerimenti

The statement works like C/C++ macros: it applies from declaration point till the end of the file or till a redeclaration, so you have to redeclare it

This statment act like a C Preprocessor macro, so it acts starting from where the statment is inserted in the code till the end of the source file or when the same statment is re-declared with a different command. Doesn't matter if you declare it inside a function, for, while or any other code block: the statment applies from his declaration till the end of file or a next declaration

I use often this directive for handling cursors inside Pro*C++ source code:

EXEC SQL WHENEVER NOT FOUND DO THROW_SQLERROR("free text"); // If no data found execute THROW_SQLERROR macro.

        try
        {
            EXEC SQL DECLARE c CURSOR FOR
                SELECT field
                FROM table;

            EXEC SQL OPEN c;

            while(1)
            {
EXEC SQL WHENEVER NOT FOUND DO break; // if no data found execute C break
                EXEC SQL FETCH c INTO :iField;
EXEC SQL WHENEVER NOT FOUND DO THROW_SQLERROR("free text"); // If no data found execute C THROW_SQLERROR macro.

                ...
            }

            EXEC SQL CLOSE c;
        }
        catch(...) 
        { 
            try { EXEC SQL CLOSE c; } catch(...) { }
            throw;
        }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top