Page 1 of 1

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

Posted: 06.04.2017, 06:25
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

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

Posted: 08.04.2017, 15:59
by marsupilami
Hello geert,

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

With best regards,

Jan