Browse Source

* Moved some code to avoid problems while handling exceptions

git-svn-id: trunk@12512 -
joost 16 years ago
parent
commit
d6903a4bb6
1 changed files with 8 additions and 2 deletions
  1. 8 2
      packages/fcl-db/src/sqldb/sqldb.pp

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

@@ -919,11 +919,17 @@ begin
     if FSQLBuf = '' then
     if FSQLBuf = '' then
       DatabaseError(SErrNoStatement);
       DatabaseError(SErrNoStatement);
 
 
+    SQLParser(FSQLBuf);
+
+    // There may no error occur between the allocation of the cursor and
+    // the preparation of the cursor. Because internalclose (which is called in
+    // case of an exception) assumes that allocated cursors are also prepared,
+    // and thus calls unprepare.
+    // A call to unprepare while the cursor is not prepared at all can lead to
+    // unpredictable results.
     if not assigned(fcursor) then
     if not assigned(fcursor) then
       FCursor := Db.AllocateCursorHandle;
       FCursor := Db.AllocateCursorHandle;
 
 
-    SQLParser(FSQLBuf);
-
     if ServerFiltered then
     if ServerFiltered then
       Db.PrepareStatement(Fcursor,sqltr,AddFilter(FSQLBuf),FParams)
       Db.PrepareStatement(Fcursor,sqltr,AddFilter(FSQLBuf),FParams)
     else
     else