mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-15 20:29:17 +02:00
* Patch from Joost van der Sluis
- adapted for the changes in TBuffDataset
This commit is contained in:
parent
29e9e1aef2
commit
c720d44ee8
@ -33,7 +33,6 @@ Type
|
|||||||
protected
|
protected
|
||||||
Procedure ConnectToServer; virtual;
|
Procedure ConnectToServer; virtual;
|
||||||
Procedure SelectDatabase; virtual;
|
Procedure SelectDatabase; virtual;
|
||||||
function MySQLDataSize(AType: enum_field_types; ASize: Integer): Integer;
|
|
||||||
function MySQLDataType(AType: enum_field_types; ASize: Integer; var NewType: TFieldType; var NewSize: Integer): Boolean;
|
function MySQLDataType(AType: enum_field_types; ASize: Integer; var NewType: TFieldType; var NewSize: Integer): Boolean;
|
||||||
function MySQLWriteData(AType: enum_field_types; ASize: Integer; Source, Dest: PChar): Integer;
|
function MySQLWriteData(AType: enum_field_types; ASize: Integer; Source, Dest: PChar): Integer;
|
||||||
// SQLConnection methods
|
// SQLConnection methods
|
||||||
@ -49,10 +48,8 @@ Type
|
|||||||
procedure FreeFldBuffers(cursor : TSQLHandle); override;
|
procedure FreeFldBuffers(cursor : TSQLHandle); override;
|
||||||
procedure Execute(cursor: TSQLHandle;atransaction:tSQLtransaction); override;
|
procedure Execute(cursor: TSQLHandle;atransaction:tSQLtransaction); override;
|
||||||
procedure AddFieldDefs(cursor: TSQLHandle; FieldDefs : TfieldDefs); override;
|
procedure AddFieldDefs(cursor: TSQLHandle; FieldDefs : TfieldDefs); override;
|
||||||
function GetFieldSizes(cursor : TSQLHandle) : integer; override;
|
|
||||||
function Fetch(cursor : TSQLHandle) : boolean; override;
|
function Fetch(cursor : TSQLHandle) : boolean; override;
|
||||||
procedure LoadFieldsFromBuffer(cursor : TSQLHandle;buffer: pchar); override;
|
function LoadField(cursor : TSQLHandle;FieldDef : TfieldDef;buffer : pointer) : boolean; override;
|
||||||
function GetFieldData(Cursor : TSQLHandle;Field: TField; FieldDefs : TfieldDefs; Buffer: Pointer;currbuff : pchar): Boolean; override;
|
|
||||||
function GetTransactionHandle(trans : TSQLHandle): pointer; override;
|
function GetTransactionHandle(trans : TSQLHandle): pointer; override;
|
||||||
function Commit(trans : TSQLHandle) : boolean; override;
|
function Commit(trans : TSQLHandle) : boolean; override;
|
||||||
function RollBack(trans : TSQLHandle) : boolean; override;
|
function RollBack(trans : TSQLHandle) : boolean; override;
|
||||||
@ -233,31 +230,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMySQLConnection.MySQLDataSize(AType: enum_field_types; ASize: Integer): Integer;
|
|
||||||
|
|
||||||
begin
|
|
||||||
Result := 0;
|
|
||||||
case AType of
|
|
||||||
FIELD_TYPE_TINY, FIELD_TYPE_SHORT, FIELD_TYPE_LONG, FIELD_TYPE_LONGLONG,
|
|
||||||
FIELD_TYPE_INT24:
|
|
||||||
begin
|
|
||||||
Result := SizeOf(Integer);
|
|
||||||
end;
|
|
||||||
FIELD_TYPE_DECIMAL, FIELD_TYPE_FLOAT, FIELD_TYPE_DOUBLE:
|
|
||||||
begin
|
|
||||||
Result := SizeOf(Double);
|
|
||||||
end;
|
|
||||||
FIELD_TYPE_TIMESTAMP, FIELD_TYPE_DATE, FIELD_TYPE_TIME, FIELD_TYPE_DATETIME:
|
|
||||||
begin
|
|
||||||
Result := SizeOf(TDateTime);
|
|
||||||
end;
|
|
||||||
FIELD_TYPE_VAR_STRING, FIELD_TYPE_STRING, FIELD_TYPE_ENUM, FIELD_TYPE_SET:
|
|
||||||
begin
|
|
||||||
Result := ASize;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TMySQLConnection.MySQLDataType(AType: enum_field_types; ASize: Integer;
|
function TMySQLConnection.MySQLDataType(AType: enum_field_types; ASize: Integer;
|
||||||
var NewType: TFieldType; var NewSize: Integer): Boolean;
|
var NewType: TFieldType; var NewSize: Integer): Boolean;
|
||||||
begin
|
begin
|
||||||
@ -323,33 +295,14 @@ begin
|
|||||||
For I:= 0 to FC-1 do
|
For I:= 0 to FC-1 do
|
||||||
begin
|
begin
|
||||||
field := mysql_fetch_field_direct(C.FRES, I);
|
field := mysql_fetch_field_direct(C.FRES, I);
|
||||||
// Writeln('MySQL: creating fielddef ',I+1);
|
// Writeln('MySQL: creating fielddef ',I+1);
|
||||||
|
|
||||||
if MySQLDataType(field^.ftype, field^.length, DFT, DFS) then
|
if MySQLDataType(field^.ftype, field^.length, DFT, DFS) then
|
||||||
TFieldDef.Create(FieldDefs, field^.name, DFT, DFS, False, I+1);
|
TFieldDef.Create(FieldDefs, field^.name, DFT, DFS, False, I+1);
|
||||||
end;
|
end;
|
||||||
// Writeln('MySQL: Finished adding fielddefs');
|
// Writeln('MySQL: Finished adding fielddefs');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TMySQLConnection.GetFieldSizes(cursor: TSQLHandle): integer;
|
|
||||||
|
|
||||||
var
|
|
||||||
I, FC: Integer;
|
|
||||||
field: PMYSQL_FIELD;
|
|
||||||
C : TMySQLCursor;
|
|
||||||
begin
|
|
||||||
// Writeln('GetFieldSizes');
|
|
||||||
C:=Cursor as TMySQLCursor;
|
|
||||||
Result:=0;
|
|
||||||
FC:=mysql_num_fields(C.FRES);
|
|
||||||
for I:=0 to FC-1 do
|
|
||||||
begin
|
|
||||||
field := mysql_fetch_field_direct(C.FRES, I);
|
|
||||||
Result:=Result+MySQLDataSize(field^.ftype, field^.length);
|
|
||||||
end;
|
|
||||||
// Writeln('GetFieldSizes result :',Result);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TMySQLConnection.Fetch(cursor: TSQLHandle): boolean;
|
function TMySQLConnection.Fetch(cursor: TSQLHandle): boolean;
|
||||||
|
|
||||||
Var
|
Var
|
||||||
@ -361,9 +314,9 @@ begin
|
|||||||
Result:=(C.Row<>Nil);
|
Result:=(C.Row<>Nil);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMySQLConnection.LoadFieldsFromBuffer(cursor: TSQLHandle;
|
function TMySQLConnection.LoadField(cursor : TSQLHandle;
|
||||||
buffer: pchar);
|
FieldDef : TfieldDef;buffer : pointer) : boolean;
|
||||||
|
|
||||||
var
|
var
|
||||||
I, FC, CT: Integer;
|
I, FC, CT: Integer;
|
||||||
field: PMYSQL_FIELD;
|
field: PMYSQL_FIELD;
|
||||||
@ -380,13 +333,16 @@ begin
|
|||||||
end;
|
end;
|
||||||
Row:=C.Row;
|
Row:=C.Row;
|
||||||
FC := mysql_num_fields(C.FRES);
|
FC := mysql_num_fields(C.FRES);
|
||||||
|
|
||||||
for I := 0 to FC-1 do
|
for I := 0 to FC-1 do
|
||||||
begin
|
begin
|
||||||
field := mysql_fetch_field_direct(C.FRES, I);
|
field := mysql_fetch_field_direct(C.FRES, I);
|
||||||
CT := MySQLWriteData(field^.ftype, field^.length, Row^, Buffer);
|
if field^.name=FieldDef.name then break;
|
||||||
Inc(Buffer, CT);
|
|
||||||
Inc(Row);
|
Inc(Row);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
CT := MySQLWriteData(field^.ftype, field^.length, Row^, Buffer);
|
||||||
|
result := true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function InternalStrToFloat(S: string): Extended;
|
function InternalStrToFloat(S: string): Extended;
|
||||||
@ -564,38 +520,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMySQLConnection.GetFieldData(Cursor : TSQLHandle;Field: TField; FieldDefs : TfieldDefs; Buffer: Pointer;currbuff : pchar): Boolean;
|
|
||||||
|
|
||||||
var
|
|
||||||
I, FC: Integer;
|
|
||||||
fld: PMYSQL_FIELD;
|
|
||||||
C : TMySQLCursor;
|
|
||||||
|
|
||||||
begin
|
|
||||||
Result := False;
|
|
||||||
C:=Cursor as TMySQLCursor;
|
|
||||||
FC:= mysql_num_fields(C.FRES);
|
|
||||||
I:=0;
|
|
||||||
While (I<FC) and not Result do
|
|
||||||
begin
|
|
||||||
fld:=mysql_fetch_field_direct(C.FRES,I);
|
|
||||||
if CompareText(Field.FieldName,fld^.name)=0 then
|
|
||||||
begin
|
|
||||||
Move(CurrBuff^, PChar(Buffer)^, MySQLDataSize(fld^.ftype, fld^.length));
|
|
||||||
if Field.DataType in [ftString{, ftWideString}] then
|
|
||||||
begin
|
|
||||||
Result:=PChar(buffer)^<>#0;
|
|
||||||
if Result then
|
|
||||||
PChar(buffer)[fld^.length]:=#0;
|
|
||||||
end
|
|
||||||
else
|
|
||||||
Result := True;
|
|
||||||
end;
|
|
||||||
Inc(CurrBuff, MySQLDataSize(fld^.ftype, fld^.length));
|
|
||||||
Inc(I);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
Function GetSQLStatementType(SQL : String) : TStatementType;
|
Function GetSQLStatementType(SQL : String) : TStatementType;
|
||||||
|
|
||||||
Var
|
Var
|
||||||
@ -645,16 +569,6 @@ begin
|
|||||||
Exit(t);
|
Exit(t);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{function TMySQLConnection.GetStatementType(cursor: TSQLHandle): tStatementType;
|
|
||||||
|
|
||||||
Var
|
|
||||||
C : TMySQLCursor;
|
|
||||||
|
|
||||||
begin
|
|
||||||
C:=Cursor as TMySQLCursor;
|
|
||||||
Result:=GetSQLStatementType(C.FStatement);
|
|
||||||
end;}
|
|
||||||
|
|
||||||
function TMySQLConnection.GetTransactionHandle(trans: TSQLHandle): pointer;
|
function TMySQLConnection.GetTransactionHandle(trans: TSQLHandle): pointer;
|
||||||
begin
|
begin
|
||||||
Result:=Nil;
|
Result:=Nil;
|
||||||
|
Loading…
Reference in New Issue
Block a user