Subject Firebird Trigger Local Variable Gotcha
Author t.s.
Dear All,

Just thought i'm gonna share this little problem that a customer
reported last friday. Took me 2 days to pinpoint the problem.

In an AFTER UPDATE trigger for a MASTER table, i have the following code:
...
-- for each detail record
for select blah blah blah
from detail_table
where (master_id = new.master_id)
do begin

-- fetch lookup information
select lookup_field
from lookup_table where (lookup_id = new.lookup_id)
into :lookup_var;

-- only process if the lookup information exists
if (lookup_var is null) then begin
...
...
...
end
end
...

Can anyone spot the bug in this ? :)

I was expecting the "lookup_var" local variable to be set to NULL if the
lookup data does not exists. Somehow firebird (1.5.3, Win32) ignores the
"select into" if the select returns NULL.

Adding initialization code BEFORE the 'fetch' operation solves the
problem, but this sure is a difficult 'bug' to find. Has anyone ran into
this problem before? Is this normal, or did i run into a bug ?

Thanks in advance,
t.s.