summaryrefslogtreecommitdiffstats
path: root/tests/auto/qsqlquerymodel
diff options
context:
space:
mode:
authorDerick Hawcroft <derick.hawcroft@nokia.com>2009-06-15 01:16:59 (GMT)
committerDerick Hawcroft <derick.hawcroft@nokia.com>2009-06-15 01:16:59 (GMT)
commit16fe846058aa0a89577660d18bdc0aceda7fecfd (patch)
tree517cdb1ad6a26f872b5b4a15b6ff74e379e9448b /tests/auto/qsqlquerymodel
parent335780b2c0cba64d75812d7e2e98f44e072d171d (diff)
downloadQt-16fe846058aa0a89577660d18bdc0aceda7fecfd.zip
Qt-16fe846058aa0a89577660d18bdc0aceda7fecfd.tar.gz
Qt-16fe846058aa0a89577660d18bdc0aceda7fecfd.tar.bz2
Adds unit test for task: 180617
Tests to see if QSqlQueryModel inserts extra empty gridlines into a view for a specific SQL query statement that should return no data.
Diffstat (limited to 'tests/auto/qsqlquerymodel')
-rw-r--r--tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp45
1 files changed, 41 insertions, 4 deletions
diff --git a/tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp b/tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp
index 88b5770..051764e 100644
--- a/tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp
+++ b/tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp
@@ -94,6 +94,9 @@ private slots:
void setQueryWithNoRowsInResultSet_data() { generic_data(); }
void setQueryWithNoRowsInResultSet();
+ void task_180617();
+ void task_180617_data() { generic_data(); }
+
private:
void generic_data(const QString &engine=QString());
void dropTestTables(QSqlDatabase db);
@@ -496,7 +499,7 @@ void tst_QSqlQueryModel::withSortFilterProxyModel()
QSignalSpy modelRowsInsertedSpy(&model, SIGNAL(rowsInserted(const QModelIndex &, int, int)));
model.setQuery(QSqlQuery("SELECT * FROM " + qTableName("test3"), db));
view.scrollToBottom();
-
+
QTestEventLoop::instance().enterLoop(1);
QCOMPARE(proxy.rowCount(), 511);
@@ -530,12 +533,12 @@ void tst_QSqlQueryModel::setQuerySignalEmission()
QSignalSpy modelRowsRemovedSpy(&model, SIGNAL(rowsRemoved(const QModelIndex &, int, int)));
// First select, the model was empty and no rows had to be removed!
- model.setQuery(QSqlQuery("SELECT * FROM " + qTableName("test"), db));
+ model.setQuery(QSqlQuery("SELECT * FROM " + qTableName("test"), db));
QCOMPARE(modelRowsAboutToBeRemovedSpy.count(), 0);
QCOMPARE(modelRowsRemovedSpy.count(), 0);
// Second select, the model wasn't empty and two rows had to be removed!
- model.setQuery(QSqlQuery("SELECT * FROM " + qTableName("test"), db));
+ model.setQuery(QSqlQuery("SELECT * FROM " + qTableName("test"), db));
QCOMPARE(modelRowsAboutToBeRemovedSpy.count(), 1);
QCOMPARE(modelRowsAboutToBeRemovedSpy.value(0).value(1).toInt(), 0);
QCOMPARE(modelRowsAboutToBeRemovedSpy.value(0).value(2).toInt(), 1);
@@ -559,10 +562,44 @@ void tst_QSqlQueryModel::setQueryWithNoRowsInResultSet()
// The query's result set will be empty so no signals should be emitted!
QSqlQuery query(db);
QVERIFY_SQL(query, exec("SELECT * FROM " + qTableName("test") + " where 0 = 1"));
- model.setQuery(query);
+ model.setQuery(query);
QCOMPARE(modelRowsAboutToBeInsertedSpy.count(), 0);
QCOMPARE(modelRowsInsertedSpy.count(), 0);
}
+// For task 180617
+// According to the task, several specific duplicate SQL queries would cause
+// multiple empty grid lines to be visible in the view
+void tst_QSqlQueryModel::task_180617()
+{
+ QFETCH(QString, dbName);
+ QSqlDatabase db = QSqlDatabase::database(dbName);
+ CHECK_DATABASE(db);
+
+ QTableView view;
+ QCOMPARE(view.columnAt(0), -1);
+ QCOMPARE(view.rowAt(0), -1);
+
+ QSqlQueryModel model;
+ model.setQuery( "SELECT TOP 0 * FROM " + qTableName("test3"), db );
+ view.setModel(&model);
+
+ bool error = false;
+ // Usually a syntax error
+ if (model.lastError().isValid()) // usually a syntax error
+ error = true;
+
+ QCOMPARE(view.columnAt(0), (error)?-1:0 );
+ QCOMPARE(view.rowAt(0), -1);
+
+ model.setQuery( "SELECT TOP 0 * FROM " + qTableName("test3"), db );
+ model.setQuery( "SELECT TOP 0 * FROM " + qTableName("test3"), db );
+ model.setQuery( "SELECT TOP 0 * FROM " + qTableName("test3"), db );
+ model.setQuery( "SELECT TOP 0 * FROM " + qTableName("test3"), db );
+
+ QCOMPARE(view.columnAt(0), (error)?-1:0 );
+ QCOMPARE(view.rowAt(0), -1);
+}
+
QTEST_MAIN(tst_QSqlQueryModel)
#include "tst_qsqlquerymodel.moc"