summaryrefslogtreecommitdiffstats
path: root/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp')
-rw-r--r--tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp33
1 files changed, 32 insertions, 1 deletions
diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
index 76df61c892..6d6d65b791 100644
--- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
+++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
@@ -68,6 +68,8 @@ private slots:
void query_exec();
void execErrorRecovery_data() { generic_data(); }
void execErrorRecovery();
+ void prematureExec_data() { generic_data(); }
+ void prematureExec();
void first_data() { generic_data(); }
void first();
void next_data() { generic_data(); }
@@ -2770,6 +2772,35 @@ void tst_QSqlQuery::execErrorRecovery()
QVERIFY_SQL( q, exec() );
}
+void tst_QSqlQuery::prematureExec()
+{
+ QFETCH(QString, dbName);
+ // We only want the engine name, for addDatabase():
+ int cut = dbName.indexOf(QChar('@'));
+ if (cut < 0)
+ QSKIP("Failed to parse database type out of name");
+ dbName.truncate(cut);
+ cut = dbName.indexOf(QChar('_'));
+ if (cut >= 0)
+ dbName = dbName.mid(cut + 1);
+
+ auto db = QSqlDatabase::addDatabase(dbName);
+ QSqlQuery q(db);
+
+ QTest::ignoreMessage(QtWarningMsg,
+ "QSqlDatabasePrivate::removeDatabase: connection "
+ "'qt_sql_default_connection' is still in use, all "
+ "queries will cease to work.");
+ QTest::ignoreMessage(QtWarningMsg,
+ "QSqlDatabasePrivate::addDatabase: duplicate connection name "
+ "'qt_sql_default_connection', old connection removed.");
+ auto otherDb = QSqlDatabase::addDatabase(dbName);
+
+ QTest::ignoreMessage(QtWarningMsg, "QSqlQuery::exec: called before driver has been set up");
+ // QTBUG-100037: shouldn't crash !
+ QVERIFY(!q.exec("select stuff from TheVoid"));
+}
+
void tst_QSqlQuery::lastInsertId()
{
QFETCH( QString, dbName );