Subject Re: [IBO] Procedure and TIB_DSQL
Author Helen Borrie
At 04:34 a.m. 20/06/2013, Alexandre wrote:
>Hi Guys,
>I need to know how works TIB_DSQL.
>For example if I have a SP like this:
>begin
> select count(projetos_id) from tb_projetos where projetos_status>=0
> into :total;
> suspend;
>end
>
>I did this in my code:
>
>IB_DSQL1.SQL.Clear;
>IB_DSQL1.SQL.Add(‘EXECUTE PROCEDURE PRO_PROJETOSCOUNT’);
>IB_DSQL1.Prepare;
>IB_DSQL1.Execute;
>
>But now, how to get the output parameter ?

Pass input parameters in the Params array, read output parameters in the Fields array.

Assuming the procedure header is

create procedure pro_projectoscountxx
returns (total integer)
as
...

then, after execution, read ib_dsql1.FieldByName('total').asInteger;

Note, using tib_dsql works only with an executable procedure that returns 1 row (or no row). I hope you understand the difference between an executable procedure and a selectable one. To work with the output of a selectable procedure, you need to use a dataset component (tib_cursor or tib_query).

The SUSPEND statement you have in your executable procedure should not be there. The compiler allows it but it is not tidy work. In an executable procedure, SUSPEND behaves exactly like EXIT: it takes the flow of control directly to the last END statement. In this case, it doesn't do any harm, since there is no processing after it. In another procedure, you might not get away with it.

Helen