[fpc-pascal] TSQLQuery.ApplyUpdates problem with UTF-8

Dennis Poon dennis at avidsoft.com.hk
Tue Mar 18 11:06:13 CET 2014


LacaK wrote:
> Dennis Poon  wrote / napĂ­sal(a):
>>
>>
>> Dennis Poon wrote:
>>>
>>>
>>> Michael Van Canneyt wrote:
>>>>
>>>>
>>>> On Fri, 14 Mar 2014, Dennis Poon wrote:
>>>>
>>>>> the content appeared as garbage.
>>>>>
>>>>> I already specified the CHARSET=utf8  in the Create Table SQL.
>>>>
>>>> Did you set the TSQLConnection.Charset property to UTF8 as well ?
>>>>
>>>
>>> I set it to utf8 (UTF-8 will raise exception)  but still appears as 
>>> garbage.
>>>
>>> I wrote a test UI program use TDBGrid to edit the text with chinese 
>>> and then refresh it.
> So when you first time read data from MySQL then they are displayed 
> correctly.
> And only after editing, Posting, ApplyingUpdates and reading back are 
> character data displayed incorrectly ?
>
>>> The chinese text, after refreshing, appears as ???
>>>
>>
>> I even tried TSQLScript but it also failed and the chinese values 
>> appear as ??? in the updated record.
>> I suspect that TSQLConnection (or only when it works with MYSQL) 
>> failed to handle multi-byte charset.
> MySQL Connection only takes string data as are stored in TField (or 
> TParam) and forwards them to underlying mysql client library.
> Can you prepare any simple test application (with CREATE TABLE, fill 
> data etc.) which will show problem ?
>
> -Laco.
>

Thanks in advance for your help. Attached is the zipped project files 
with the Create Table, Insert SQL statements.

The table PROVIDERS1 has 1 row with the 'name' field containing chinese 
characters in utf8.
It can display Chinese characters normally as seen in this screen print.
before update
When clicked the button "Test Edit", the program will

procedure TForm1.BtnTestEditClick(Sender: TObject);
var s, s2, s3 : String;
begin
   with   SQLQuery1 do begin
      if not active then
        open;
      First;
      s := FieldbyName('Name').AsString;
      Edit;
      s2 := s + '.';
      FieldbyName('Name').AsString := s2;
      Post;
      ApplyUpdates;

      Close;
      Open;
      S3 := FieldbyName('Name').AsString;
      Memo1.lines.add('Expected='+S2);
      Memo1.lines.add('After update='+S3);
   End;

end;

In the memo1, it displays the expected value and the actual value after 
updated. Pls see the attached screen print.


test utf8

-------------- next part --------------
A non-text attachment was scrubbed...
Name: testutf8.zip
Type: application/zip
Size: 151194 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140318/0719286b/attachment.zip>


More information about the fpc-pascal mailing list