Subject | Re: [firebird-support] problem with before update trigger |
---|---|
Author | Fernando Medeiros |
Post date | 2009-12-10T01:01:36Z |
use Coalesce in the code
2009/12/9 Helen Borrie <helebor@...>
http://twitter.com/fernandomds
http://fernandomedeiros.com.br/blog
[Non-text portions of this message have been removed]
2009/12/9 Helen Borrie <helebor@...>
>--
>
> At 09:27 AM 10/12/2009, you wrote:
> >hi ,
> >maybe it is late , so i can't be over
> >a little silly problem :
> >
> >in a table i have a field 'testupdated' ,
> >in the same table in the before update event i have
> >a trigger : ' mytable.testupdated = 'S' ,
> >of course i can''t set its value to 'N' ......that trigger will change it
> in 'S' ,
> >is it possible to exclude fields from that event ?
> >.... in other words : don't fire the trigger when the field 'testupdated'
> changes
>
> First, never refer to the "self" table. When you refer to fields in the
> self table, refer to the "old" and "new" arrays.
>
> Next, don't do unconditional operations in triggers unless you INTEND for
> them to be unconditional.
>
> Replace this line with:
>
> if (
> (old.testupdated is null and new.testupdated is not null)
> or
> (new.testupdated = old.testupdated)
> or
> (new.testupdated is null and old.testupdated is not null)
>
> ) then
> new.testupdated = 'S';
>
> (or whatever logic you intend to achieve with this trigger...)
>
> ./heLen
>
>
>
http://twitter.com/fernandomds
http://fernandomedeiros.com.br/blog
[Non-text portions of this message have been removed]