Subject | Re: [firebird-support] Re: Firebird Trigger Local Variable Gotcha |
---|---|
Author | t.s. |
Post date | 2006-04-03T04:46:33Z |
> Ouch. Had you posted here it would have been spotted.The problem is that this is a rather large system. Once i made sure that
the problem is in THIS particular trigger, the answer kinda popped out,
after staring at the screen for thirty minutes or so, hehe.
The funny thing was that this particular code was the first part that i
scrutinized, but after scratching my head for some time, i couldn't see
how it could fail, so i moved on to 'widen the net'.
> We have createdInteresting. Is there a built-in text logging feature planned for
> an external function that wraps a call to OutputDebugString which is
> invaluable in debugging PSQL. We use it to confirm the values in
> particular variables when debugging issues. I recommend you try
> something similar.
Firebird? It might come in handy for something like this that needs full
tracing. Otherwise maybe i'll cook up some stored procedure that writes
to an EXTERNAL TABLE.... someone stop me before i'm barking up the wrong
tree again :).
> Please note I am not suggesting this is how it executes, I am sayingYes. Ms Borrie's response also indicated that this is a 'programmer
> that unless there is actually something returned, the variable will
> not be affected.
error' :). I'm going to go kill myself now.
> select nullIf it's up to me,
> from RDB$DATABASE
> into :lookup_var;
> What is in lookup_var.
I would argue that lookup_var should be NULL at this point :).
"I keed, I keed~~!! :)".
> NULL does not mean empty. It means that the value of a particularThanks. Will do.
> field is unknown or unspecified. Google for the Firebird NULL guide
> for all the gotchas there.
> There is a difference between 'not knowing the value where a record isSo maybe to prevent the same bug to ever see me face to face again,
> known to exist' and 'knowing that no records exist'.
would it be better to change the "check whether something exists"
construct from :
...
select (blah) from (blah_table) into :blah_var;
if (:blah_var is null) then begin
-- normal processing here
end;
...
to
...
if (exists(blah blah blah)) then begin
select (blah) from (blah_table) into :blah_var;
...
-- normal processing here
end
...
The downside is that it'd be slightly slower due to having to do the
query twice.
> You also correctly worked out you need to initialise it first. It can+1 Clairvoyant. I'm a longtime Delphi guy :).
> be a difficult error to find, especially if you are used to languages
> like Delphi which tend to pre-initialise variables for you.
Thanks again.
t.s.