Permalink
Browse files

Apply fix from forum user damhye, for wrong octet length of exported …

  • Loading branch information...
ansgarbecker committed Feb 5, 2018
1 parent 810decc commit 651b485af375d53dfed9627ea1dc57777699d055
Showing with 60 additions and 1 deletion.
  1. +59 −1 source/dbconnection.pas
  2. +1 −0 source/main.pas
@@ -584,11 +584,13 @@ TDBQuery = class(TComponent)
procedure First;
procedure Next;
function ColumnCount: Integer;
function GetColBinData(Column: Integer; var baData: TBytes): Boolean; virtual; abstract;
function Col(Column: Integer; IgnoreErrors: Boolean=False): String; overload; virtual; abstract;
function Col(ColumnName: String; IgnoreErrors: Boolean=False): String; overload;
function ColumnLengths(Column: Integer): Int64; virtual;
function HexValue(Column: Integer; IgnoreErrors: Boolean=False): String; overload;
function HexValue(BinValue: String): String; overload;
function HexValue(var ByteData: TBytes): String; overload;
function DataType(Column: Integer): TDBDataType;
function MaxLength(Column: Integer): Int64;
function ValueList(Column: Integer): TStringList;
@@ -644,6 +646,7 @@ TMySQLQuery = class(TDBQuery)
public
destructor Destroy; override;
procedure Execute(AddResult: Boolean=False; UseRawResult: Integer=-1); override;
function GetColBinData(Column: Integer; var baData: TBytes): Boolean; override;
function Col(Column: Integer; IgnoreErrors: Boolean=False): String; overload; override;
function ColIsPrimaryKeyPart(Column: Integer): Boolean; override;
function ColIsUniqueKeyPart(Column: Integer): Boolean; override;
@@ -662,6 +665,7 @@ TAdoDBQuery = class(TDBQuery)
public
destructor Destroy; override;
procedure Execute(AddResult: Boolean=False; UseRawResult: Integer=-1); override;
// function GetColBinData(Column: Integer; var baData: TBytes;): Boolean; override;
function Col(Column: Integer; IgnoreErrors: Boolean=False): String; overload; override;
function ColIsPrimaryKeyPart(Column: Integer): Boolean; override;
function ColIsUniqueKeyPart(Column: Integer): Boolean; override;
@@ -681,6 +685,7 @@ TPGQuery = class(TDBQuery)
public
destructor Destroy; override;
procedure Execute(AddResult: Boolean=False; UseRawResult: Integer=-1); override;
// function GetColBinData(Column: Integer; var baData: TBytes;): Boolean; override;
function Col(Column: Integer; IgnoreErrors: Boolean=False): String; overload; override;
function ColIsPrimaryKeyPart(Column: Integer): Boolean; override;
function ColIsUniqueKeyPart(Column: Integer): Boolean; override;
@@ -5936,6 +5941,37 @@ function TDBQuery.ColumnCount: Integer;
Result := ColumnNames.Count;
end;
function TMySQLQuery.GetColBinData(Column: Integer; var baData: TBytes): Boolean;
var
AnsiStr: AnsiString;
BitString: String;
NumBit: Integer;
ByteVal: Byte;
c: Char;
Field: PMYSQL_FIELD;
begin
if (Column > -1) and (Column < ColumnCount) then begin
if FEditingPrepared and Assigned(FCurrentUpdateRow) then begin
// Row was edited and only valid in a TRowData
AnsiStr := AnsiString(FCurrentUpdateRow[Column].NewText);
if Datatype(Column).Category in [dtcBinary, dtcSpatial] then begin
SetLength(baData, Length(AnsiStr));
CopyMemory(baData, @AnsiStr[1], Length(AnsiStr));
Exit(True);
end else
Exit(False);
end else begin
// The normal case: Fetch cell from mysql result
SetString(AnsiStr, FCurrentRow[Column], FColumnLengths[Column]);
if Datatype(Column).Category in [dtcBinary, dtcSpatial] then begin
SetLength(baData, Length(AnsiStr));
CopyMemory(baData, @AnsiStr[1], Length(AnsiStr));
Exit(True);
end else
Exit(False);
end;
end;
end;
function TMySQLQuery.Col(Column: Integer; IgnoreErrors: Boolean=False): String;
var
@@ -6059,9 +6095,15 @@ function TDBQuery.ColumnLengths(Column: Integer): Int64;
function TDBQuery.HexValue(Column: Integer; IgnoreErrors: Boolean=False): String;
var
baData: TBytes;
begin
// Return a binary column value as hex AnsiString
Result := HexValue(Col(Column, IgnoreErrors));
if FConnection.Parameters.IsMysql then begin
GetColBinData(Column, baData);
Result := HexValue(baData);
end else
Result := HexValue(Col(Column, IgnoreErrors));
end;
@@ -6082,6 +6124,22 @@ function TDBQuery.HexValue(BinValue: String): String;
end;
end;
function TDBQuery.HexValue(var ByteData: TBytes): String;
var
BinLen: Integer;
Ansi: AnsiString;
begin
BinLen := Length(ByteData);
SetString(Ansi, PAnsiChar(ByteData), BinLen);
if BinLen = 0 then begin
Result := Connection.EscapeString('');
end else begin
SetLength(Result, BinLen*2);
BinToHex(PAnsiChar(Ansi), PChar(Result), BinLen);
Result := '0x' + Result;
end;
end;
function TDBQuery.DataType(Column: Integer): TDBDataType;
var
@@ -4935,6 +4935,7 @@ procedure TMainForm.DataGridBeforePaint(Sender: TBaseVirtualTree; TargetCanvas:
and (KeyCols.Count > 0) // We need a sufficient key to be able to load remaining row data
and (c.DataType.LoadPart)
and (not IsKeyColumn) // We need full length of any key column, so DataGridLoadFullRow() has the chance to fetch the right row
and ((not DBObj.Connection.Parameters.IsMySQL) or (not (Ord(c.DataType.Category) = Ord(dtcBinary))))
and ((ColLen > GRIDMAXDATA) or (ColLen = 0)) // No need to blow SQL with LEFT() if column is shorter anyway
then begin
case DBObj.Connection.Parameters.NetTypeGroup of

0 comments on commit 651b485

Please sign in to comment.