@@ -1277,6 +1277,15 @@ bool QMYSQLDriver::open(const QString& db,
1277
1277
unixSocket.isNull () ? nullptr : unixSocket.toUtf8 ().constData (),
1278
1278
optionFlags);
1279
1279
1280
+ if (mysql != d->mysql ) {
1281
+ setLastError (qMakeError (tr (" Unable to connect" ),
1282
+ QSqlError::ConnectionError, d));
1283
+ mysql_close (d->mysql );
1284
+ d->mysql = nullptr ;
1285
+ setOpenError (true );
1286
+ return false ;
1287
+ }
1288
+
1280
1289
// now ask the server to match the charset we selected
1281
1290
if (!cs || mysql_set_character_set (d->mysql , cs->csname ) != 0 ) {
1282
1291
bool ok = false ;
@@ -1292,30 +1301,15 @@ bool QMYSQLDriver::open(const QString& db,
1292
1301
mysql_character_set_name (d->mysql ));
1293
1302
}
1294
1303
1295
- if (mysql == d->mysql ) {
1296
- if (!db.isEmpty () && mysql_select_db (d->mysql , db.toUtf8 ().constData ())) {
1297
- setLastError (qMakeError (tr (" Unable to open database '%1'" ).arg (db), QSqlError::ConnectionError, d));
1298
- mysql_close (d->mysql );
1299
- setOpenError (true );
1300
- return false ;
1301
- }
1302
- if (reconnect)
1303
- mysql_options (d->mysql , MYSQL_OPT_RECONNECT, &reconnect);
1304
- } else {
1305
- setLastError (qMakeError (tr (" Unable to connect" ),
1306
- QSqlError::ConnectionError, d));
1304
+ if (!db.isEmpty () && mysql_select_db (d->mysql , db.toUtf8 ().constData ())) {
1305
+ setLastError (qMakeError (tr (" Unable to open database '%1'" ).arg (db), QSqlError::ConnectionError, d));
1307
1306
mysql_close (d->mysql );
1308
- d->mysql = nullptr ;
1309
1307
setOpenError (true );
1310
1308
return false ;
1311
1309
}
1312
1310
1313
- // force the communication to be utf8mb4 (only utf8mb4 supports 4-byte characters)
1314
- if (mysql_set_character_set (d->mysql , " utf8mb4" )) {
1315
- // this failed, try forcing it to utf (BMP only)
1316
- if (mysql_set_character_set (d->mysql , " utf8" ))
1317
- qWarning () << " MySQL: Unable to set the client character set to utf8." ;
1318
- }
1311
+ if (reconnect)
1312
+ mysql_options (d->mysql , MYSQL_OPT_RECONNECT, &reconnect);
1319
1313
1320
1314
d->preparedQuerysEnabled = checkPreparedQueries (d->mysql );
1321
1315
0 commit comments