diff options
author | michael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2021-02-18 09:54:39 +0000 |
---|---|---|
committer | michael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2021-02-18 09:54:39 +0000 |
commit | 829ac4a7769f5360c4097f876cd12cb7e5acd396 (patch) | |
tree | bec1dc63d14c6582944fe033e079403bcb680ba6 /packages | |
parent | c4d7b6f0d95f40ee7cb6da910d10d312fb37cc16 (diff) | |
download | fpc-829ac4a7769f5360c4097f876cd12cb7e5acd396.tar.gz |
* 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: https://svn.freepascal.org/svn/fpc/branches/fixes_3_2@48706 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'packages')
-rw-r--r-- | packages/fcl-db/src/datadict/fpddmysql80.pp | 2 | ||||
-rw-r--r-- | packages/fcl-db/src/sqldb/mysql/mysql80conn.pas | 2 | ||||
-rw-r--r-- | packages/fcl-db/src/sqldb/mysql/mysqlconn.inc | 46 |
3 files changed, 37 insertions, 13 deletions
diff --git a/packages/fcl-db/src/datadict/fpddmysql80.pp b/packages/fcl-db/src/datadict/fpddmysql80.pp index 69be3a54eb..c8e2a0bbfb 100644 --- a/packages/fcl-db/src/datadict/fpddmysql80.pp +++ b/packages/fcl-db/src/datadict/fpddmysql80.pp @@ -3,7 +3,7 @@ Copyright (c) 2007 by Michael Van Canneyt, member of the 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, for details about the copyright. diff --git a/packages/fcl-db/src/sqldb/mysql/mysql80conn.pas b/packages/fcl-db/src/sqldb/mysql/mysql80conn.pas index 19f526752d..739f68150d 100644 --- a/packages/fcl-db/src/sqldb/mysql/mysql80conn.pas +++ b/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; diff --git a/packages/fcl-db/src/sqldb/mysql/mysqlconn.inc b/packages/fcl-db/src/sqldb/mysql/mysqlconn.inc index a53b0da409..f90fd9f310 100644 --- a/packages/fcl-db/src/sqldb/mysql/mysqlconn.inc +++ b/packages/fcl-db/src/sqldb/mysql/mysqlconn.inc @@ -103,6 +103,10 @@ Type TCursorName = Class(TSQLCursor) protected 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; Row : MYSQL_ROW; Lengths : pculong; { Lengths of the columns of the current row } @@ -134,6 +138,7 @@ Type function InternalStrToDateTime(C: pchar; Len: integer): TDateTime; function InternalStrToFloat(C: pchar; Len: integer): Extended; function InternalStrToInt(C: pchar; Len: integer): integer; + function InternalStrToDWord(C: pchar; Len: integer): DWord; function InternalStrToInt64(C: pchar; Len: integer): Int64; function InternalStrToTime(C: pchar; Len: integer): TDateTime; function StrToMSecs(C: pchar; Len: integer): Word; @@ -575,7 +580,6 @@ begin // Version string should start with version number: // Note: in case of MariaDB version mismatch: tough luck, we report MySQL // version only. - writeln('TConnectionName.DoInternalConnect FullVersion=',FullVersion,' MySQLVersion=',MySQLVersion); if (pos(MySQLVersion, FullVersion) <> 1) and (pos(MariaDBVersion, FullVersion) <> 1) then Raise EInOutError.CreateFmt(SErrVersionMisMatch,[ClassName,MySQLVersion,FullVersion]); @@ -655,10 +659,11 @@ 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); - end + FPreparedStatement := AParams.ParseSQL(FPreparedStatement,false,sqEscapeSlash in ConnOptions, sqEscapeRepeat in ConnOptions,psSimulated,paramBinding,ParamReplaceString); + FPrepared:=True; + end; end; procedure TConnectionName.UnPrepareStatement(cursor: TSQLCursor); @@ -686,6 +691,7 @@ begin mysql_free_result(C.FRes); C.FRes:=Nil; end; + C.FInitFieldDef:=True; SetLength(c.MapDSRowToMSQLRow,0); inherited; end; @@ -713,18 +719,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) @@ -986,6 +993,17 @@ begin Result:=StrToInt(S); 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; Var @@ -1104,7 +1122,7 @@ begin Result := 0 else Result := EncodeDate(EY, EM, ED); - Result := ComposeDateTime(Result, EncodeTime(EH, EN, ES, EMS)); + Result := ComposeDateTime(Result, EncodeTimeInterval(EH, EN, ES, EMS)); end; function TConnectionName.InternalStrToTime(C: pchar; Len: integer): TDateTime; @@ -1172,6 +1190,7 @@ var VL: LargeInt; VS: Smallint; VW: Word; + VO: LongWord; VF: Double; VC: Currency; VD: TDateTime; @@ -1213,6 +1232,11 @@ begin VL := InternalStrToInt64(Source, Len); Move(VL, Dest^, SizeOf(LargeInt)); end; + ftLongWord: + begin + VO := InternalStrToDWord(Source, Len); + Move(VO, Dest^, SizeOf(LongWord)); + end; ftFloat: begin VF := InternalStrToFloat(Source, Len); |