summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoni Poikelin <joni.poikelin@qt.io>2017-02-27 12:59:27 +0200
committerJoni Poikelin <joni.poikelin@qt.io>2017-02-28 05:10:47 +0000
commite7f019011ace53d83d439c7c596fb063e02f5d79 (patch)
tree6a1b5d4358585913ca09153bc0623a836e8a78d0
parent740b5c1fea56d1ec7b227b25e58a64355a8963f9 (diff)
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 <andy.shaw@qt.io>
-rw-r--r--src/plugins/sqldrivers/mysql/qsql_mysql.cpp12
1 files 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