Subject Re: [ib-support] cancelling a trigger
Author Helen Borrie
At 04:53 PM 14-05-02 -0400, you wrote:

>How can I cancel the execution of an operation before the operation takes
>place, with a trigger?

The normal outcome of a delete operation is to delete the row. I think you
want to stop the operation, not stop the trigger....is this so? You can
use your Before Delete trigger to engineer an exception and thus stop the
operation. Of course, if you want the user to know that the delete failed,
your client will need to listen for the exception (read the message) in the
error status array.

create exception dont_delete 'Delete operation was cancelled...message up
to 78 bytes';

CREATE TRIGGER bd_myTable FOR myTable BEFORE DELETE POSITION 1 AS
BEGIN
IF (someDoNotDeleteCondition = TRUE) THEN
exception dont_delete;
END

If what you wanted instead was to let the delete operation proceed but
prevent some special activity from occurring, then use the exception to
handle the condition:

CREATE TRIGGER bd_myTable FOR myTable BEFORE DELETE POSITION 1 AS
BEGIN
IF (someDoNotDeleteCondition = TRUE) THEN
exception dont_delete; /* flow now jumps to the handler */
/* Code to do the BeforeDelete activity - it will occur only if the
exception
condition is not raised */
WHEN EXCEPTION dont_delete
DO BEGIN
/* Alternative activity */
END
/* If needed, add more stuff to do in any event - even raise more
exceptions
if you want to */
END

In the second case, the handler swallows the exception and the client is
none the wiser.

All for Open and Open for All
Firebird Open SQL Database · http://firebirdsql.org ·
http://users.tpg.com.au/helebor/
_______________________________________________________