special chars not displayed correctly

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
fre
Posts: 41
Joined: Fri Nov 12, 2010 7:22 pm

special chars not displayed correctly

Post by fre » Wed Nov 24, 2010 4:06 pm

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

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: special chars not displayed correctly

Post by shaosean » Wed Nov 24, 2010 4:18 pm

Take look at this post, maybe it will help out

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

fre
Posts: 41
Joined: Fri Nov 12, 2010 7:22 pm

Re: special chars not displayed correctly

Post by fre » Wed Nov 24, 2010 4:46 pm

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 ?

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: special chars not displayed correctly

Post by shaosean » Wed Nov 24, 2010 4:51 pm

Have you tried the ISOToMac function?

fre
Posts: 41
Joined: Fri Nov 12, 2010 7:22 pm

Re: special chars not displayed correctly

Post by fre » Thu Nov 25, 2010 10:58 am

thank you again, shaosean.
unfortunately the ISOToMac function does not change anything.

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: special chars not displayed correctly

Post by Klaus » Thu Nov 25, 2010 1:08 pm

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

fre
Posts: 41
Joined: Fri Nov 12, 2010 7:22 pm

Re: special chars not displayed correctly

Post by fre » Mon Nov 29, 2010 3:19 pm

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.

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: special chars not displayed correctly

Post by Klaus » Mon Nov 29, 2010 5:02 pm

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: special chars not displayed correctly

Post by Mark » Mon Nov 29, 2010 9:49 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

fre
Posts: 41
Joined: Fri Nov 12, 2010 7:22 pm

Re: special chars not displayed correctly

Post by fre » Wed Dec 01, 2010 3:48 pm

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

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: special chars not displayed correctly

Post by Klaus » Wed Dec 01, 2010 5:15 pm

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

fre
Posts: 41
Joined: Fri Nov 12, 2010 7:22 pm

Re: special chars not displayed correctly

Post by fre » Wed Dec 01, 2010 6:41 pm

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: special chars not displayed correctly

Post by Mark » Thu Dec 02, 2010 12:22 am

Alright, Fred, now things are starting to become clear. What is the text encoding of the file hyb1.txt?

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

fre
Posts: 41
Joined: Fri Nov 12, 2010 7:22 pm

Re: special chars not displayed correctly

Post by fre » Thu Dec 02, 2010 10:08 am

hi mark, the text encoding of the file is iso-8859-1
converting it to utf-8 does not change anything.

fred.

ctflatt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 243
Joined: Sun Dec 06, 2009 12:24 am
Contact:

Re: special chars not displayed correctly

Post by ctflatt » Thu Oct 20, 2011 3:09 am

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

Post Reply