#1 2016-05-10 08:33:44

HollosCs
Member
Registered: 2015-12-08
Posts: 56

Close and release SQLite databse file

Hi!

Open a SQLite databse file, read data, close.
Until not quit from program, the SQLite db file not move or delete.

aProp := TSQLDBSQLite3ConnectionProperties.Create(StringToUtf8(eDbName.Text), '', '', '');
aSynDb := ToDataSet(nil, aProp.ExecuteInlined('select * from vwTermenySor WHERE RS_Id IS NULL', true));
....

aProp.MainConnection.Disconnect;
aProp.MainSQLite3DB.DBClose;
aProp.Free;

How can I release SQLite db file completely?


Thx, CSaba

Offline

#2 2016-05-10 11:40:43

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,131
Website

Re: Close and release SQLite databse file

aProp.Free DOES release the SQLite3 file, without any need of calling Disconnect or DBClose.

There is something wrong with your code.

Are you sure you release the ISQLDBRows instance as returned by aProp.ExecuteInlined?
RTFM at http://synopse.info/files/html/Synopse% … #TITLE_173

Here is some code which proves the fact:

program sqlite3syndbclose;

{$APPTYPE CONSOLE}

uses
  FastMM4,
  SysUtils,
  SynCommons,
  SynSQLite3Static,
  SynDB,
  SynDBSQLite3;

procedure Test;
var props: TSQLDBSQLite3ConnectionProperties;
    rows: ISQLDBRows;
begin
  props := TSQLDBSQLite3ConnectionProperties.Create('d:\dev\lib\sqlite3\exe\testsql3.db3','','','');
  rows := props.Execute('select * from dddtest',[]);
  Assert(rows.Step);
  Readln; // here we CAN'T delete the file
  rows := nil;
  props.Free;
end;

begin
  Test;
  Readln; // here we CAN delete the file
end.

Online

#3 2016-05-10 12:17:28

HollosCs
Member
Registered: 2015-12-08
Posts: 56

Re: Close and release SQLite databse file

Many, many thanks! Work it!
My fault, not released the ISQLDBRows instance!

Offline

Board footer

Powered by FluxBB