Question

My C++/Win32/Unicode program uses the ADO / MSDASQL / MyODBC chain to write data to MySQL.

The problem is that strings are converted to latin1 before arriving to MySQL, which expects UTF8. Accented characters are therefore rejected as being invalid characters.

My program passes OLE strings (UFT16-encoded) to ADO but somehow the MyODBC (MySQL ODBC driver) receives latin1 strings (I've recompiled MyODBC from the source code to check what comes in the driver through the SqlBindParameter ODBC function).

I've tried with both the ANSI and Unicode version of the MyODBC 5.3 driver. Also, all 'char%' and 'collation%' variables of MySQL say 'utf8'. MyODBC charset is configured as utf8.

How come ADO and/or MSDASQL turns my string to latin1?

TIA.

Was it helpful?

Solution 2

I eventually solved my problem: I use ADO prepared statements. The problem was the in the CreateParameter() call upon setup of the prepared statement

PCommand->CreateParameter(
  LPCTSTR(NULL), ADODB::adVarChar, ADODB::adParamInput, 50);

In there, simply replacing adVarChar by adVarWChar solved the problem. adVarChar seems to be considered an ANSI character without any regard to the underlying driver/DB.

OTHER TIPS

Precede the quoted string with N to save the data as Unicode:

INSERT INTO someTable (someField) VALUES (N'Ång')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top