Subject Re: [ib-support] Wrong codeflow in SP. Possible bug
Author Paul Reeves
Andrew Guts wrote:
> Hello IB support.
>
> This is a fragment of my stored proc. Qty is an integer parameter. The
> statement after "ELSE" is never executed. When I've replaced
> "ELSE" by "if (Qty <= 0) then" it works as expected. What is wrong with it?

The compiler just doesn't respect your indentation, does it?

>
> if (Qty > 0) then
> if (exists (select docid from Closed_Docs where DocID = :d))
> then exception xcptdoc_closed;
> else
> if (exists (select DocRow from Reserves where DocRow = :DocRow
> and Term >= 'NOW' and AuthorID <> :E))
> then exception XCPT_RESERVED;
>

What the compiler sees is this:

if (Qty > 0) then
if (exists (select docid from Closed_Docs where DocID = :d)) then
exception xcptdoc_closed;
else
if (exists (select DocRow from Reserves where DocRow = :DocRow
and Term >= 'NOW' and AuthorID <> :E)) then
exception XCPT_RESERVED;

Try again with the judicious use of BEGIN and END.


Paul
--

Paul Reeves
http://www.ibphoenix.com
Supporting users of Firebird and InterBase