Subject Re: [IBO] Stored procedure, ExecSQL and Suspend
Author Paul Vinkenoog
Hi all,

> Think at SUSPEND as the equivalent of "return value" in C (where
> "value" is actually a whole tuple, a single record in DB parlance),
> or better the "yeld" keyword in Python: without it (that is, when
> you reach the end of your SP, with or without an explicit EXIT)
> there is nothing coming back from the server: all components should
> give you an EOF status, I would be very surprised if this is not the
> case.

I have several SP's that do a singleton SELECT into the return
variables, without SUSPEND, and they've been working fine since more
than a year.

One example is:


CREATE PROCEDURE GEEFSCHOOLJAARINFO
RETURNS (
BEGINJAAR NUMERIC(4),
STRSCHOOLJAAR CHAR(10),
MAXOB NUMERIC(1),
MAXBB NUMERIC(1),
MAXEB NUMERIC(1) )
AS
declare variable Aantal numeric(1,0);
begin
/* ...Initialization stuff deleted... */
select count(*) from SCHOOLJAAR into :Aantal;
if (Aantal = 1) then
begin
select BEGINJAAR, OBPERIODEN, BBPERIODEN, EBPERIODEN
from SCHOOLJAAR
into :Beginjaar, :MaxOB, :MaxBB, :MaxEB;
if (Beginjaar between 1930 and 9998) then
StrSchooljaar = cast(Beginjaar as char(4)) || '-' || cast((Beginjaar+1) as char(5));
end
end


In the data module I have a TIB_StoredProc with property
StoredProcName == GEEFSCHOOLJAARINFO
and SQL->Text == EXECUTE PROCEDURE GEEFSCHOOLJAARINFO

And in the C++ source code:

StoredProcGeefSchooljaarInfo->Prepare();
StoredProcGeefSchooljaarInfo->ExecProc();
SchooljaarInfo.Beginjaar =
StoredProcGeefSchooljaarInfo->Fields->Columns[0]->AsSmallint;
SchooljaarInfo.StrSchooljaar =
StoredProcGeefSchooljaarInfo->Fields->Columns[1]->AsString;
...
...

This works fine, and several others like this work fine, too.


Also, the Data Definition Guide, on page 153, states that SUSPEND in
an executable procedure jumps to the final END statement, but that it
is not recommended.

In an executable procedure, it's the final END that returns the values
to the caller. In a selectable procedure (with FOR SELECT ... DO),
SUSPEND returns values but END doesn't.


Greetings,
Paul Vinkenoog