mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-20 11:29:22 +02:00
* Patch from Laco to fix Bug ID #27260 (mem leak)
git-svn-id: trunk@30138 -
This commit is contained in:
parent
321deae34c
commit
2c878e7684
@ -24,7 +24,12 @@ type
|
|||||||
{*************************************************************}
|
{*************************************************************}
|
||||||
{*************************************************************}
|
{*************************************************************}
|
||||||
private
|
private
|
||||||
fPSQlite: PPsqlite3;
|
type
|
||||||
|
TFieldList = class(TList)
|
||||||
|
protected
|
||||||
|
procedure Notify(Ptr: Pointer; Action: TListNotification); override;
|
||||||
|
end;
|
||||||
|
var
|
||||||
fSQLite:Psqlite3;
|
fSQLite:Psqlite3;
|
||||||
fMsg: String;
|
fMsg: String;
|
||||||
fIsOpen: Boolean;
|
fIsOpen: Boolean;
|
||||||
@ -39,7 +44,7 @@ type
|
|||||||
fOnBusy: TOnBusy;
|
fOnBusy: TOnBusy;
|
||||||
fOnQueryComplete: TOnQueryComplete;
|
fOnQueryComplete: TOnQueryComplete;
|
||||||
fBusyTimeout: longint;
|
fBusyTimeout: longint;
|
||||||
fPMsg: PChar;
|
fPMsg: PAnsiChar;
|
||||||
fChangeCount: longint;
|
fChangeCount: longint;
|
||||||
fNb_Champ : Integer;
|
fNb_Champ : Integer;
|
||||||
fList_FieldName : TStringList;
|
fList_FieldName : TStringList;
|
||||||
@ -48,9 +53,9 @@ type
|
|||||||
{*************************************************************}
|
{*************************************************************}
|
||||||
{*************************************************************}
|
{*************************************************************}
|
||||||
public
|
public
|
||||||
constructor Create(DBFileName: String);
|
constructor Create(const DBFileName: String);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function Query(Sql: String; Table: TStrings ): boolean;
|
function Query(const Sql: String; Table: TStrings ): boolean;
|
||||||
function ErrorMessage(ErrNo: Integer): string;
|
function ErrorMessage(ErrNo: Integer): string;
|
||||||
function IsComplete(Sql: String): boolean;
|
function IsComplete(Sql: String): boolean;
|
||||||
function LastInsertRow: integer;
|
function LastInsertRow: integer;
|
||||||
@ -65,12 +70,12 @@ type
|
|||||||
property OnQueryComplete: TOnQueryComplete read fOnQueryComplete write fOnQueryComplete;
|
property OnQueryComplete: TOnQueryComplete read fOnQueryComplete write fOnQueryComplete;
|
||||||
property BusyTimeout: longint read fBusyTimeout write SetBusyTimeout;
|
property BusyTimeout: longint read fBusyTimeout write SetBusyTimeout;
|
||||||
property ChangeCount: longint read fChangeCount;
|
property ChangeCount: longint read fChangeCount;
|
||||||
property List_FieldName: TStringList read fList_FieldName write fList_FieldName;
|
property List_FieldName: TStringList read fList_FieldName;
|
||||||
property List_Field: TList read fList_Field write fList_Field;
|
property List_Field: TList read fList_Field;
|
||||||
property Nb_Champ: integer read fNb_Champ write fNb_Champ;
|
property Nb_Champ: integer read fNb_Champ write fNb_Champ;
|
||||||
procedure SQLOnData(Sender: TObject; Columns: Integer; ColumnNames, ColumnValues: String);
|
procedure SQLOnData(Sender: TObject; Columns: Integer; ColumnNames, ColumnValues: String);
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function Pas2SQLStr(const PasString: string): string;
|
function Pas2SQLStr(const PasString: string): string;
|
||||||
function SQL2PasStr(const SQLString: string): string;
|
function SQL2PasStr(const SQLString: string): string;
|
||||||
function QuoteStr(const s: string; QuoteChar: Char ): string;
|
function QuoteStr(const s: string; QuoteChar: Char ): string;
|
||||||
@ -314,20 +319,27 @@ begin
|
|||||||
end;
|
end;
|
||||||
if length(InterS) > 0 then Field.add(InterS);
|
if length(InterS) > 0 then Field.add(InterS);
|
||||||
List_Field.add(Field);
|
List_Field.add(Field);
|
||||||
Field.Free;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{*************************************************************}
|
{*************************************************************}
|
||||||
constructor TSQLite.Create(DBFileName: String);
|
procedure TSQLite.TFieldList.Notify(Ptr: Pointer; Action: TListNotification);
|
||||||
|
{*************************************************************}
|
||||||
|
begin
|
||||||
|
if Action=lnDeleted then
|
||||||
|
TObject(Ptr).Free;
|
||||||
|
inherited;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{*************************************************************}
|
||||||
|
constructor TSQLite.Create(const DBFileName: String);
|
||||||
{*************************************************************
|
{*************************************************************
|
||||||
SQlite3 constructor
|
SQlite3 constructor
|
||||||
G. Marcou
|
G. Marcou
|
||||||
*************************************************************}
|
*************************************************************}
|
||||||
var
|
|
||||||
name : pchar;
|
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
List_FieldName := TStringList.Create;
|
fList_FieldName := TStringList.Create;
|
||||||
List_Field := TList.Create;
|
fList_Field := TFieldList.Create;
|
||||||
fError := SQLITE_ERROR;
|
fError := SQLITE_ERROR;
|
||||||
fIsOpen := False;
|
fIsOpen := False;
|
||||||
fLstName := TStringList.Create;
|
fLstName := TStringList.Create;
|
||||||
@ -336,10 +348,8 @@ begin
|
|||||||
fOnBusy := nil;
|
fOnBusy := nil;
|
||||||
fOnQueryComplete := nil;
|
fOnQueryComplete := nil;
|
||||||
fChangeCount := 0;
|
fChangeCount := 0;
|
||||||
name:=StrAlloc (length(DBFileName)+1);
|
|
||||||
strpcopy(name,DBFileName);
|
|
||||||
OnData:=@SQLOnData;
|
OnData:=@SQLOnData;
|
||||||
sqlite3_open(name,@fSQLite);
|
sqlite3_open(PAnsiChar(DBFileName), @fSQLite);
|
||||||
sqlite3_free(fPMsg);
|
sqlite3_free(fPMsg);
|
||||||
if fSQLite <> nil then
|
if fSQLite <> nil then
|
||||||
begin
|
begin
|
||||||
@ -349,7 +359,6 @@ begin
|
|||||||
fError := SQLITE_OK;
|
fError := SQLITE_OK;
|
||||||
end;
|
end;
|
||||||
fMsg := sqlite3_errmsg(fSQLite);
|
fMsg := sqlite3_errmsg(fSQLite);
|
||||||
strdispose(name);
|
|
||||||
end;
|
end;
|
||||||
{*************************************************************}
|
{*************************************************************}
|
||||||
destructor TSQLite.Destroy;
|
destructor TSQLite.Destroy;
|
||||||
@ -369,12 +378,12 @@ begin
|
|||||||
fOnQueryComplete := nil;
|
fOnQueryComplete := nil;
|
||||||
fLstName := nil;
|
fLstName := nil;
|
||||||
fLstVal := nil;
|
fLstVal := nil;
|
||||||
List_FieldName.destroy;
|
fList_FieldName.destroy;
|
||||||
List_Field.destroy;
|
fList_Field.destroy;
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
{*************************************************************}
|
{*************************************************************}
|
||||||
function TSQLite.Query(Sql: String; Table: TStrings ): boolean;
|
function TSQLite.Query(const Sql: String; Table: TStrings ): boolean;
|
||||||
{*************************************************************
|
{*************************************************************
|
||||||
SQLite3 query the database
|
SQLite3 query the database
|
||||||
G. Marcou
|
G. Marcou
|
||||||
@ -394,7 +403,7 @@ begin
|
|||||||
List_FieldName.clear;
|
List_FieldName.clear;
|
||||||
List_Field.clear;
|
List_Field.clear;
|
||||||
Nb_Champ:=-1;
|
Nb_Champ:=-1;
|
||||||
fError := sqlite3_exec(fSQLite, PChar(sql), @ExecCallback, Self, @fPMsg);
|
fError := sqlite3_exec(fSQLite, PAnsiChar(sql), @ExecCallback, Self, @fPMsg);
|
||||||
sqlite3_free(fPMsg);
|
sqlite3_free(fPMsg);
|
||||||
fChangeCount := sqlite3_changes(fSQLite);
|
fChangeCount := sqlite3_changes(fSQLite);
|
||||||
fTable := nil;
|
fTable := nil;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
program test;
|
program test;
|
||||||
|
|
||||||
uses sqlite,sqlitedb, strings,classes;
|
uses sqlite3,sqlite3db, strings,classes;
|
||||||
|
|
||||||
var
|
var
|
||||||
MySQL: TSQLite;
|
MySQL: TSQLite;
|
||||||
|
Loading…
Reference in New Issue
Block a user