Subject | Re: [firebird-support] Re: Stored Procedure vs Inline Query Results |
---|---|
Author | Helen Borrie |
Post date | 2005-03-01T02:41:12Z |
At 02:01 AM 1/03/2005 +0000, you wrote:
create exception EMPTY_SET 'There are no rows in this set';
commit;
create procedure get_stuff (akey integer)
returns (
<list of vars>
as
begin
if (not exists (select ..... from ...where id - :aKey)) then
exception EMPTY_SET;
else
-- carry on
end
set. The SELECT ... INTO syntax will except if the query returns multiple
rows.
literally suspends execution of the procedure and waits for the client to
fetch the latest output row from the buffer.
In an executable SP, SUSPEND simply causes an immediate EXIT.
documentation in the IB 6 Beta manuals: a little in LangRef.pdf and more
in DataDef.pdf and EmbedSQL.pdf.
Also do both a site search and a Knowledgebase search at www.ibphoenix.com
- you will probably find some papers on the topic.
./heLen
>Hi Helen,Yes, you can do this with an exception.
>
> >Firstly, the query is an inner join that finds
> >no match between the two tables - hence the DSQL
> >query returns no rows.
> >Inside the SP. the query also returns no data to
> >the variables - hence the uninitialised) variables
> >simply return their unchanged values (nulls) as
> >return values to the SP call.
>
>Thanks for that explanation. It makes sense now. I tried changing the
>SP like Dimitry recommended but it still returns the null variables.
>So the question now is, is there anyway for the SP to not return
>anything if the query inside doesn't? Would it be better to just check
>to see if the value of the variable from the SP is null rather than
>checking if it returned a record?
create exception EMPTY_SET 'There are no rows in this set';
commit;
create procedure get_stuff (akey integer)
returns (
<list of vars>
as
begin
if (not exists (select ..... from ...where id - :aKey)) then
exception EMPTY_SET;
else
-- carry on
end
>I'm also a little unclear on some aspects of Firebird SP's. How do youUse the FOR SELECT...DO where you want to iterate through a mutli-row
>know when to use the FOR....DO as Dimitry suggested,
set. The SELECT ... INTO syntax will except if the query returns multiple
rows.
>what aboutUse SUSPEND only when you plan to call the SP using SELECT. SUSPEND
>SUSPEND
literally suspends execution of the procedure and waits for the client to
fetch the latest output row from the buffer.
In an executable SP, SUSPEND simply causes an immediate EXIT.
> vs EXIT, etc?Yes, Part Seven (5 chapters) of The Firebird Book. You can find some
>Is there any good detailed documentation about
>SP's in Firebird?
documentation in the IB 6 Beta manuals: a little in LangRef.pdf and more
in DataDef.pdf and EmbedSQL.pdf.
Also do both a site search and a Knowledgebase search at www.ibphoenix.com
- you will probably find some papers on the topic.
./heLen