summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPhilip Seeger <philip@philip-seeger.de>2016-06-06 23:26:02 +0200
committerPhilip Seeger <philip@philip-seeger.de>2016-07-24 12:09:03 +0000
commit3f1e8d85cce8e8385476f189fb0a129bde7b8d7d (patch)
tree5571e70992ea827e4a3d4d8bbafde6f86c14635c /src
parent3c6a7a96ef17d5bd1fbea1d9e06617d281c6ca20 (diff)
MySQL: Use charset utf8mb4 to allow 4-byte characters
In MySQL, the character set named utf8 uses a maximum of 3 bytes per character and contains only BMP characters. It does not support supplementary characters. In version 5.5.3, a new UTF-8 character set called utf8mb4 has been introduced, which supports 4-byte characters. [ChangeLog][QtSql][QSqlDatabase] When connecting to a MySQL server whose version is 5.5.3 or higher, the default connection charset is now utf8mb4 instead of utf8 to allow 4-byte UTF-8 encodings. Change-Id: I718bd23212afd67367b39d4ce7da2a99ae0f1cca Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> Reviewed-by: Liang Qi <liang.qi@qt.io> Reviewed-by: Andy Shaw <andy.shaw@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/sqldrivers/mysql/qsql_mysql.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp
index b13e10e3a5..30a0a04f44 100644
--- a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp
+++ b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp
@@ -1414,8 +1414,13 @@ bool QMYSQLDriver::open(const QString& db,
}
#if (MYSQL_VERSION_ID >= 40113 && MYSQL_VERSION_ID < 50000) || MYSQL_VERSION_ID >= 50007
- // force the communication to be utf8
- mysql_set_character_set(d->mysql, "utf8");
+ 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 {
+ // force the communication to be utf8
+ mysql_set_character_set(d->mysql, "utf8");
+ }
#endif
#ifndef QT_NO_TEXTCODEC
d->tc = codec(d->mysql);