summaryrefslogtreecommitdiff
path: root/tests/auto/sql
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-04-12 11:39:21 +0200
committerAndy Shaw <andy.shaw@qt.io>2021-05-27 15:39:01 +0200
commit79edc48c0dcd03a33abeb36c4b5b512a61339113 (patch)
tree9c66760d0c6ce409cf9f41fa52f6b6a979ee8ecb /tests/auto/sql
parent096c6223683e35dddd930fd06ee0dc0f5eefcf22 (diff)
downloadqtbase-79edc48c0dcd03a33abeb36c4b5b512a61339113.tar.gz
QSqlTableModel::orderByClause(): Quote the table name
This ensures correct handling of names with special characters. Fixes: QTBUG-92584 Change-Id: I95c7c54d9c7ee00b221a55f3d07ef1ec3a3bd217 Reviewed-by: Andy Shaw <andy.shaw@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> (cherry picked from commit 21b3b54193b9d90ee377fdfa306e21d2fdfe2837)
Diffstat (limited to 'tests/auto/sql')
-rw-r--r--tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp48
1 files changed, 26 insertions, 22 deletions
diff --git a/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp b/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp
index 157565bc03..935734c070 100644
--- a/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp
+++ b/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp
@@ -311,33 +311,37 @@ void tst_QSqlTableModel::select()
QSqlDatabase db = QSqlDatabase::database(dbName);
CHECK_DATABASE(db);
- QSqlTableModel model(0, db);
- model.setTable(test);
- model.setSort(0, Qt::AscendingOrder);
- QVERIFY_SQL(model, select());
+ QString withoutQuotes = test;
+ const QStringList tables = {test, withoutQuotes.remove(QLatin1Char('"'))};
+ for (const QString &tbl : tables) {
+ QSqlTableModel model(0, db);
+ model.setTable(tbl);
+ model.setSort(0, Qt::AscendingOrder);
+ QVERIFY_SQL(model, select());
- QCOMPARE(model.rowCount(), 3);
- QCOMPARE(model.columnCount(), 3);
+ QCOMPARE(model.rowCount(), 3);
+ QCOMPARE(model.columnCount(), 3);
- QCOMPARE(model.data(model.index(0, 0)).toInt(), 1);
- QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry"));
- QCOMPARE(model.data(model.index(0, 2)).toInt(), 1);
- QCOMPARE(model.data(model.index(0, 3)), QVariant());
+ QCOMPARE(model.data(model.index(0, 0)).toInt(), 1);
+ QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry"));
+ QCOMPARE(model.data(model.index(0, 2)).toInt(), 1);
+ QCOMPARE(model.data(model.index(0, 3)), QVariant());
- QCOMPARE(model.data(model.index(1, 0)).toInt(), 2);
- QCOMPARE(model.data(model.index(1, 1)).toString(), QString("trond"));
- QCOMPARE(model.data(model.index(1, 2)).toInt(), 2);
- QCOMPARE(model.data(model.index(1, 3)), QVariant());
+ QCOMPARE(model.data(model.index(1, 0)).toInt(), 2);
+ QCOMPARE(model.data(model.index(1, 1)).toString(), QString("trond"));
+ QCOMPARE(model.data(model.index(1, 2)).toInt(), 2);
+ QCOMPARE(model.data(model.index(1, 3)), QVariant());
- QCOMPARE(model.data(model.index(2, 0)).toInt(), 3);
- QCOMPARE(model.data(model.index(2, 1)).toString(), QString("vohi"));
- QCOMPARE(model.data(model.index(2, 2)).toInt(), 3);
- QCOMPARE(model.data(model.index(2, 3)), QVariant());
+ QCOMPARE(model.data(model.index(2, 0)).toInt(), 3);
+ QCOMPARE(model.data(model.index(2, 1)).toString(), QString("vohi"));
+ QCOMPARE(model.data(model.index(2, 2)).toInt(), 3);
+ QCOMPARE(model.data(model.index(2, 3)), QVariant());
- QCOMPARE(model.data(model.index(3, 0)), QVariant());
- QCOMPARE(model.data(model.index(3, 1)), QVariant());
- QCOMPARE(model.data(model.index(3, 2)), QVariant());
- QCOMPARE(model.data(model.index(3, 3)), QVariant());
+ QCOMPARE(model.data(model.index(3, 0)), QVariant());
+ QCOMPARE(model.data(model.index(3, 1)), QVariant());
+ QCOMPARE(model.data(model.index(3, 2)), QVariant());
+ QCOMPARE(model.data(model.index(3, 3)), QVariant());
+ }
}
class SelectRowModel: public QSqlTableModel