소스 검색

* 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;