PDA

View Full Version : Mixing character encodings with QSql



Barnacle
23rd January 2009, 14:49
Anyone know if it's possible to use other encodings than UTF-8 in things like QSqlQuery?

My problem is that my MySQL database has a mixture of encodings. For example, some columns use the normal UTF-8 encoding and some use ascii_bin or latin1 (I can not change this). When I run a query against an ascii_bin column I get "illegal mix of collations" errors presumably because Qt is trying to convert everything to UTF on the back-end and the database doesn't like that.

So I'm wondering if there any way to force a query to use a different encoding than UTF? It would be nice if the string QVariant had a way to forcibly set the character encoding but I don't know how to do it if it's possible. Either that or if QSqlQuery had a way to set the encoding of the bound values.

axed
19th March 2014, 11:08
Same here but with ODBC.
The database works with IBM850 and QSqlResult only returns wrong encoded strings.
To bad there's no way to convert from the wrongly interpreted UTF8 to what encoding the result should be.

Even though there is QTextCodec, the text arrives crippled and so there is no way (as far as i know) to en/decode it right.

(Qt5.2.1)

The last thing that would come to my mind is, to reimlement QODBCDriver and kick all the uses of QVariant::toString and QString out and replace them by a QByteArray.

Or does anybody have some better advice?