Skip to content
Permalink
Browse files

Check connection object state before destroying remaining query resul…

…ts, and release library when closing a connection
  • Loading branch information
ansgarbecker committed Feb 4, 2020
1 parent d5a2764 commit a16465795a0da3a3265272017bd055b7e0d5f684
Showing with 27 additions and 11 deletions.
  1. +27 −11 source/dbconnection.pas
@@ -533,6 +533,7 @@ TMySQLConnection = class(TDBConnection)
procedure SetLockedByThread(Value: TThread); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Lib: TMySQLLib read FLib;
procedure Query(SQL: String; DoStoreResult: Boolean=False; LogCategory: TDBLogCategory=lcSQL); override;
function Ping(Reconnect: Boolean): Boolean; override;
@@ -1770,13 +1771,19 @@ constructor TSQLiteConnection.Create(AOwner: TComponent);

destructor TDBConnection.Destroy;
begin
if Active then Active := False;
ClearCache(True);
FKeepAliveTimer.Free;
FFavorites.Free;
inherited;
end;

destructor TMySQLConnection.Destroy;
begin
if Active then Active := False;
FLib.Free;
inherited;
end;


destructor TAdoDBConnection.Destroy;
begin
@@ -1789,15 +1796,16 @@ destructor TAdoDBConnection.Destroy;
destructor TPgConnection.Destroy;
begin
if Active then Active := False;
//FreeAndNil(FHandle);
FRegClasses.Free;
FLib.Free;
inherited;
end;


destructor TSQLiteConnection.Destroy;
begin
if Active then Active := False;
FLib.Free;
inherited;
end;

@@ -6274,8 +6282,10 @@ destructor TMySQLQuery.Destroy;
var
i: Integer;
begin
if HasResult then for i:=Low(FResultList) to High(FResultList) do
FConnection.Lib.mysql_free_result(FResultList[i]);
if HasResult and (FConnection <> nil) and (FConnection.Active) then begin
for i:=Low(FResultList) to High(FResultList) do
FConnection.Lib.mysql_free_result(FResultList[i]);
end;
SetLength(FResultList, 0);
inherited;
end;
@@ -6285,9 +6295,11 @@ destructor TAdoDBQuery.Destroy;
var
i: Integer;
begin
if HasResult then for i:=Low(FResultList) to High(FResultList) do begin
FResultList[i].Close;
FResultList[i].Free;
if HasResult and (FConnection <> nil) and (FConnection.Active) then begin
for i:=Low(FResultList) to High(FResultList) do begin
FResultList[i].Close;
FResultList[i].Free;
end;
end;
SetLength(FResultList, 0);
inherited;
@@ -6298,8 +6310,10 @@ destructor TPGQuery.Destroy;
var
i: Integer;
begin
if HasResult then for i:=Low(FResultList) to High(FResultList) do
FConnection.Lib.PQclear(FResultList[i]);
if HasResult and (FConnection <> nil) and (FConnection.Active) then begin
for i:=Low(FResultList) to High(FResultList) do
FConnection.Lib.PQclear(FResultList[i]);
end;
SetLength(FResultList, 0);
inherited;
end;
@@ -6309,8 +6323,10 @@ destructor TSQLiteQuery.Destroy;
var
i: Integer;
begin
if HasResult then for i:=Low(FResultList) to High(FResultList) do
FResultList[i].Free;
if HasResult and (FConnection <> nil) and (FConnection.Active) then begin
for i:=Low(FResultList) to High(FResultList) do
FResultList[i].Free;
end;
SetLength(FResultList, 0);
inherited;
end;

0 comments on commit a164657

Please sign in to comment.
You can’t perform that action at this time.