Subject RE: [firebird-support] Re: The New command in triggers
Author Helen Borrie
At 10:31 AM 16/02/2006, you wrote:
>I have some further questions based on Milan's advice since I have not come
>across the concept of NULL in Boolean evaluation before.

But you might have heard of UNKNOWN? In Boolean evaluation, the
result will be true if the condition is met and false otherwise. An
UNKNOWN result in Firebird resolves to a result of False, not NULL.

In many expressions, the result of a calculation involving NULL and
value will return NULL, representing an UNKNOWN result.

>
>If NULL=NOTNULL evaluates to NULL does
>
>NULL<>NOTNULL also evaluate to NULL?

Assuming you meant to say "a value" rather than NOTNULL (which
doesn't exist) and you meant that both tests were predicates for IF,
then, in both cases, they will evaluate to False, not NULL.

>Does NULL within any Boolean expression such as
>
>IF ((Null OR False) and True) make the whole expression evaluate to NULL?

There is no such syntax and there are no predicates named as False and True.

The predicates IS NULL and IS NOT NULL exist. Both return True or
False to the engine but there is no output result of True or False
returned to the caller.

However, to partly answer your question, Boolean evaluation works
from left to right and from inner conditions to outer conditions.

>Is it valid to test the result of a Boolean expression for NULL as well as
>true and false?
>
>Eg.
>
>If (New.ID=Old.ID) is Null then .. Whatever

No. For one thing, the result of the inner test is either true or
false and can never be "NULL". The flow of execution proceeds
directly from the result of the test, viz.
If (New.ID=Old.ID) then .. Whatever

Firebird doesn't support a Boolean type, per se. You can predicate a
result for further reference by declaring and setting a variable to
store something you will later use as a reference to the result of your test.

declare variable IsTrue smallint = 0;
....

If (New.ID=Old.ID) then
begin
IsTrue = 1;
...
...
if (IsTrue = 0) then .. Whatever

...
end

If you want to return a Boolean result from a stored procedure,
define an output variable of your preferred type for Boolean use,
assign a value to it according to your IF (..) result and return that.

./heLen