Przeglądaj źródła

* Merging revisions 48695,48705 from trunk:
------------------------------------------------------------------------
r48695 | mattias | 2021-02-17 14:26:23 +0100 (Wed, 17 Feb 2021) | 1 line

fcl-db: clean up
------------------------------------------------------------------------
r48705 | mattias | 2021-02-18 10:20:44 +0100 (Thu, 18 Feb 2021) | 1 line

fcl-db: fixed mysql transaction
------------------------------------------------------------------------

git-svn-id: tags/release_3_2_2_rc1@48707 -

michael 4 lat temu
rodzic
commit
a85e8b419e

+ 1 - 1
packages/fcl-db/src/datadict/fpddmysql80.pp

@@ -3,7 +3,7 @@
     Copyright (c) 2007 by Michael Van Canneyt, member of the
     Copyright (c) 2007 by Michael Van Canneyt, member of the
     Free Pascal development team
     Free Pascal development team
 
 
-    MySQL 5.7 Data Dictionary Engine Implementation.
+    MySQL 8.0 Data Dictionary Engine Implementation.
 
 
     See the file COPYING.FPC, included in this distribution,
     See the file COPYING.FPC, included in this distribution,
     for details about the copyright.
     for details about the copyright.

+ 1 - 1
packages/fcl-db/src/sqldb/mysql/mysql80conn.pas

@@ -1,5 +1,5 @@
 {
 {
-  Contains the TMysqlConnection for MySQL 5.7
+  Contains the TMysqlConnection for MySQL 8.0
 }
 }
 
 
 unit mysql80conn;
 unit mysql80conn;

+ 35 - 11
packages/fcl-db/src/sqldb/mysql/mysqlconn.inc

@@ -103,6 +103,10 @@ Type
   TCursorName = Class(TSQLCursor)
   TCursorName = Class(TSQLCursor)
   protected
   protected
     FRes: PMYSQL_RES;                   { Record pointer }
     FRes: PMYSQL_RES;                   { Record pointer }
+    // Statement with param placeholders $1 $2 etc.
+    FPreparedStatement : String;
+    // Statement with param placeholders replaced with actual values.
+    FActualStatement : String;
     FStatement : String;
     FStatement : String;
     Row : MYSQL_ROW;
     Row : MYSQL_ROW;
     Lengths : pculong;                  { Lengths of the columns of the current row }
     Lengths : pculong;                  { Lengths of the columns of the current row }
@@ -134,6 +138,7 @@ Type
     function InternalStrToDateTime(C: pchar; Len: integer): TDateTime;
     function InternalStrToDateTime(C: pchar; Len: integer): TDateTime;
     function InternalStrToFloat(C: pchar; Len: integer): Extended;
     function InternalStrToFloat(C: pchar; Len: integer): Extended;
     function InternalStrToInt(C: pchar; Len: integer): integer;
     function InternalStrToInt(C: pchar; Len: integer): integer;
+    function InternalStrToDWord(C: pchar; Len: integer): DWord;
     function InternalStrToInt64(C: pchar; Len: integer): Int64;
     function InternalStrToInt64(C: pchar; Len: integer): Int64;
     function InternalStrToTime(C: pchar; Len: integer): TDateTime;
     function InternalStrToTime(C: pchar; Len: integer): TDateTime;
     function StrToMSecs(C: pchar; Len: integer): Word;
     function StrToMSecs(C: pchar; Len: integer): Word;
@@ -575,7 +580,6 @@ begin
     // Version string should start with version number:
     // Version string should start with version number:
     // Note: in case of MariaDB version mismatch: tough luck, we report MySQL
     // Note: in case of MariaDB version mismatch: tough luck, we report MySQL
     // version only.
     // version only.
-    writeln('TConnectionName.DoInternalConnect FullVersion=',FullVersion,' MySQLVersion=',MySQLVersion);
     if (pos(MySQLVersion, FullVersion) <> 1) and
     if (pos(MySQLVersion, FullVersion) <> 1) and
        (pos(MariaDBVersion, FullVersion) <> 1) then
        (pos(MariaDBVersion, FullVersion) <> 1) then
       Raise EInOutError.CreateFmt(SErrVersionMisMatch,[ClassName,MySQLVersion,FullVersion]);
       Raise EInOutError.CreateFmt(SErrVersionMisMatch,[ClassName,MySQLVersion,FullVersion]);
@@ -655,10 +659,11 @@ begin
 //    DatabaseError('Parameters (not) yet supported for the MySQL SqlDB connection.',self);
 //    DatabaseError('Parameters (not) yet supported for the MySQL SqlDB connection.',self);
   With Cursor as TCursorName do
   With Cursor as TCursorName do
     begin
     begin
-    FStatement:=Buf;
+    FPreparedStatement:=Buf;
     if assigned(AParams) and (AParams.count > 0) then
     if assigned(AParams) and (AParams.count > 0) then
-      FStatement := AParams.ParseSQL(FStatement,false,sqEscapeSlash in ConnOptions, sqEscapeRepeat in ConnOptions,psSimulated,paramBinding,ParamReplaceString);
-    end
+      FPreparedStatement := AParams.ParseSQL(FPreparedStatement,false,sqEscapeSlash in ConnOptions, sqEscapeRepeat in ConnOptions,psSimulated,paramBinding,ParamReplaceString);
+    FPrepared:=True;
+    end;
 end;
 end;
 
 
 procedure TConnectionName.UnPrepareStatement(cursor: TSQLCursor);
 procedure TConnectionName.UnPrepareStatement(cursor: TSQLCursor);
@@ -686,6 +691,7 @@ begin
     mysql_free_result(C.FRes);
     mysql_free_result(C.FRes);
     C.FRes:=Nil;
     C.FRes:=Nil;
     end;
     end;
+  C.FInitFieldDef:=True;
   SetLength(c.MapDSRowToMSQLRow,0);
   SetLength(c.MapDSRowToMSQLRow,0);
   inherited;
   inherited;
 end;
 end;
@@ -713,18 +719,19 @@ begin
         ParamNames[AParams.count-i-1] := C.ParamReplaceString+inttostr(AParams[i].Index+1);
         ParamNames[AParams.count-i-1] := C.ParamReplaceString+inttostr(AParams[i].Index+1);
         ParamValues[AParams.count-i-1] := GetAsSQLText(AParams[i]);
         ParamValues[AParams.count-i-1] := GetAsSQLText(AParams[i]);
         end;
         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
     if LogEvent(detParamValue) then
       LogParams(AParams);
       LogParams(AParams);
     if LogEvent(detExecute) then
     if LogEvent(detExecute) then
-      Log(detExecute, C.FStatement);
+      Log(detExecute, C.FPreparedStatement);
     if LogEvent(detActualSQL) then
     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
       begin
       if not ForcedClose then
       if not ForcedClose then
         MySQLError(FMYSQL,SErrExecuting,Self)
         MySQLError(FMYSQL,SErrExecuting,Self)
@@ -986,6 +993,17 @@ begin
   Result:=StrToInt(S);
   Result:=StrToInt(S);
 end;
 end;
 
 
+function TConnectionName.InternalStrToDWord(C: pchar; Len: integer): DWord;
+Var
+  S : String;
+begin
+  Result := 0;
+  if (Len=0) or (C=Nil) then
+    exit;
+  SetString(S,C,Len);
+  Result:=StrToDWord(S);
+end;
+
 function TConnectionName.InternalStrToInt64(C: pchar; Len: integer): Int64;
 function TConnectionName.InternalStrToInt64(C: pchar; Len: integer): Int64;
 
 
 Var
 Var
@@ -1104,7 +1122,7 @@ begin
     Result := 0
     Result := 0
   else
   else
     Result := EncodeDate(EY, EM, ED);
     Result := EncodeDate(EY, EM, ED);
-  Result := ComposeDateTime(Result, EncodeTime(EH, EN, ES, EMS));
+  Result := ComposeDateTime(Result, EncodeTimeInterval(EH, EN, ES, EMS));
 end;
 end;
 
 
 function TConnectionName.InternalStrToTime(C: pchar; Len: integer): TDateTime;
 function TConnectionName.InternalStrToTime(C: pchar; Len: integer): TDateTime;
@@ -1172,6 +1190,7 @@ var
   VL: LargeInt;
   VL: LargeInt;
   VS: Smallint;
   VS: Smallint;
   VW: Word;
   VW: Word;
+  VO: LongWord;
   VF: Double;
   VF: Double;
   VC: Currency;
   VC: Currency;
   VD: TDateTime;
   VD: TDateTime;
@@ -1213,6 +1232,11 @@ begin
       VL := InternalStrToInt64(Source, Len);
       VL := InternalStrToInt64(Source, Len);
       Move(VL, Dest^, SizeOf(LargeInt));
       Move(VL, Dest^, SizeOf(LargeInt));
       end;
       end;
+    ftLongWord:
+      begin
+      VO := InternalStrToDWord(Source, Len);
+      Move(VO, Dest^, SizeOf(LongWord));
+      end;
     ftFloat:
     ftFloat:
       begin
       begin
       VF := InternalStrToFloat(Source, Len);
       VF := InternalStrToFloat(Source, Len);