Subject Re: [firebird-support] Re: acces on old field value on after delete
Author Helen Borrie
At 02:06 PM 29/08/2004 +0000, you wrote:
> > Currently, yes. But the behaviour is changed in HEAD so, in the next
> > version, you will get an exception if your delete trigger code
>refers to
> > the NEW variables or your insert code refers to the OLD.
> >
>If yes then why is it that the update result is not null? for example
>if i have this ...
>
>update table
>set qty = qty -old.qty + new.qty
>
>in after insert event wherein the old.qty is null.

Possibly it's just a no-op currently, rather than null...which would be OK
for now (if it's so) but not OK for future versions. So it's better to
write the safe code NOW, rather than have to fix it when you upgrade.

i.e.
declare update_qty integer = 0;
...
if (inserting or updating) then
update_qty = update_qty + new.qty;
if (updating or deleting) then
update_qty = update_qty - old.qty;
update table
set qty = qty + :update_qty
where {search criteria} ;

./heLen