QSqlDatabase: Skip confusing thread warning on invalid QSqlDatabase

If the db isn't valid, then that's the actual issue, not the fact that we're
getting the same invalid db (with the same driver QSqlNullDriver) in
multiple threads.

Change-Id: I95490818ed78e741c3823e115f139c2cff01b0b1
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
This commit is contained in:
David Faure 2018-04-06 09:05:40 +02:00
parent cab5f37ef4
commit e729ac6dc5
2 changed files with 7 additions and 2 deletions

View File

@ -229,12 +229,14 @@ QSqlDatabase QSqlDatabasePrivate::database(const QString& name, bool open)
dict->lock.lockForRead();
QSqlDatabase db = dict->value(name);
dict->lock.unlock();
if (db.driver() && db.driver()->thread() != QThread::currentThread()) {
if (!db.isValid())
return db;
if (db.driver()->thread() != QThread::currentThread()) {
qWarning("QSqlDatabasePrivate::database: requested database does not belong to the calling thread.");
return QSqlDatabase();
}
if (db.isValid() && !db.isOpen() && open) {
if (open && !db.isOpen()) {
if (!db.open())
qWarning() << "QSqlDatabasePrivate::database: unable to open database:" << db.lastError().text();

View File

@ -2374,6 +2374,9 @@ public slots:
"QSqlDatabasePrivate::database: requested database does not belong to the calling thread.");
QSqlDatabase db = QSqlDatabase::database(dbName);
QVERIFY(!db.isValid());
QSqlDatabase invalidDb = QSqlDatabase::database("invalid");
QVERIFY(!invalidDb.isValid());
QThread::currentThread()->exit();
}
private: