Results 1 to 2 of 2

Thread: Mixing character encodings with QSql

  1. #1
    Join Date
    Jan 2009
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Mixing character encodings with QSql

    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.

  2. #2
    Join Date
    Apr 2012
    Location
    Vienna, Austria
    Posts
    17
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Mixing character encodings with QSql

    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?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.