Subject Re: Firebird Trigger Local Variable Gotcha
Author Adam
> Interesting. Is there a built-in text logging feature planned for
> Firebird?

Not that I am aware of, the roadmap is available of FirebirdSQL.org.

> 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 :).

No that would also work, and in some ways is probably neater.

> So maybe to prevent the same bug to ever see me face to face again,
> 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.

Well the best way is

blah_var = NULL;
select (blah) from (blah_table) into :blah_var;
if (:blah_var is null) then begin
-- normal processing here
end;

I don't like the exists check because it is doubling the work. It is
also introducing another place you will need to maintain the query.
Whether that is significant enough to worry about, only you can
answer.

Of course if you do not need to know the value you are selecting but
only care about whether such a record exists, then exists is perfect
for that.

> +1 Clairvoyant. I'm a longtime Delphi guy :).

Adam