Browse Source

* Guard against the case connection is nil when closing datasets

Michaël Van Canneyt 1 year ago
parent
commit
2a281b6be6
1 changed files with 10 additions and 2 deletions
  1. 10 2
      packages/fcl-db/src/sqldb/sqldb.pp

+ 10 - 2
packages/fcl-db/src/sqldb/sqldb.pp

@@ -2518,13 +2518,21 @@ Const
 
 var
   Q : TSQLQuery;
+  C : TSQLConnection;
 
 begin
   Q:=DS as TSQLQuery;
   if not (sqoKeepOpenOnCommit in Q.Options) then
     inherited CloseDataset(Q,InCommit);
-  if UnPrepOptions[InCommit] in SQLConnection.ConnOptions then
-   Q.UnPrepare;
+  C:=SQLConnection;
+  if C=Nil then
+    C:=Q.SQLConnection;
+  if Q.Prepared then
+    if not Assigned(C) then
+      // No database, we must unprepare...
+      Q.UnPrepare // Unprepare checks if there is still a cursor.
+    else if UnPrepOptions[InCommit] in C.ConnOptions then
+      Q.UnPrepare;
 end;
 
 procedure TSQLTransaction.Commit;