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

LacaK lacak at zoznam.sk
Tue Mar 25 07:12:28 CET 2014


Dennis Poon  wrote / napísal(a):
>
>
> LacaK wrote:
>> Dennis Poon  wrote / napísal(a):
>>>
>>>>> I tried, the results are:
>>>>>
>>>>> @@character_set_client      : utf8
>>>>> @@character_set_connection  : latin1
>>>>> @@character_set_database   : latin1
>>>>>
>>>>>
>>>> Dennis, do you received my reply?:
>>>>
>>>> IMO @@character_set_connection is wrong and must be utf8.
>>>> I will try fix it, but first can you try as workaround this:
>>>> - after connection is established can you use 
>>>> MySQLConnection1.ExecuteDirect('SET NAMES ''utf8''');
>>>> - and then check again @@character_set_client, 
>>>> @@character_set_connection (IMO both must be utf8 ... if they will 
>>>> be, then your program should work as expected ... can you test it 
>>>> again?)
>>>>
>>>> -Laco.
>>>>
>>> I tried  MYSQLConnection1.ExecuteDirect('SET NAMES ''utf8'';');
>>> and recheck
>>>   @@character_set_client    : utf8
>>>   @@character_set_connection : utf8
>>>   @@character_set_database : latin1
>>>
>>> So, it corrected one variable.
>> This is okay now
>>
>>>
>>> I re-ran my test but still  ?????? after applyUpdates.
>> When I use your test program I receve same result as you describe.
>> But when I add into procedure TForm1.FormCreate(Sender: TObject);
>> begin
>>  MySQL55Connection1.ExecuteDirect('SET NAMES ''utf8''');  // <-- ADDED
>>  SQLQuery1.Open;
>> end;
>>
>> It works for me as expected ... so now I am confused with your 
>> results  ... can you try again please your test application with 
>> added line ...
>> (it will require patch for mysqlconnection in all cases, but before  
>> want have confirmed, that it helps)
>>
>> -Laco.
>>
>>
>
> My apology.
no problem :-)
> My last attempt did not recreate a fresh database table for testing so 
> it started with the ruined table values and thus did not give the 
> correct result.
> Your Set Names command did the trick.
> Thanks a lot.
I am happy, that mystery is solved and it works now.
I will patch it in mysqlconnection so extra SET NAMES will not be 
required in the future.

>
> By the way, why isn't a semicolon required at the end of SET NAMES 
> 'utf8' command? I tried both with and without semicolon and neither 
> raise an error.
Seems, that MySQL is tolerant to this.
MySQL supports MULTI_STATEMENTS, which enables client to pass multiple 
statements separated by ";" in one string.
So may be, that MySQL interprets ";" as delimiter between multiple 
statements on one batch.
If you use only one sql statement it is always better do not use 
terminating ";" IMHO

-Laco.




More information about the fpc-pascal mailing list