MySQL : database ENUM-column not translated to WideString but to integer + patch

The forum for ZeosLib 7.2 Report problems. Ask for help, post proposals for the new version and Zeoslib 7.2 features here. This is a forum that will be edited once the 7.2.x version goes into RC/stable!!

My personal intention for 7.2 is to speed up the internals as optimal a possible for all IDE's. Hope you can help?! Have fun with testing 7.2
Post Reply
geert
Fresh Boarder
Fresh Boarder
Posts: 14
Joined: 17.08.2005, 09:16
Location: Belgium
Contact:

MySQL : database ENUM-column not translated to WideString but to integer + patch

Post by geert »

I tested zeoslib 7.2.1-rc in our project, and noticed that handling of enum columns is broken compared to 7.1.4-stable.

Enum-fields should translate to WideString (and did so in 7.1.4), but in 7.2.1-rc *and* also in the current svn-version of testing-7.2 (= r3986 ), in the file dbc/ZDbcMySqlUtils.pas , in the function ConvertMySQLColumnInfoFromString, the FieldType is never set to stString in the case that typename='enum', and the enum is not ('Y','N') or ('N','Y'). See code block below (note that the patch is already added there between {PATCH ENUM FIELDTYPE} comments). This resulted in an integer type being returned (this may even be by accident, and maybe FieldType is actually undefined in that case, I did not look into that).

I think there may be a relation to the changes described in the post : http://zeoslib.sourceforge.net/viewtopi ... 40&t=42410 . I think that post discusses mapping boolean values on enum('Y','N'), but maybe the changes made at that point have broken the handling of other enum columns which should map to string (see also MySQL manual, for the C-API, which says enum is mapped to string).

The patch is (as we tested) simply to set the field type (marked below with the comment {PATCH ENUM FIELDTYPE} ):

Code: Select all

  { the column type is ENUM}
  if TypeName = 'enum' then begin
     if (TypeInfoSecond = '''Y'',''N''') or (TypeInfoSecond = '''N'',''Y''') then
      FieldType := stBoolean
    else begin
      TempPos := 1;
      { PATCH ENUM FIELDTYPE }
      FieldType := stString;
      { END PATCH ENUM FIELDTYPE }
      while true do begin 
        pC := PosEx({$IFDEF UNICODE}RawByteString{$ENDIF}(','), TypeInfoSecond, TempPos);
        if pC > 0 then begin
          TypeInfoSecond[pc] := #0;
          ColumnSize := Max(ColumnSize, ZFastCode.StrLen(@TypeInfoSecond[TempPos]));
          TempPos := pc;
        end else begin
          ColumnSize := Max(ColumnSize, ZFastCode.StrLen(@TypeInfoSecond[TempPos]));
          Break;
        end;
      end;
    end
  end else
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: MySQL : database ENUM-column not translated to WideString but to integer + patch

Post by marsupilami »

Hello geert,

thank you for the report. I will file a bugreport.

With best regards,

Jan
Post Reply