Page 1 of 1

special chars not displayed correctly

Posted: Wed Nov 24, 2010 4:06 pm
by fre
i am getting data from a mysql database and display them. the data contains special chars like ä, ö, ü.

when i create a standalone application the special chars appear correct on a windows machine, but not on a mac.

i changed the mysql table character set from Latin1 to UTF-8 but that did not help.

does anybody know how i could make the mac understand what char to display
or can anybody point me to a post that help me.

thank you
fre

Re: special chars not displayed correctly

Posted: Wed Nov 24, 2010 4:18 pm
by shaosean
Take look at this post, maybe it will help out

http://forums.runrev.com/phpBB2/viewtop ... =12&t=6040

Re: special chars not displayed correctly

Posted: Wed Nov 24, 2010 4:46 pm
by fre
thank you shaosean, i did read that post before posting.
and i tryed what i found there: use utf-8 tables.
but it did not help.

has anybody else had that problem before ?

Re: special chars not displayed correctly

Posted: Wed Nov 24, 2010 4:51 pm
by shaosean
Have you tried the ISOToMac function?

Re: special chars not displayed correctly

Posted: Thu Nov 25, 2010 10:58 am
by fre
thank you again, shaosean.
unfortunately the ISOToMac function does not change anything.

Re: special chars not displayed correctly

Posted: Thu Nov 25, 2010 1:08 pm
by Klaus
Hi fre,

changing the the encoding of the db tables to utf8 does not work if you do not also save your text as utf8 to the db!
This may even corrupt your data!

How do you pass the contents of your fields to the db?

If your standalone is meant to be crossplatform then you must decide to only use ONE encoding (mac or windows/iso) on both platforms!
I have done this in the past and decided to use ISO even on the mac, so I converted everything on the mac to ISO format with mactoiso() before writing to the database!

Unfortunately this will only work with lower ASCII characters (<=127). Higher characters like e.g. the copyright sign © are lost.
So you should convert your strings to utf8 before you write them to the db and convert them back to "normal" text after retrieving them from the db and before you put them back into Livecode fields.


Best

Klaus

Re: special chars not displayed correctly

Posted: Mon Nov 29, 2010 3:19 pm
by fre
klaus, thank you for your post.

i do not write data to the db. i only retrieve data from db and dispaly it.
i have a csv file that was created on a mac.

i import that file with php to a utf-8 table.
then my special chars are readable on windows but not on mac.
So you should convert your strings to utf8 before you write them to the db and convert them back to "normal" text after retrieving them from the db and before you put them back into Livecode fields.
when i convert that file (with ultraedit) to utf-8 bevor importing
with php to the utf-8 table, the special chars are not readable on windows.
what do you mean with "convert them back to normal text after retrieving them from the db" ?

thanks
fre.

Re: special chars not displayed correctly

Posted: Mon Nov 29, 2010 5:02 pm
by Klaus
Hi fre,

hmmm, the meaning of UTF8 is to be crossplatform, so I think there is something wrong in the encoding.
But I know to littel about unicode to be of any help.

##what do you mean with "convert them back to normal text after retrieving them from the db" ?
Sorry, this was from one of my projects, where i used "normal ascii" (NO unicodetext!) fields on mac an windows,
so I had to convert the contents of the db back to Mac resp. ISO encoding before displaying in Livecode.
Know what I mean?

You do "set the unicodetext of fld XYZ to ..." in your app, right?
Just a guess.


Best

Klaus

Re: special chars not displayed correctly

Posted: Mon Nov 29, 2010 9:49 pm
by Mark
Hi Fre,

Could you please provide the scripts that write the data to the database and the script that read the data from the database?

Do you still have the database UTF8 encoded, or have you decided to go back to something else? Have you checked that all text fields in the database are indeed UTF8 encoded? Please, double-check this.

It would be best to delete the database completely and set it up again with the correct encoding.

Kind regards,

Mark

Re: special chars not displayed correctly

Posted: Wed Dec 01, 2010 3:48 pm
by fre
hi mark,

the database is utf-8 and the table is utf-8. i deleted both and created them new.

the php script that writes the data to db:

Code: Select all

$handle = fopen ("hyb1.txt","r"); 
mysql_connect("host","user","pass");
mysql_select_db("mydb");
while ($data = fgetcsv ($handle, 1000, ";")) { 
       mysql_query("INSERT INTO hyb (id, beschwerde, ursache, affirmation, siehe) 
           VALUES (NULL,'".$data[0]."','".$data[1]."','".$data[2]."','')");
}
fclose ($handle);
and here is the code from LiveCode that writes the data to the fields:

Code: Select all

put "SELECT beschwerde,ursache,affirmation,siehe FROM " & tTableName & " WHERE beschwerde = '" & gDesease & "' " into tSQL
put revDataFromQuery(tab, cr, gConnectionID, tSQL) into tData

repeat for each line tLine in tData      
  put item 1 of tLine into field "beschwerde"
  put item 2 of tLine into field "ursache"
  put item 3 of tLine into field "affirmation"
  put item 4 of tLine into field "siehe"
end repeat
thanks.
fre

Re: special chars not displayed correctly

Posted: Wed Dec 01, 2010 5:15 pm
by Klaus
Hi Fredy,

the problem is that you receive the data in UTF8 format, but treat them as "normal" text when putting the data into Livecode fields!
Unfortunately I can only describe the probem, but not the solution, I have zero experience with unicode stuff. 8)
But check my last post anaway!

And I guess that you also do not pass utf8 but "normal" text to the PHP scripts?

Best

Klaus

Re: special chars not displayed correctly

Posted: Wed Dec 01, 2010 6:41 pm
by fre
thanks for your post klaus,

i have tryed to convert the data bevore writing to db with php's utf8_encode function, but that did not help.
a have also tested with the LiveCode function unicodetext. no success.

regards
fred

Re: special chars not displayed correctly

Posted: Thu Dec 02, 2010 12:22 am
by Mark
Alright, Fred, now things are starting to become clear. What is the text encoding of the file hyb1.txt?

Mark

Re: special chars not displayed correctly

Posted: Thu Dec 02, 2010 10:08 am
by fre
hi mark, the text encoding of the file is iso-8859-1
converting it to utf-8 does not change anything.

fred.

Re: special chars not displayed correctly

Posted: Thu Oct 20, 2011 3:09 am
by ctflatt
Hello, everyone!

I just wanted to let you know that this post saved a project for me.

I have an SQLite database containing records with an assortment of several special characters. When displayed within my app, the special characters were misrepresented. Adding the ISOtoMac function to the displayed text did the trick.

Great community help here! I really appreciate it.

:Todd