Using TDBQuery.ColAttributes() and TTableColumn.LengthSet in a query result does not work, as this relies on a previous SHOW CREATE TABLE parsing. Check PMYSQL_FIELD.length instead to return the correct zero-padded string bitmask for a BIT column. Fixes issue #2544.

This commit is contained in:
Ansgar Becker
2013-10-02 04:56:48 +00:00
parent 47f555810a
commit 5832bf45b9

View File

@ -4,7 +4,7 @@ interface
uses
Classes, SysUtils, windows, mysql_structures, SynRegExpr, Generics.Collections, Generics.Defaults,
DateUtils, Types, Math, Dialogs, ADODB, DB, DBCommon, ComObj, Graphics, ExtCtrls,
DateUtils, Types, Math, Dialogs, ADODB, DB, DBCommon, ComObj, Graphics, ExtCtrls, StrUtils,
gnugettext;
@ -4167,6 +4167,7 @@ var
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
@ -4181,6 +4182,8 @@ begin
Result := Connection.DecodeAPIString(AnsiStr);
// Create string bitmask for BIT fields
if Datatype(Column).Index = dtBit then begin
Field := mysql_fetch_field_direct(FCurrentResults, column);
// FConnection.Log(lcInfo, Field.name+': def: '+field.def+' length: '+inttostr(field.length)+' max_length: '+inttostr(field.max_length)+' decimals: '+inttostr(field.decimals));
for c in Result do begin
ByteVal := Byte(c);
BitString := '';
@ -4189,13 +4192,13 @@ begin
BitString := BitString + '1'
else
BitString := BitString + '0';
if Length(BitString) >= MaxLength(Column) then
if Length(BitString) >= Field.length then
break;
end;
if Length(BitString) >= MaxLength(Column) then
if Length(BitString) >= Field.length then
break;
end;
Result := BitString;
Result := ReverseString(BitString);
end;
end;