XE3 mysql utf8 problem
Posted: 14.05.2013, 04:34
Hi,
I just upgraded from Delphi7 to XE3. I was having trouble in doing insert/update SQL to my mysql server.
In delphi7, if I want to save a utf8 field in mysql DB I will do this :
ws : widestring;
sql : string;
ws := '環保及資源管'; // which was some Chinese character
sql := 'insert into DB_123 values (''' + utf8encode(ws) + ''')';
.....
Then do a mysqlexec (sql)...... Everything was fine in Delphi7, the value in the widestring was correctly stored in UTF8 in mysql database server.
The problem come when I moved to XE3, where string is now unicodestring in UTF16, so the same code will be :
sql : string;
sql := 'insert into DB_123 values (''環保及資源管'')';
then do a Zconnection1.ExecuteDirect (sql);
The call was successful, but the piece of data was stored as ???? in the mysql database.
I have set the following in Zconnection1 :
Zconnection1.controlcodepage := cCP_utf16;
zconnection1.clientcodepage := utf8;
Still I got ??? in my DB server.
So what's wrong ? Please help !
I just upgraded from Delphi7 to XE3. I was having trouble in doing insert/update SQL to my mysql server.
In delphi7, if I want to save a utf8 field in mysql DB I will do this :
ws : widestring;
sql : string;
ws := '環保及資源管'; // which was some Chinese character
sql := 'insert into DB_123 values (''' + utf8encode(ws) + ''')';
.....
Then do a mysqlexec (sql)...... Everything was fine in Delphi7, the value in the widestring was correctly stored in UTF8 in mysql database server.
The problem come when I moved to XE3, where string is now unicodestring in UTF16, so the same code will be :
sql : string;
sql := 'insert into DB_123 values (''環保及資源管'')';
then do a Zconnection1.ExecuteDirect (sql);
The call was successful, but the piece of data was stored as ???? in the mysql database.
I have set the following in Zconnection1 :
Zconnection1.controlcodepage := cCP_utf16;
zconnection1.clientcodepage := utf8;
Still I got ??? in my DB server.
So what's wrong ? Please help !