Recent

Author Topic: Caracters not shown with MySQL and Lazarus  (Read 13254 times)

jeanchristophe

  • Jr. Member
  • **
  • Posts: 88
Caracters not shown with MySQL and Lazarus
« on: June 04, 2009, 08:16:06 am »
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

  • Sr. Member
  • ****
  • Posts: 275
Re: Caracters not shown with MySQL and Lazarus
« Reply #1 on: June 04, 2009, 03:50:30 pm »
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
« Last Edit: June 04, 2009, 03:53:21 pm by clauslack »

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Re: Caracters not shown with MySQL and Lazarus
« Reply #2 on: June 04, 2009, 04:21:42 pm »
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

  • New Member
  • *
  • Posts: 10
Re: Caracters not shown with MySQL and Lazarus
« Reply #3 on: June 04, 2009, 07:15:39 pm »
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

  • Jr. Member
  • **
  • Posts: 88
Re: Caracters not shown with MySQL and Lazarus
« Reply #4 on: June 05, 2009, 10:20:37 am »
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

  • Sr. Member
  • ****
  • Posts: 275
Re: Caracters not shown with MySQL and Lazarus
« Reply #5 on: June 05, 2009, 04:00:38 pm »
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

  • New Member
  • *
  • Posts: 10
Re: Caracters not shown with MySQL and Lazarus
« Reply #6 on: June 05, 2009, 11:29:45 pm »

edit1.text:=AnsiToUtf8(SQLQuery1.FieldByName('some field').asstring);

Regards

I have used this, but is still showing only ?????????

clauslack

  • Sr. Member
  • ****
  • Posts: 275
Re: Caracters not shown with MySQL and Lazarus
« Reply #7 on: June 06, 2009, 12:05:28 am »
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       



« Last Edit: June 06, 2009, 12:07:04 am by clauslack »

Dorica

  • Newbie
  • Posts: 1
Re: Caracters not shown with MySQL and Lazarus
« Reply #8 on: June 22, 2009, 11:57:29 pm »
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

    • New Member
    • *
    • Posts: 10
    Re: Caracters not shown with MySQL and Lazarus
    « Reply #9 on: July 04, 2009, 05:17:56 pm »
    Previous post is the prof that Lazarus connection to MySQL server is not UTF, it is Latin1.




     

    TinyPortal © 2005-2018