Caracters not shown with MySQL and Lazarus lazarus / 16-Databases ---------------------------------------------------------------------- jeanchristophe · 2009-06-04 06:16 Hello Lazarus, I have some databases in MySQL charset Latin with danish letters: ÆØÅ. I can read them both under linux or Windows. I cannot see these records under Lazarus. I try to ask on a French website, but could just see that I was not alone with this problem. Is it something you know? Do you have a solution? Thank you Regards Jean Christophe ---------------------------------------------------------------------- clauslack · 2009-06-04 13:50 Lazarus controls works with UTF8 (unicode 8 bits), you must convert the data to utf8. In my case I use AnsiToUtf8, for other charset look functions in lazarus/lcl/lconvencoding.pas (CP1252ToUTF8, etc) About utf8 there is a lot of info; search in the wikis, forum, etc Regards ---------------------------------------------------------------------- Vincent Snijders · 2009-06-04 14:21 Maybe you can tell the database connection to return the strings using the UTF8 encoding, so that you don't have to convert them yourself. ---------------------------------------------------------------------- gviger · 2009-06-04 17:15 And I have problem with UTF characters form MySQL and I have also notices some other problems with some older applications compiled now with 0.96.2, DBGrid is not showing UTF characters from SQLite3. SQLite application is working fine compiled with Lazarus 0.95. It seems then SQLConnection is not retrieving data in UTF-8 from database. ---------------------------------------------------------------------- jeanchristophe · 2009-06-05 08:20 Hello everybody, Thanks for your suggestions! Clauslack: I didn't try yet, but if I cannot see the field where the words are wroted with danish letters, how can I them convert them? Vincent: Can you please tell me how to do so? or where I can read about it? Gviger: If I read you right, so there is obviously no solution to my problem. If SQL-Connection is not retrieving data in UTF-8, how is it retrieving it then? Anyway thanks for your input I am not that good yet, I am getting old. But I like Lazarus, the potential is huge. Please don't hesitate with more comments, obviously i am not alone with the problem. Have a nice week end Jean-Christophe ---------------------------------------------------------------------- clauslack · 2009-06-05 14:00 In my case I convert all the string, from Dbf to Firebird, but before, I convert dbf from Oem to Ansi. destino:=AnsiToUtf8(Dbf1.Fields.asstring); SQLQuery1.Params.Asstring:=destino; You can try this for test. SQLQuery come with with danish letters. edit1.text:=AnsiToUtf8(SQLQuery1.FieldByName('some field').asstring); or other function in lazarus/lcl/lconvencoding.pas (CP1252ToUTF8, etc) Regards ---------------------------------------------------------------------- gviger · 2009-06-05 21:29 Quote from: clauslack on June 05, 2009, 04:00:38 pm edit1.text:=AnsiToUtf8(SQLQuery1.FieldByName('some field').asstring); Regards I have used this, but is still showing only ????????? ---------------------------------------------------------------------- clauslack · 2009-06-05 22:05 I never used this functions, but you can try, from the LConvEncoding unit. function UTF8BOMToUTF8(const s: string): string; // UTF8 with BOM function ISO_8859_1ToUTF8(const s: string): string; // central europe function CP1250ToUTF8(const s: string): string; // central europe function CP1251ToUTF8(const s: string): string; // cyrillic function CP1252ToUTF8(const s: string): string; // latin 1 function CP1253ToUTF8(const s: string): string; // greek function CP1254ToUTF8(const s: string): string; // turkish function CP1255ToUTF8(const s: string): string; // hebrew function CP1256ToUTF8(const s: string): string; // arabic function CP1257ToUTF8(const s: string): string; // baltic function CP1258ToUTF8(const s: string): string; // vietnam function CP866ToUTF8(const s: string): string;  // DOS and Windows console's cyrillic function CP874ToUTF8(const s: string): string;  // thai function KOI8ToUTF8(const s: string): string;  // russian cyrillic ---------------------------------------------------------------------- Dorica · 2009-06-22 21:57 Hello everybody, this is my first post. I also had the problem with my MySQL-Lazarus setup where accentued characters where replaced by question marks: ???. I then understood today that if my database definition, my MySQL server, my Lazarus application were all using UTF8 encoding, my actual text was still in latin1 inside the database. So the solution was just a matter of converting my ISO_8859-1 encoded text that was inside an UTF8 database into real UTF8 encoded data inside an UTF8 database. This is what you can do to get to it: 1 Create a mysql dump backup:Code: [Select]mysqldump --databases --add-drop-database --add-drop-table --add-locks [your-database] > data-dump.sqlBe sure that each table is defined with DEFAULT CHARSET=utf8;. 2 Convert the content of the dump file into UTF8 text:Code: [Select]iconv -f ISO_8859-1 -t UTF-8 data-dump.sql > new-data-in- utf8.sql 3 Import back the UTF8 text into the database:Code: [Select]mysql < new-data-in-utf8.sql After that procedure, everything is in UFT8, you don't have to use any function like AnsiToUTF8() or else to get the right display in your FreePascal application. ---------------------------------------------------------------------- gviger · 2009-07-04 15:17 Previous post is the prof that Lazarus connection to MySQL server is not UTF, it is Latin1.