Menu

#56 TffQuery parameter values not being updated

open
nobody
7
2013-01-13
2003-01-23
Anonymous
No

Exported from Bugzilla, issue 4169.

--- Comment added on 12/12/02 8:50:11 AM ---
David Clarke, 12/12/2002
Hello all:

I have the following section of code that prepares an INSERT query and
executes a loop which modifies the parameters values on each iteration
through the loop, but what I find is that the values in the resulting
records are all the same. It appears that the parameter values are not being
refreshed if the prepare is outside of the loop.

When I move the Unprepare inside the loop it all works ok, but this defeats
the purpose of preparing the query in the first place and the execution time
is much slower.

Code that does not work:
FffQuery.SQL.Clear;
FffQuery.SQL.Add ( 'INSERT INTO Production');
FffQuery.SQL.Add ( ' ( ItemName, ItemIndex, DateTimeStamp,
ItemValue, ItemUnits )' );
FffQuery.SQL.Add ( 'VALUES' );
FffQuery.SQL.Add ( '( :ParItemName, :ParItemIndex,
:ParDataTimeStamp, :ParItemValue, :ParItemUnits )');
FffQuery.Prepare;

TimeStamp := Now;
for j := Low ( FSampleRateCounter.ItemData ) to High (
FSampleRateCounter.ItemData ) do begin
FffQuery.ParamByName ( 'ParItemName' ).AsString :=
FSampleRateCounter.ItemName;
FffQuery.ParamByName ( 'ParItemIndex' ).AsInteger := j;
FffQuery.ParamByName ( 'ParDataTimeStamp' ).AsDateTime :=
TimeStamp;
FffQuery.ParamByName ( 'ParItemValue' ).AsFloat :=
FSampleRateCounter.ItemData [ j ];
FffQuery.ParamByName ( 'ParItemUnits' ).AsString :=
FSampleRateCounter.ItemUnits;

FffQuery.ExecSQL;
end;

FffQuery.Unprepare;
Fffdb.Commit;
FffSess.Active := false;

Code that works, but much slower:

FffQuery.SQL.Clear;
FffQuery.SQL.Add ( 'INSERT INTO Production');
FffQuery.SQL.Add ( ' ( ItemName, ItemIndex, DateTimeStamp,
ItemValue, ItemUnits )' );
FffQuery.SQL.Add ( 'VALUES' );
FffQuery.SQL.Add ( '( :ParItemName, :ParItemIndex,
:ParDataTimeStamp, :ParItemValue, :ParItemUnits )');
FffQuery.Prepare;

TimeStamp := Now;
for j := Low ( FSampleRateCounter.ItemData ) to High (
FSampleRateCounter.ItemData ) do begin
FffQuery.ParamByName ( 'ParItemName' ).AsString :=
FSampleRateCounter.ItemName;
FffQuery.ParamByName ( 'ParItemIndex' ).AsInteger := j;
FffQuery.ParamByName ( 'ParDataTimeStamp' ).AsDateTime :=
TimeStamp;
FffQuery.ParamByName ( 'ParItemValue' ).AsFloat :=
FSampleRateCounter.ItemData [ j ];
FffQuery.ParamByName ( 'ParItemUnits' ).AsString :=
FSampleRateCounter.ItemUnits;

FffQuery.ExecSQL;
FffQuery.Unprepare;
end;

Fffdb.Commit;
FffSess.Active := false;

Has anyone else experienced this?

Regards,
David Clarke.

Discussion


Log in to post a comment.

Monday.com Logo