fcl-db: fixed mysql transaction

git-svn-id: trunk@48705 -
This commit is contained in:
Mattias Gaertner 2021-02-18 09:20:44 +00:00
parent 2da4113310
commit 14dcf30988
3 changed files with 37 additions and 12 deletions

View File

@ -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.

View File

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

View File

@ -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;
@ -654,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);
@ -685,6 +691,7 @@ begin
mysql_free_result(C.FRes);
C.FRes:=Nil;
end;
C.FInitFieldDef:=True;
SetLength(c.MapDSRowToMSQLRow,0);
inherited;
end;
@ -712,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)
@ -985,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
@ -1103,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;
@ -1171,6 +1190,7 @@ var
VL: LargeInt;
VS: Smallint;
VW: Word;
VO: LongWord;
VF: Double;
VC: Currency;
VD: TDateTime;
@ -1212,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);