Ver Fonte

Merged revisions 11511 via svnmerge from
svn+ssh://[email protected]/FPC/svn/fpc/trunk

........
r11511 | michael | 2008-08-05 13:58:00 +0200 (Tue, 05 Aug 2008) | 1 line

* Fixed prepare for select statements
........

git-svn-id: branches/fixes_2_2@11518 -

michael há 17 anos atrás
pai
commit
5a30e1e5b1

+ 1 - 2
packages/fcl-db/src/sqldb/interbase/ibconnection.pp

@@ -533,7 +533,6 @@ begin
 
 
     if isc_dsql_prepare(@Status[0], @tr, @Statement, 0, @Buf[1], Dialect, nil) <> 0 then
     if isc_dsql_prepare(@Status[0], @tr, @Statement, 0, @Buf[1], Dialect, nil) <> 0 then
       CheckError('PrepareStatement', Status);
       CheckError('PrepareStatement', Status);
-    FPrepared := True;
     if assigned(AParams) and (AParams.count > 0) then
     if assigned(AParams) and (AParams.count > 0) then
       begin
       begin
       AllocSQLDA(in_SQLDA,Length(ParamBinding));
       AllocSQLDA(in_SQLDA,Length(ParamBinding));
@@ -556,7 +555,6 @@ begin
       AllocSQLDA(in_SQLDA,0);
       AllocSQLDA(in_SQLDA,0);
     if FStatementType = stselect then
     if FStatementType = stselect then
       begin
       begin
-      FPrepared := False;
       if isc_dsql_describe(@Status[0], @Statement, 1, SQLDA) <> 0 then
       if isc_dsql_describe(@Status[0], @Statement, 1, SQLDA) <> 0 then
         CheckError('PrepareSelect', Status);
         CheckError('PrepareSelect', Status);
       if SQLDA^.SQLD > SQLDA^.SQLN then
       if SQLDA^.SQLD > SQLDA^.SQLN then
@@ -576,6 +574,7 @@ begin
         end;
         end;
       {$R+}
       {$R+}
       end;
       end;
+    FPrepared := True;
     end;
     end;
 end;
 end;
 
 

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

@@ -212,7 +212,7 @@ type
     FUpdateQry,
     FUpdateQry,
     FDeleteQry,
     FDeleteQry,
     FInsertQry           : TCustomSQLQuery;
     FInsertQry           : TCustomSQLQuery;
-
+    FOpenDidPrepare : Boolean;
     procedure FreeFldBuffers;
     procedure FreeFldBuffers;
     function GetServerIndexDefs: TServerIndexDefs;
     function GetServerIndexDefs: TServerIndexDefs;
     function GetStatementType : TStatementType;
     function GetStatementType : TStatementType;
@@ -980,7 +980,11 @@ procedure TCustomSQLQuery.InternalClose;
 begin
 begin
   if StatementType = stSelect then FreeFldBuffers;
   if StatementType = stSelect then FreeFldBuffers;
 // Database and FCursor could be nil, for example if the database is not assigned, and .open is called
 // Database and FCursor could be nil, for example if the database is not assigned, and .open is called
-  if (not IsPrepared) and (assigned(database)) and (assigned(FCursor)) then TSQLConnection(database).UnPrepareStatement(FCursor);
+  if (FOpenDidPrepare) and (assigned(database)) and (assigned(FCursor)) then
+    begin
+    FOpenDidPrepare:=False;
+    TSQLConnection(database).UnPrepareStatement(FCursor);
+    end;
   if DefaultFields then
   if DefaultFields then
     DestroyFields;
     DestroyFields;
   FIsEOF := False;
   FIsEOF := False;
@@ -1163,7 +1167,9 @@ var tel, fieldc : integer;
     IndexFields : TStrings;
     IndexFields : TStrings;
 begin
 begin
   try
   try
-    Prepare;
+    FOpenDidPrepare:=Not Prepared;
+    If FOpenDidPrepare then
+      Prepare;
     if FCursor.FStatementType in [stSelect] then
     if FCursor.FStatementType in [stSelect] then
       begin
       begin
       Execute;
       Execute;
@@ -1217,14 +1223,21 @@ end;
 // public part
 // public part
 
 
 procedure TCustomSQLQuery.ExecSQL;
 procedure TCustomSQLQuery.ExecSQL;
+
+Var
+  ExecDidPrepare : Boolean;
+
 begin
 begin
   try
   try
-    Prepare;
+    ExecDidPrepare:=Not IsPrepared;
+    If ExecDidPrepare then
+      Prepare;
     Execute;
     Execute;
   finally
   finally
     // FCursor has to be assigned, or else the prepare went wrong before PrepareStatment was
     // FCursor has to be assigned, or else the prepare went wrong before PrepareStatment was
     // called, so UnPrepareStatement shoudn't be called either
     // called, so UnPrepareStatement shoudn't be called either
-    if (not IsPrepared) and (assigned(database)) and (assigned(FCursor)) then TSQLConnection(database).UnPrepareStatement(Fcursor);
+    if (ExecDidPrepare) and (assigned(database)) and (assigned(FCursor)) then
+      TSQLConnection(database).UnPrepareStatement(Fcursor);
   end;
   end;
 end;
 end;