I’m getting a runtime error when converting a string value to text.
Example:
DIM EMPName as text
DIM sql as text
DIM rs as recordset
sql = “SELECT emp_name FROM emp_basic”
EMPName = rs.field(“emp_name”).stringvalue.totext
rs.close
using SQLite, this works fine since the datatype from the database is Text.
The error comes when using MySQL and the database type is VARCHAR(45)
“Unhandled xojo.Core.BadDataException
Message: String must have a known encoding”
I have not been able to find an example that shows a way to correct the encoding issue.
Please Help. Thanks
If you’re getting this from mysql make sure it is returning utf8
Have you ever executed the mysql “SET NAMES ‘utf-8’” directive when you first connect ?
Then this should be fine EMPName = rs.field(“emp_name”).stringvalue.defineEncoding(Encodings.UTF8).ToText
After doing some additional investigation, of the actual code I was using the error was coming from not coming from the location I was expecting. I had been doing my coding and debugging on a windows machine. After running "SET NAMES ‘utf-8’ on the MySQL server, and getting the same error, I ran the code on OS X and the error message I received was different and gave me the line number in the code that needed changed. The error in the windows debugger was generic and coming from an event where as the OS X debugger was more specific to the exact line of code in a method.
I’m guessing that I need to report this in the feedback…