Subject | Re: Trigger to prevent a deletion? |
---|---|
Author | sgharp |
Post date | 2004-08-02T17:03:58Z |
--- In firebird-support@yahoogroups.com, "Martijn Tonies"
<m.tonies@u...> wrote:
to not delete the record.
Steve
<m.tonies@u...> wrote:
>not
> > > > I have some tables that contain records that the user should
> > bewith
> > > > able to modify or delete. Other records in the same table
> > should be
> > > > freely modified, deleted, whatever. I'm trying to come up
> > > > an 'on update or delete' trigger that will prevent thechange if
> > ato
> > > > field value exists.
> > > >
> > > > if (NEW.SomeField = 0) then
> > > > DoNotChangeMe;
> > > >
> > > > Is something like this possible from within a trigger or is
> > there a
> > > > better way to protect these records at the server level?
> > >
> > > You can do this via a trigger that raises an exception...
> > >
> > > Here's an example:
> > > CREATE EXCEPTION DELETE_NOT_ALLOWED 'System data - not allowed
> > deleteserver
> > > this.';
> > >
> > >
> > > SET TERM ^^ ;
> > > CREATE TRIGGER CATEGORIE_SYSTEEM FOR CATEGORIE ACTIVE BEFORE
> > DELETE POSITION
> > > 0 AS
> > > BEGIN
> > > if (old.SYSTEEM = 'T')
> > > then exception DELETE_NOT_ALLOWED;
> > > END
> > > ^^
> > > SET TERM ; ^^
> > >
> > > Of course, you DO need to handle the exception :-)
> >
> > I can see where this would work but I would prefer that the
> > just disallow the deletion. I don't want my client applicationto
> > have to handle the exception; I just want the record to not beI don't need an exception or any feedback. I just want the server
> > deleted. Is there another way?
>
> Define "just disallow" --
>
> * raise an exception?
> * ignore the DELETE?
>
> How would this work, what would be your feedback?
to not delete the record.
Steve