Subject | Re: FOR SELECT in SP's |
---|---|
Author | Marco Menardi |
Post date | 2002-12-03T00:19:49Z |
You are using the wrong component.
TIB_DSQL is for executable statements (like update...), or for a SP
that returns only one row, but since you are using "FOR SELECT" this
is not the case.
Anyway, if the SP is made to return only one row, use the code like this:
with dsqlCustomerInfo do
begin
if not Prepared then Prepare;
ParamByName('IN_CUSTOMER_ID').AsString := ACustomerID;
Execute;
ADescrizioneDisp := FieldByName('DESCRIZIONEDISP').AsString;
...
For you, I suggest the use of IB_Cursor, that is an unbuffered, low
resource, light component.
Use code like this:
...
if not trsParametri.Started then
trsParametri.Started := True;
crsParamPgm.APIFirst;
ADescrizioneDisp := FieldByName('DESCRIZIONEDISP').AsString;
crsParamPgm.Close;
trsParametri.Commit;
as you can see, you don't use Open, but APIFIrst, that is equivalent
of First but, when no visual controls are involved, much more efficient.
btw, I'm sure FB Workbench handles the SP correctly probably because
they "run" it with a Query-like component.
regards
Marco Menardi
TIB_DSQL is for executable statements (like update...), or for a SP
that returns only one row, but since you are using "FOR SELECT" this
is not the case.
Anyway, if the SP is made to return only one row, use the code like this:
with dsqlCustomerInfo do
begin
if not Prepared then Prepare;
ParamByName('IN_CUSTOMER_ID').AsString := ACustomerID;
Execute;
ADescrizioneDisp := FieldByName('DESCRIZIONEDISP').AsString;
...
For you, I suggest the use of IB_Cursor, that is an unbuffered, low
resource, light component.
Use code like this:
...
if not trsParametri.Started then
trsParametri.Started := True;
crsParamPgm.APIFirst;
ADescrizioneDisp := FieldByName('DESCRIZIONEDISP').AsString;
crsParamPgm.Close;
trsParametri.Commit;
as you can see, you don't use Open, but APIFIrst, that is equivalent
of First but, when no visual controls are involved, much more efficient.
btw, I'm sure FB Workbench handles the SP correctly probably because
they "run" it with a Query-like component.
regards
Marco Menardi
--- In IBObjects@y..., "Ryan Nilsson-Harding" <nilsson@b...> wrote:
> Hi there,
>
> I'm trying to write my first multiple select SP, and having an
> issue, but I'm sure this is a simple problem. (I can get the SP to
> work using FB Workbench, but not using TIB_DSQL, hence asking here)
>
> The SP query is:
>
> RETURNS (PARTNUM VARCHAR(32))
> FOR SELECT PN FROM ORD_DET
> WHERE ORD_ID = :ord_id
> AND QTYREC < QTYORD
> INTO :PARTNUM
> DO
> SUSPEND;
>
> If I test this using FB Workbench, I get the results I am expecting,
> but when I use a TIB_DSQL component in my app, I'm getting errors.
> If the SP should return NO records, I get the error:
> "Attempt to fetch past last record in a record stream"
>
> and if the result set should contain records, I get the error:
> "Multiple rows in singleton select"
> But I thought using FOR SELECT DO allows for multiple selects.
>
> I'm sure this is simple, I'm just thrown because FB Workbench
> handles the SP correctly.
>
> Rgds,
> -Ryan