MySQL ODBC Driver Unicode/UTF-8 Support Issue

MySQL ODBC Driver Unicode/UTF-8 Support Issue

am 09.09.2009 11:32:51 von syin

Hi,
Now I use Connector/ODBC 5.1 driver, the exact driver information are as fo=
llows:
Driver =3D myodbc5.dll
Driver Version =3D 05.01.0005
And MySQL database version is: 5.1.36-community MySQL Community Server

I use VC++ to connect to MySQL database. I want to insert a Chinese charact=
er into a table. Here is the table definition from "show create table cs_te=
st2" command:
CREATE TABLE `cs_test2` (
`val` varchar(20) CHARACTER SET utf8 DEFAULT NULL
) ENGINE=3DInnoDB DEFAULT CHARSET=3Dlatin1

The following are the code to insert value into this table.
//////////////////////////////////////////////////////////// /////////////
char* StrIns =3D "insert into cs_test2 values (?)";
unsigned char ValBuf[5] =3D {0xE6,0xAF,0x8F,'\0','\0'};
SQLRETURN ret;
SQLINTEGER cbValue =3D 3;
SQLLEN RowCount;
ret =3D SQLPrepare(hstmt,(SQLCHAR*)StrIns,strlen(StrIns));
if (ret == SQL_SUCCESS)
{
ret=3DSQLBindParameter(hstmt,1,SQL_PARAM_INPUT,SQL_C_WCHAR,S QL_WVARCHAR,20,=
0,ValBuf,0,&cbValue);
if (ret == SQL_SUCCESS)
{
ret =3D SQLExecute(hstmt);
if (ret == SQL_SUCCESS)
{
ret =3D SQLRowCount(hstmt,&RowCount);
if (ret == SQL_SUCCESS)
{
printf("Affected %d row.\n", RowCou=
nt);
}
}
SQLFreeStmt(hstmt,SQL_CLOSE);
}
}
//////////////////////////////////////////////////////////// ///////////////=
/
In the code, I use SQL_C_WCHAR and SQL_WVARCHAR as the C data type and SQL =
data type respectively.

The code can be executed successfully. However, when I query the database u=
sing "select hex(val) from cs_test2" in MySQL Query Browser, the inserted c=
haracter hex value is 'EABFA6'. But in my code, the value I inserted should=
be 'E6AF8F'.

Why the value is changed during the insertion? What is the problem? Is it a=
driver issue?

Thanks,
Wesley

--
MySQL ODBC Mailing List
For list archives: http://lists.mysql.com/myodbc
To unsubscribe: http://lists.mysql.com/myodbc?unsub=3Dgcdmo-myodbc@m.gmane.o rg