0

I'm using in-memory SQLite databases with AnyDac on Delphi XE2. I noticed that my queries return results even when I forget to connect the database first after restarting the program, which is probably caused by the autoconnect capability of AnyDac. The thing is that I guess that this must also mean that the in-memory databases stay in memory even after the program itself has terminated, which is kind of a memory leak.

I looked through the AnyDac documentation and searched online, but I could not find any way of how I am supposed to disconnect from a database using AnyDac correctly. I noticed that when I call the "close" method of a TADConnection the sqlite file seems to stay open. I guess the same happens with my in-memory databases.

Can anyone please tell me how to completely close, disconnect from and remove a in-memory SQLite database in a correct and safe way?

Arioch 'The
  • 15,799
  • 35
  • 62
Jasper
  • 62
  • 3
  • Sure. The TADQuery is connected to a TADConnection. But even when I completely terminate my program the database is still available in memory when I start it again. – Jasper Jul 15 '13 at 22:41
  • Hm, there was a comment I commented on, asking if I had a TADQuery. Now it seems to have been deleted. Weird. – Jasper Jul 16 '13 at 08:58

1 Answers1

0

ADConnection.Close completely remove in-memory SQLite DB. With next ADConnection.Open, explicitly or implicitly, new empty in-memory DB is created.

This can be easy confirmed by simple test:

  ADConnection1.Open;
  ADConnection1.ExecSQL('create table TEST (A, B)');
  ADConnection1.ExecSQL('insert into TEST values (1, 2)');
  // show value of TEST.A
  ShowMessage(VarToStr(ADConnection1.ExecSQLScalar('select A from TEST')));
  ADConnection1.Close;
  ADConnection1.Open;
  // next statement generates exception - [FireDAC][Phys][SQLite] ERROR: no such table: TEST
  ShowMessage(VarToStr(ADConnection1.ExecSQLScalar('select A from TEST')));
Branko
  • 1,384
  • 1
  • 16
  • 35