Browse Source

fcl-db: sqldb:
- do not allocate cursor when opening bufdataset from file
- when closing TSQLQuery do not deallocate cursor while can be prepared (fixes "[SETUP] unable to close due to unfinalised statements" bug for SQLite)
- when unpreparing statement take into account that there are also SQLConnections which does not support [un]preparation of statements ... bur for those we must still call UnRegisterStatement (fixes multiple "[TEARDOWN] Access violation" in tests)

git-svn-id: trunk@25063 -

lacak 12 years ago
parent
commit
8602706228
1 changed files with 18 additions and 24 deletions
  1. 18 24
      packages/fcl-db/src/sqldb/sqldb.pp

+ 18 - 24
packages/fcl-db/src/sqldb/sqldb.pp

@@ -888,8 +888,7 @@ begin
   try
   try
     DoPrepare;
     DoPrepare;
   except
   except
-    if assigned(FCursor) then
-      DeAllocateCursor;
+    DeAllocateCursor;
     Raise;
     Raise;
   end;
   end;
 end;
 end;
@@ -923,7 +922,10 @@ end;
 
 
 procedure TCustomSQLStatement.Unprepare;
 procedure TCustomSQLStatement.Unprepare;
 begin
 begin
-  if Prepared then
+  // Some SQLConnections does not support statement [un]preparation, but they have allocated local cursor(s)
+  //  so let them do cleanup f.e. cancel pending queries and/or free resultset
+  //  and also do UnRegisterStatement!
+  if assigned(FCursor) then
     DoUnprepare;
     DoUnprepare;
 end;
 end;
 
 
@@ -988,6 +990,7 @@ Var
 begin
 begin
   For I:=0 to FStatements.Count-1 do
   For I:=0 to FStatements.Count-1 do
     TCustomSQLStatement(FStatements[i]).Unprepare;
     TCustomSQLStatement(FStatements[i]).Unprepare;
+  FStatements.Clear;
 end;
 end;
 
 
 destructor TSQLConnection.Destroy;
 destructor TSQLConnection.Destroy;
@@ -1625,18 +1628,13 @@ end;
 
 
 procedure TCustomSQLQuery.InternalClose;
 procedure TCustomSQLQuery.InternalClose;
 begin
 begin
-  if not IsReadFromPacket then
+  if assigned(Cursor) then
     begin
     begin
-    if assigned(Cursor) and Cursor.FSelectable then
+    if Cursor.FSelectable then
       FreeFldBuffers;
       FreeFldBuffers;
     // Some SQLConnections does not support statement [un]preparation,
     // Some SQLConnections does not support statement [un]preparation,
     //  so let them do cleanup f.e. cancel pending queries and/or free resultset
     //  so let them do cleanup f.e. cancel pending queries and/or free resultset
     if not Prepared then FStatement.DoUnprepare;
     if not Prepared then FStatement.DoUnprepare;
-    end
-  else
-    begin
-    if assigned(Cursor) then
-      FStatement.DeAllocateCursor;
     end;
     end;
   if DefaultFields then
   if DefaultFields then
     DestroyFields;
     DestroyFields;
@@ -1863,24 +1861,22 @@ procedure TCustomSQLQuery.InternalOpen;
 var tel, fieldc : integer;
 var tel, fieldc : integer;
     f           : TField;
     f           : TField;
     IndexFields : TStrings;
     IndexFields : TStrings;
-    ReadFromFile: Boolean;
 begin
 begin
-  ReadFromFile:=IsReadFromPacket;
-  if ReadFromFile then
+  if IsReadFromPacket then
     begin
     begin
-    FStatement.AllocateCursor;
-    Cursor.FSelectable:=True;
-    Cursor.FStatementType:=stSelect;
+    // When we read from file there is no need for Cursor, also note that Database may not be assigned
+    //FStatement.AllocateCursor;
+    //Cursor.FSelectable:=True;
+    //Cursor.FStatementType:=stSelect;
     FUpdateable:=True;
     FUpdateable:=True;
+    BindFields(True);
     end
     end
   else
   else
+    begin
     Prepare;
     Prepare;
+    if not Cursor.FSelectable then
+      DatabaseError(SErrNoSelectStatement,Self);
 
 
-  if not Cursor.FSelectable then
-    DatabaseError(SErrNoSelectStatement,Self);
-
-  if not ReadFromFile then
-    begin
     // Call UpdateServerIndexDefs before Execute, to avoid problems with connections
     // Call UpdateServerIndexDefs before Execute, to avoid problems with connections
     // which do not allow processing multiple recordsets at a time. (Microsoft
     // which do not allow processing multiple recordsets at a time. (Microsoft
     // calls this MARS, see bug 13241)
     // calls this MARS, see bug 13241)
@@ -1922,9 +1918,7 @@ begin
       end
       end
     else
     else
       BindFields(True);
       BindFields(True);
-    end
-  else
-    BindFields(True);
+    end;
 
 
   if not ReadOnly and not FUpdateable and (FSchemaType=stNoSchema) then
   if not ReadOnly and not FUpdateable and (FSchemaType=stNoSchema) then
     begin
     begin