浏览代码

* Guard against the case connection is nil when closing datasets

Michaël Van Canneyt 1 年之前
父节点
当前提交
2a281b6be6
共有 1 个文件被更改,包括 10 次插入2 次删除
  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;