summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2019-10-06 12:56:34 +0200
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2019-10-15 13:37:42 +0200
commited7dd9a6edd7afd8798751c8b1d3ee7802ae253f (patch)
tree642dffad5d18cbad3f7bf723d89af0ab6874b50f /tests
parent2ec93e29f75e0cb37650255d478b8e3a9da4dc25 (diff)
QODBC: Fix crash when a prepared statement is deleted after the db was removed
When a prepared statement is still alive after the database was removed with QSqlDatabase::removeDatabase(), the cleanup routine is trying to access the driver which is no longer alive which results in a crash. Fixes: QTBUG-79019 Change-Id: I4630e3b947a12b23ed062f015abc373fc0e246c1 Reviewed-by: Andy Shaw <andy.shaw@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp27
1 files changed, 13 insertions, 14 deletions
diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
index 784d0a70d7..fd7f24f308 100644
--- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
+++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
@@ -196,8 +196,7 @@ private slots:
void task_250026_data() { generic_data("QODBC"); }
void task_250026();
- void task_205701_data() { generic_data("QMYSQL"); }
- void task_205701();
+ void crashQueryOnCloseDatabase();
void task_233829_data() { generic_data("QPSQL"); }
void task_233829();
@@ -311,6 +310,8 @@ void tst_QSqlQuery::init()
void tst_QSqlQuery::cleanup()
{
+ if (QTest::currentTestFunction() == QLatin1String("crashQueryOnCloseDatabase"))
+ return;
QFETCH( QString, dbName );
QSqlDatabase db = QSqlDatabase::database( dbName );
CHECK_DATABASE( db );
@@ -3448,19 +3449,17 @@ void tst_QSqlQuery::task_250026()
QCOMPARE( q.value( 0 ).toString().length(), data1026.length() );
}
-void tst_QSqlQuery::task_205701()
+void tst_QSqlQuery::crashQueryOnCloseDatabase()
{
- QSqlDatabase qsdb = QSqlDatabase::addDatabase("QMYSQL", "atest");
- qsdb.setHostName("test");
- qsdb.setDatabaseName("test");
- qsdb.setUserName("test");
- qsdb.setPassword("test");
- qsdb.open();
-
-// {
- QSqlQuery query(qsdb);
-// }
- QSqlDatabase::removeDatabase("atest");
+ for (const auto &dbName : qAsConst(dbs.dbNames)) {
+ QSqlDatabase clonedDb = QSqlDatabase::cloneDatabase(
+ QSqlDatabase::database(dbName), "crashTest");
+ qDebug() << "Testing crash in sqlquery dtor for driver" << clonedDb.driverName();
+ QVERIFY(clonedDb.open());
+ QSqlQuery q(clonedDb);
+ clonedDb.close();
+ QSqlDatabase::removeDatabase("crashTest");
+ }
}
#ifdef NOT_READY_YET