[fcl-db] An SQL statement is always prepared in open/close loop even if the SQL doesn't change
Original Reporter info from Mantis: kluug.net @onpok
-
Reporter name: Ondrej Pokorny
Original Reporter info from Mantis: kluug.net @onpok
- Reporter name: Ondrej Pokorny
Description:
An SQL staement should be prepared only once if executed repeatedly. Instead, every time you open/close a TSQLQuery, the statement is prepared and unprepared.
I tested MSSQL and Postgres - both show this unwanted behavior.
Steps to reproduce:
Apply the attached db-debug.patch to get output debug lines and run the following program (you can easily change it for a different database system):
program DBconn;
uses
db, pqconnection, sqldb, sysutils;
var
xSQL: TPQConnection;
Q: TSQLQuery;
T: TSQLTransaction;
I: Integer;
begin
xSQL := TPQConnection.Create(nil);
try
xSQL.HostName := 'localhost';
xSQL.DatabaseName := 'postgres';
xSQL.UserName := 'postgres';
xSQL.Password := 'password';
xSQL.Params.Add('port=5432');
xSQL.Connected := True;
Q := TSQLQuery.Create(xSQL);
T := TSQLTransaction.Create(xSQL);
T.DataBase := xSQL;
Q.DataBase := xSQL;
Q.Transaction := T;
Writeln(sLineBreak, 'Statement start here', sLineBreak);
Q.SQL.Text := 'SELECT :ID';
for I := 0 to 1 do
begin
Q.ParamByName('ID').AsInteger := I;
Q.Open;
Writeln(' -->> Result ', I, ': ', Q.Fields[0].AsInteger);
Q.Close;
end;
finally
xSQL.Free;
end;
Readln;
end.
Mantis conversion info:
- Mantis ID: 33025
- Version: 3.1.1
- Fixed in version: 3.3.1
- Fixed in revision: 43024 (#0ce71294)
- Target version: 4.0.0