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>
This commit is contained in:
parent
3c6a7a96ef
commit
3f1e8d85cc
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user