mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-06 00:47:52 +02:00
* 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: branches/fixes_3_2@48706 -
This commit is contained in:
parent
0d71b5ede0
commit
84ec1e3794
@ -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.
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
Contains the TMysqlConnection for MySQL 5.7
|
||||
Contains the TMysqlConnection for MySQL 8.0
|
||||
}
|
||||
|
||||
unit mysql80conn;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user