Recent

Author Topic: Any danger in leaving Datasets open?  (Read 897 times)

egsuh

  • Hero Member
  • *****
  • Posts: 1273
Any danger in leaving Datasets open?
« on: May 23, 2020, 09:45:24 am »
Hi,
I'd like to commit transaction database as soon as accessing database (especially select) is finished, but I need to access the resultant dataset afterwards. So I use CommitRetaining frequently. The real codes would look like:


Code: Pascal  [Select][+][-]
  1. SQLQuery1.Close;
  2. SQLQuery1.SQL.Text := 'select * from table1 where cond1=:condition1';
  3. SQLQuery1.Params[0].AsString := 'a string';
  4.  
  5. ATransaction.Active := True;
  6. SQLQuery1.Open;
  7. ATransaction.CommitRetaining;
  8.  
  9. with SQLQuery1 do begin
  10.     MyVar1 := FieldbyName('myvar1').AsInteger;
  11.    // ... similar operations
  12. end;
  13.  

In this case, the SQLQuery1 is left Open when the application is terminated, unless I deliberately close it. But it is a little bit cumbersome to find all datasets that might be open at later stage. 

So I'm wondering whether it is save to leave it as open. In Windows application, I think there would not be a big problem. But how about if it is run in web-server in Fast CGI modules?


mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: Any danger in leaving Datasets open?
« Reply #1 on: May 25, 2020, 08:52:38 am »
It is not possible that TSQLQuery is open after closing your application. When closing all components are freed from the system. The objects, which are created manually and are not freed, can results to a memoryleak.

Why do you think your dataset is still open?
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

egsuh

  • Hero Member
  • *****
  • Posts: 1273
Re: Any danger in leaving Datasets open?
« Reply #2 on: May 26, 2020, 04:38:02 am »
Code: Pascal  [Select][+][-]
  1. Why do you think your dataset is still open?

I'm not worried about about Windows application.
My concern is when it is used in webserver FastCGI mode. I think this should not be a problem because it is closed before I assign any SQL text, but just want to make sure.     

 

TinyPortal © 2005-2018