2
0
Эх сурвалжийг харах

* Merging revisions 43702 from trunk:
------------------------------------------------------------------------
r43702 | michael | 2019-12-20 17:28:42 +0100 (Fri, 20 Dec 2019) | 1 line

* Fix bug #0036461, parameters not correctly refreshed in Mysql
------------------------------------------------------------------------

git-svn-id: branches/fixes_3_2@46563 -

michael 5 жил өмнө
parent
commit
e506bc902a

+ 14 - 9
packages/fcl-db/src/sqldb/mysql/mysqlconn.inc

@@ -92,7 +92,10 @@ Type
   TCursorName = Class(TSQLCursor)
   protected
     FRes: PMYSQL_RES;                   { Record pointer }
-    FStatement : String;
+    // Statement with param placeholders $1 $2 etc.
+    FPreparedStatement : String;
+    // Statement with param placeholders replaced with actual values.
+    FActualStatement : String;
     Row : MYSQL_ROW;
     Lengths : pculong;                  { Lengths of the columns of the current row }
     RowsAffected : QWord;
@@ -589,9 +592,9 @@ begin
 //    DatabaseError('Parameters (not) yet supported for the MySQL SqlDB connection.',self);
   With Cursor as TCursorName do
     begin
-    FStatement:=Buf;
+    FPreparedStatement:=Buf;
     if assigned(AParams) and (AParams.count > 0) then
-      FStatement := AParams.ParseSQL(FStatement,false,sqEscapeSlash in ConnOptions, sqEscapeRepeat in ConnOptions,psSimulated,paramBinding,ParamReplaceString);
+      FPreparedStatement := AParams.ParseSQL(FPreparedStatement,false,sqEscapeSlash in ConnOptions, sqEscapeRepeat in ConnOptions,psSimulated,paramBinding,ParamReplaceString);
     end
 end;
 
@@ -620,6 +623,7 @@ begin
     mysql_free_result(C.FRes);
     C.FRes:=Nil;
     end;
+  C.FInitFieldDef:=True;
   SetLength(c.MapDSRowToMSQLRow,0);
   inherited;
 end;
@@ -647,18 +651,19 @@ begin
         ParamNames[AParams.count-i-1] := C.ParamReplaceString+inttostr(AParams[i].Index+1);
         ParamValues[AParams.count-i-1] := GetAsSQLText(AParams[i]);
         end;
-      // paramreplacestring kan een probleem geven bij postgres als hij niet meer gewoon $ is?
-      C.FStatement := stringsreplace(C.FStatement,ParamNames,ParamValues,[rfReplaceAll]);
-      end;
+      C.FActualStatement := stringsreplace(C.FPreparedStatement,ParamNames,ParamValues,[rfReplaceAll]);
+      end
+    else
+      C.FActualStatement:=C.FPreparedStatement;
 
     if LogEvent(detParamValue) then
       LogParams(AParams);
     if LogEvent(detExecute) then
-      Log(detExecute, C.FStatement);
+      Log(detExecute, C.FPreparedStatement);
     if LogEvent(detActualSQL) then
-      Log(detActualSQL,C.FStatement);
+      Log(detActualSQL,C.FActualStatement);
 
-    if mysql_query(FMySQL,Pchar(C.FStatement))<>0 then
+    if mysql_query(FMySQL,Pchar(C.FActualStatement))<>0 then
       begin
       if not ForcedClose then
         MySQLError(FMYSQL,SErrExecuting,Self)