I'm using Delphi XE2 and a TSQLQuery object. It works the first time that I use it. If I immediately reuse it, then it doesn't parse the new SQL for its parameters and rebuild the qry.Params
list:
var
qry: TSQLQuery;
begin
qry := TSQLQuery.Create(nil);
try
qry.MaxBlobSize := -1;
qry.SQLConnectin := AnExistingConnection;
qry.CommandText := 'select field1 from table1 where fieldX = @valueX';
qry.ParamByName('valueX').Value := 1;
qry.Open;
// ... use data ...
qry.Close;
qry.Params.Clear; // <- works the same with or without this
qry.CommandText := 'select field2 from table2 where fieldY = @valueY';
qry.ParamByName('valueY').Value := 2; // <- Error: 'valueY' Param not found
qry.Open;
finally
FreeAndNil(qry);
end;
end;
It doesn't matter what I do, it doesn't parse the 2nd SQL statement for its parameters so I can't bind the 'valueY' parameter by name.
I can think of two workarounds:
- Manually build the
qry.Params
list myself. - Destroy and recreate the
qry
object in between the two commands.
I shouldn't have to do either of these. Perhaps there is a property or something on the qry
object that will cause it to reparse parameters each time a new SQL statement is assigned to its CommandText
property?