(utf8 + mysql) Someone please get me on track :(

Forum related to version 6.1.5 of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
Sakura
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 27.05.2008, 17:01

(utf8 + mysql) Someone please get me on track :(

Post by Sakura »

I'm trying for almost 4 hours to squeeze some UTF8 from my mysql database into Delphi, with no success at all. Problem is, I cannot use Delphi stdlib functions since these are always using AnsiString's. This also applies to tableName.FieldByName(constFieldName).AsString()

I have a perfectly set up UTF8-only database with perfectly set up UTF8 tables inside, all using utf8_general_ci sorting. (Just telling so you see I know how to set up a database in UTF8 ;-))

Inside this table are some cyrillic utf-8 encoded records, most notably in a field called 'title'...

Here's what I came up with:

Code: Select all

VAR AValue   : Pointer;
VAR memsize  : Cardinal;
VAR Decoded  : WideString;
CONST TestFieldName = 'title';
begin
  tableKundgaben.First;
  memsize := tableKundgaben.FieldByName(TestFieldName).DataSize*3+2;
  try
    GetMem(AValue, memsize);
  except
    MessageDlg('Error allocating ''+IntToStr(memsize)+'' bytes.''', mtError, [mbOK], 0);
    Exit;
  End;
  try
    FillChar(AValue^, memsize, 0);

    If tableKundgaben.FieldByName(TestFieldName).IsBlob Then
      raise Exception.Create('OMCG! It''s a BLOB!');
    If NOT tableKundgaben.FieldByName(TestFieldName).GetData(AValue, True) Then
      raise Exception.Create('Cannot read *that* field, silly!');

    Decoded := UTF8Decode(UTF8String(AValue));
    Console.Lines.Add(Decoded);

  finally
    FreeMem(AValue, 65534);
  End;
end;
I have to call GetData(&buffer, true) to ensure I get the UTF8 encoded string AS-IS but all I seem to get is random nonsense. Well, not random since it's always the same rubbish. I guess I made a really silly mistake here ne? [js]

Mysql 4.11, Delphi 9, ZEOS 6.1
Sakura
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 27.05.2008, 17:01

Post by Sakura »

Same "problem" with version 6.6beta of ZeosLib :(
Sakura
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 27.05.2008, 17:01

Post by Sakura »

Problem solved, please close topic.

Solution: Use BDE+ODBC Connector
Post Reply