Putting Unicode text into MySQL and getting it back
Posted: Sun Jun 02, 2013 3:41 am
From a LiveCode field, want to put UTF-8 text into a field in a table in a MySQL database where it can be searchable, and get it back unchanged.
I have been trying for a week and just can't get it to work, unicode encoding and decoding etc.
I guess that this is a problem for many.
OK, the details:
In a field called "S4 Text" (it is text in S4 phonetics), I have the following text with weird but wanted characters:
I want insert this into my database with something like this:
But all I get is garbage characters in the database.
I can take the text from field "S4 Text" field as unicode, convert it back and put it in another field (called "Data") with the following routine:
This puts the following into field "Data"
Why can't a MySQL database perform the same role as a variable, transparently?
I really need to get this sorted out, all suggestions gratefully received.
I have been trying for a week and just can't get it to work, unicode encoding and decoding etc.
I guess that this is a problem for many.
OK, the details:
In a field called "S4 Text" (it is text in S4 phonetics), I have the following text with weird but wanted characters:
ðə top twe‛ntii pəse‛nt
hæv oo‛lweiz bii‛n pritii we‛l edʒəkeitid
I want insert this into my database with something like this:
Code: Select all
on mouseUp
global gConnectionID
if gConnectionID is not a number then
answer error "Please connect to the database first."
exit to top
end if
--put unidecode(the unicodeText of field "S4 Text" ,"UTF8") into theS4Text
get the unicodeText of fld "S4 Text"
put uniDecode(it,"utf8") into theS4Text
put "Update main set S4_Spelling = '" &theS4Text& "';" into tSQL
put tSQL
revExecuteSQL gConnectionID, tSQL
put the result
end mouseUp
I can take the text from field "S4 Text" field as unicode, convert it back and put it in another field (called "Data") with the following routine:
Code: Select all
on mouseUp
put uniEncode(the unicodeText of field "S4 Text","UTF16") into theUnicode8text
set the unicodeText of field "Data" to uniDecode(theUnicode8text,"English")
end mouseUp
The boldness of the characters is lost, but this does not matter.ðə top twe‛ntii pəse‛nt
hæv oo‛lweiz bii‛n pritii we‛l edʒəkeitid
Why can't a MySQL database perform the same role as a variable, transparently?
I really need to get this sorted out, all suggestions gratefully received.