Charset problem on grid after successful SQL SELECT

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jlspereira
Posts: 18
Joined: Sat Mar 01, 2014 10:35 pm

Charset problem on grid after successful SQL SELECT

Post by jlspereira » Mon Mar 17, 2014 9:44 pm

I am starting to use LiveCode with MySQL. My database has a single table (it's a begin), containing textfields. My computer is a Mac and I am coming from Windows and MS/Access.
To transport the database, I exported the final join as a single table on CSV format and imported it to MySQL. The table content looks perfect when viewing though MySQL Workbench. then I did set up a grid on a stack and it looks great except than, through the grid, all accented characters and replaced by weird characters. The database is UFT-8 (previously was "latin1" but now I have changed all to UFT-8.
Can anyone help?

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Charset problem on grid after successful SQL SELECT

Post by bangkok » Tue Mar 18, 2014 8:17 am

First, override the standard behavior of your datagrid by following this lesson :

http://lessons.runrev.com/s/lessons/m/d ... -to-a-cell

Then in the behavior script, change the FillInData script with :

Code: Select all

on FillInData pData
    -- This message is sent when the Data Grid needs to populate
    -- this template with the column data. pData is the value to be displayed.
   set the unicodetext of the long ID of me to uniencode(pData, "utf8")
end FillInData
This will display correctly UTF8 strings in your datagrid, provided you retrieve UTF8 data from your SQL query.

Last but not least, you could try to play with the charset of MySQL by executing this command, BEFORE to do your SELECT.

Code: Select all

revExecuteSQL dbID, "SET NAMES 'utf8'"

jlspereira
Posts: 18
Joined: Sat Mar 01, 2014 10:35 pm

Re: Charset problem on grid after successful SQL SELECT

Post by jlspereira » Tue Mar 18, 2014 9:46 am

Ok. I'll try do do it immediatly.

jlspereira
Posts: 18
Joined: Sat Mar 01, 2014 10:35 pm

Re: Charset problem on grid after successful SQL SELECT

Post by jlspereira » Tue Mar 18, 2014 10:31 am

Gee! Thanks! It works perfectly!

Please let me know it I am interpreting in the right manner what you suggested:

1. create an object (aka a button) that will contain the predefined behaviour of another object, in this case, a grid (my grid name is "DataT")
2. point in the grid object (DataT) the standard behaviour to the behaviour programmed in the new object (thus the new FillInData code) and do that in the Message Box

Two questions arose:

1. can I avoid the Message Box command and put that in the code itself at application launch?

2. Sort order: something wend wrong and the sort order is not perfect. I am attaching a sample where "Suleimane" comes AFTER "Sábado" and it should be the opposite. How can I do to correct it?
Attachments
Screen Shot 2014-03-18 at 09.15.16.png
screenshot of sort problem

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Charset problem on grid after successful SQL SELECT

Post by bangkok » Tue Mar 18, 2014 11:23 am

jlspereira wrote: 1. create an object (aka a button) that will contain the predefined behaviour of another object, in this case, a grid (my grid name is "DataT")
2. point in the grid object (DataT) the standard behaviour to the behaviour programmed in the new object (thus the new FillInData code) and do that in the Message Box
Yes for both.
jlspereira wrote: 1. can I avoid the Message Box command and put that in the code itself at application launch?
No need. The modification made on the datagrid IS SAVED :) (provided you save your stack). So you do it once, and then it stays.
jlspereira wrote: 2. Sort order: something wend wrong and the sort order is not perfect. I am attaching a sample where "Suleimane" comes AFTER "Sábado" and it should be the opposite. How can I do to correct it?
Sorting problems with UTF8 in datagrid ?... hum... that's beyond my competence.

I think you should handle the problem in your query, at the MySQL server level.
Read this :
http://stackoverflow.com/questions/8782 ... r-ordering

Example : .....

Code: Select all

ORDER BY mycolumn COLLATE utf8_persian_ci

jlspereira
Posts: 18
Joined: Sat Mar 01, 2014 10:35 pm

Re: Charset problem on grid after successful SQL SELECT

Post by jlspereira » Tue Mar 18, 2014 3:04 pm

Nope... The data grid itself sorts out if I click on the column. I must go through the data grid (anyway I started with your suggestion but it failed when re-sorting)

Thanks for the help because the crucial problem is now solved by you. The reason to put the code at open stack was to make sure that in future applications I am treating well the character set issue.

Now I am going to a data grid form to sort out the other problems

thanks again

Joao

Post Reply