1

I want to repeatedly open/close a TFDQuery without having the overhead of preparing each time but calling TFDQuery.Close automatically unprepares the query.

I have tried XE6 and Studio 10 with FireBird 3.0. I initially thought it was my configuration however after analyzing with FireDAC Monitor I found the trace as follows

Close -> Stop -> Commit -> Offline -> ReleaseBase -> DoUnprepareSource

I am unable to find any options which would leave the query prepared for un-preparing either manually or when component freed.

Query:=TFDQuery.Create(nil);
try
  Query.ConnectionName:='Test';
  Query.SQL.Text:='SELECT A FROM B';
  Query.Prepare;
  Query.Open;
  Query.Close;
  Query.Open; // should still be prepared but is not
finally
  Query.Free;
end;
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Richard Shuck
  • 113
  • 1
  • 10
  • I have found that setting FetchOptions.AutoClose to false and not using close but using Refresh keeps the query prepared. I will have to do some more testing as I have not tried changing a queries parameters before whilst open. – Richard Shuck Oct 14 '19 at 17:34
  • 1
    Just try to surround this code by transaction, and you will see, that query will stay prepared. – da-soft Oct 14 '19 at 18:47
  • Because calls like `.Prepare` and `.PrepareStatement` never meant really much in Delphi, since ancient BDE & `TBDEDataSet` times. Try to find something analoguos to `.Prepared := true;` See also https://github.com/petdance/bobby-tables/issues/98 – Arioch 'The Oct 15 '19 at 07:59

0 Answers0