[fpc-devel] Unicodestring branch, please test and help fixing #2

ABorka fpc-devel at aborka.com
Wed Sep 17 06:16:41 CEST 2008


After reading the mailing lists more I've played a little bit with this 
and it seems that with Zeos (MySQL5) it is working out of the box at 
first sight (need some more tests) if one sets the 
ZConnection.Properties to

character_set_client=utf8
character_set_connection=utf8
character_set_database=utf8
character_set_results=utf8
character_set_server=utf8
character_set_system=utf8
collation_connection=utf8_general_ci
collation_database=utf8_general_ci
collation_server=utf8_general_ci
Codepage=utf8

(suggested by Ivan Gan on the Lazarus mailing list back in July)
No matter if the database/table is UTF8 encoded or not, the returned 
values are OK for the Lazarus controls as well as to the 
FieldByName...AsString string assignments. For me it seems to be working 
   both ways (reading from the tables and writing to the tables with SQL 
statements).

If I'm using the fcl-db (SQLdb Lazarus package) no matter what I tried 
it didn't work out of the box. Unless I used the 
ConvertEncoding(SomeStringFromTheTable, 'cp1252', 'utf8') function I 
could not get any string value from the table fields. Did not matter if 
the database/table was UTF8 encoded or not.
I'm sure it can be made to work somehow.

AB

Joost van der Sluis wrote:
> Op vrijdag 12-09-2008 om 15:56 uur [tijdzone +0200], schreef Mattias
> Gärtner:
>> Zitat von Joost van der Sluis <joost at cnoc.nl>:
>>
>>> Op vrijdag 12-09-2008 om 13:22 uur [tijdzone +0200], schreef JoshyFun:
>>>
>>>> A> Thanks for pointing me to the Lazarus thread about this and the bug
>>>> A> report. Checked them.
>>>> A> But as I understand there is no solution available at the moment for
>>> this.
>>>> I had partially solved the problem using the handler "OnGetText" ?
>>>> (I'm not sure about the name) for each field which is somehow dirty
>>>> forcing a codepage to UTF8 conversion (in Lazarus you will find some
>>>> codepage<->UTF conversions available).
>>> I think that the original poster didn't looked very well in the
>>> archives, this solution is told here quite often.
>>>
>>>> A> I have a database that is not encoded utf8 (and it will never be because
>>>> A> other client programs are accessing it and their users do not want/need
>>>> A> to be converted to unicode). How do I get the field values into
>>>> A> FPC/Lazarus into a string variable? Right now the non-unicode strings
>>>> A> are returned as empty from a database field due to FCL conversion
>>> functions.
>>>> If you will need this as a fixed solution for this project maybe you
>>>> can think in create a new database unit file based in the current one
>>>> (change the name of course) with hardcoded UTF8 encoding from codepage
>>>> for each string once retrieved from the database. Take care about
>>>> string length as UTF8 ones will be equal or longer than the original
>>>> ones.
>>> You can just override one single method to do this. This is also told a
>>> few times on this list.
>> Maybe it is not documented at the right place?
> 
> It is not documented at all. Just like the rest of the database-stuff.
> But maybe I should write a FAQ for fpc. With the new lazarus-versions
> using UTF-8 by default, this is asked quite often.
> 
> Joost
> 
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
> 




More information about the fpc-devel mailing list