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;
Mysql 4.11, Delphi 9, ZEOS 6.1