MySQL ODBC Driver Unicode/UTF-8 Support Issue

"Shiwei Yin [Wesley]" <[email protected]> Wed, 9 Sep 2009 01:32:51 -0800
Newsgroups gmane.comp.db.mysql.odbc
Message-ID <C193E097DA77BB4482B17A5E5802BF230B61B634@parc-exch01.tibco-support.com>
Hi,
Now I use Connector/ODBC 5.1 driver, the exact driver information are as follows:
Driver = myodbc5.dll
Driver Version = 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 character into a table. Here is the table definition from "show create table cs_test2" command:
CREATE TABLE `cs_test2` (
  `val` varchar(20) CHARACTER SET utf8 DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1

The following are the code to insert value into this table.
/////////////////////////////////////////////////////////////////////////
char* StrIns = "insert into cs_test2 values (?)";
unsigned char ValBuf[5] = {0xE6,0xAF,0x8F,'\0','\0'};
SQLRETURN ret;
SQLINTEGER cbValue = 3;
SQLLEN RowCount;
ret = SQLPrepare(hstmt,(SQLCHAR*)StrIns,strlen(StrIns));
if (ret == SQL_SUCCESS)
{
ret=SQLBindParameter(hstmt,1,SQL_PARAM_INPUT,SQL_C_WCHAR,SQL_WVARCHAR,20,0,ValBuf,0,&cbValue);
                if (ret == SQL_SUCCESS)
                {
                        ret = SQLExecute(hstmt);
                        if (ret == SQL_SUCCESS)
                        {
                                ret = SQLRowCount(hstmt,&RowCount);
                                if (ret == SQL_SUCCESS)
                                {
                                        printf("Affected %d row.\n", RowCount);
                                }
                        }
                        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 using "select hex(val) from cs_test2" in MySQL Query Browser, the inserted character 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/[email protected]