From e7f019011ace53d83d439c7c596fb063e02f5d79 Mon Sep 17 00:00:00 2001 From: Joni Poikelin Date: Mon, 27 Feb 2017 12:59:27 +0200 Subject: Fix wrong codec with MySQL plugin in newer versions Since MySQL now properly supports UTF-8 through utf8mb4 option, it caused regression on systems which did not use UTF-8 encoding by default which caused queries to fail as they were converted into system codec. To fix this, simply use UTF-8 encoding for queries when MySQL supports it. Task-number: QTBUG-59176 Change-Id: I21cc9102b15df15a31bc7c74469321c44a257946 Reviewed-by: Andy Shaw --- src/plugins/sqldrivers/mysql/qsql_mysql.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp index 7cfa554418..ee439fa33e 100644 --- a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp +++ b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp @@ -1421,13 +1421,17 @@ bool QMYSQLDriver::open(const QString& db, if (mysql_get_client_version() >= 50503 && mysql_get_server_version(d->mysql) >= 50503) { // force the communication to be utf8mb4 (only utf8mb4 supports 4-byte characters) mysql_set_character_set(d->mysql, "utf8mb4"); - } else { +#ifndef QT_NO_TEXTCODEC + d->tc = QTextCodec::codecForName("UTF-8"); +#endif + } else + { // force the communication to be utf8 mysql_set_character_set(d->mysql, "utf8"); - } -#endif #ifndef QT_NO_TEXTCODEC - d->tc = codec(d->mysql); + d->tc = codec(d->mysql); +#endif + } #endif #if MYSQL_VERSION_ID >= 40108 -- cgit v1.2.3