Skip to content

Commit

Permalink
Update to Qt 6.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
stoeckerb committed Dec 4, 2021
1 parent 831f35f commit e5e8d22
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions mysql/qsql_mysql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,15 @@ bool QMYSQLDriver::open(const QString& db,
unixSocket.isNull() ? nullptr : unixSocket.toUtf8().constData(),
optionFlags);

if (mysql != d->mysql) {
setLastError(qMakeError(tr("Unable to connect"),
QSqlError::ConnectionError, d));
mysql_close(d->mysql);
d->mysql = nullptr;
setOpenError(true);
return false;
}

// now ask the server to match the charset we selected
if (!cs || mysql_set_character_set(d->mysql, cs->csname) != 0) {
bool ok = false;
Expand All @@ -1292,30 +1301,15 @@ bool QMYSQLDriver::open(const QString& db,
mysql_character_set_name(d->mysql));
}

if (mysql == d->mysql) {
if (!db.isEmpty() && mysql_select_db(d->mysql, db.toUtf8().constData())) {
setLastError(qMakeError(tr("Unable to open database '%1'").arg(db), QSqlError::ConnectionError, d));
mysql_close(d->mysql);
setOpenError(true);
return false;
}
if (reconnect)
mysql_options(d->mysql, MYSQL_OPT_RECONNECT, &reconnect);
} else {
setLastError(qMakeError(tr("Unable to connect"),
QSqlError::ConnectionError, d));
if (!db.isEmpty() && mysql_select_db(d->mysql, db.toUtf8().constData())) {
setLastError(qMakeError(tr("Unable to open database '%1'").arg(db), QSqlError::ConnectionError, d));
mysql_close(d->mysql);
d->mysql = nullptr;
setOpenError(true);
return false;
}

// force the communication to be utf8mb4 (only utf8mb4 supports 4-byte characters)
if (mysql_set_character_set(d->mysql, "utf8mb4")) {
// this failed, try forcing it to utf (BMP only)
if (mysql_set_character_set(d->mysql, "utf8"))
qWarning() << "MySQL: Unable to set the client character set to utf8.";
}
if (reconnect)
mysql_options(d->mysql, MYSQL_OPT_RECONNECT, &reconnect);

d->preparedQuerysEnabled = checkPreparedQueries(d->mysql);

Expand Down

0 comments on commit e5e8d22

Please sign in to comment.