Subject Re: [IBO] Re: TIB_Cursor not returning correct result
Author Lucas Franzen
Steve,


> procedure TDMFb.UpdateAveIdealUsage(const sItem : String);
> Var
> iInvItemID : Integer;
> qry : TIB_Query;
> Begin
> iInvItemID := DMFb.GetInvItemID(sItem);
> if (iInvItemID <> 0) then
> Begin
> qry := TIB_Query.Create(Self);
> Try
> qry.IB_Connection := conIx;
> qry.IB_Transaction := trnIx;
> qry.DatabaseName := 'IxFB';

what do you assign the database for???
Just assign the Connection and Transaction. That's all you need.

> qry.SQL.Add('Select QtySold From xItemUsages');
> qry.SQL.Add('Where InvItemID = ' + IntToStr(iInvItemID));

Add a qry.PREPARE here.

> qry.Open;
> qry.First;

Remove the qry.FIRST;
Where do you expect a TIB_Query to be at when opening?

>
> // #todo1 Not Working - Returns 0 for QtySold
> if (not qry.FieldByName('QtySold').IsNull) then
> Begin
> DMFb.spUpdateAveIdealUsage.ParamByName
> ('pInvItemID').AsInteger := iInvItemID;
> DMFb.spUpdateAveIdealUsage.ParamByName
> ('pUsage').AsFloat := qry.FieldByName('QtySold').AsFloat;
> DMFb.spUpdateAveIdealUsage.ExecSQL;

Is the update just happening here?
What does the procedure look like?

> End;
> Finally
> qry.Close;
> FreeAndNil(qry);
> End;
> End;
> End;
>
> Note that IBExpert returns the correct value with exactly the same
> query.

With exactly the same SQL, not the same query ;-)
What happens if you do the same select with an existing TIB_Query (one
that you're not creating on the fly?)

Luc.