Subject Re: [firebird-support] Cancelling an operation in a Trigger
Author Martijn Tonies
Anand,

> Is there any way in FireBird to cancel an INSERT or UPDATE or
> DELETE operation from a BEFORE... trigger? For e.g. if the user
> tries to delete a row from a table and I need to do some
> validations before the row can be deleted, is there any way I
> could write a BEFORE DELETE trigger that would perform the
> validations and cancel the delete operation if a certain result
> was not found?
>
> Thanks in advance for any tips and suggestions,

Raise an exception -

Example:


SET TERM ^^ ;
CREATE TRIGGER CATEGORIE_SYSTEEM FOR CATEGORIE ACTIVE BEFORE DELETE POSITION
0 AS
/*
Trigger:

Author : Martijn Tonies
Date : 28-11-2001 14:12:17
Purpose : Cancel the delete on a "system" categorie

Date :
Changed:
*/

BEGIN
if (old.SYSTEEM = 'T')
then exception DELETE_NOT_ALLOWED;
END
^^
SET TERM ; ^^

Exception "DELETE_NOT_ALLOWED" is defined as:

CREATE EXCEPTION DELETE_NOT_ALLOWED 'Systeem gegevens - mag niet worden
verwijderd.';


With regards,

Martijn Tonies
Database Workbench - the developer tool for InterBase & Firebird
Upscene Productions
http://www.upscene.com