diff options
author | Andy Shaw <andy.shaw@digia.com> | 2011-06-03 06:17:40 (GMT) |
---|---|---|
committer | Charles Yin <charles.yin@nokia.com> | 2011-07-26 23:25:30 (GMT) |
commit | 2c60a4f67f9fb02f3b711fe749b2f293a07b4e02 (patch) | |
tree | 9f3899b1723c3daa0ed2d947f212e2996d0e091d /tests/auto/qsqlrelationaltablemodel | |
parent | e2e62bc810d21fecc9ed1d1db486b529b760d292 (diff) | |
download | Qt-2c60a4f67f9fb02f3b711fe749b2f293a07b4e02.zip Qt-2c60a4f67f9fb02f3b711fe749b2f293a07b4e02.tar.gz Qt-2c60a4f67f9fb02f3b711fe749b2f293a07b4e02.tar.bz2 |
Make it possible to update a related table after an external update
When a table that is related to in a QSqlRelationalTableModel gets
updated in some way (e.g. a new row, or the data is changed) then the
related model could not be updated without recreating the
QSqlRelationalTableModel.
Now, to get around this, select() can be called on the related model to
get it to be updated.
Task-number: QTBUG-7885
Reviewed-by: Charles Yin
Reviewed-by: Michael Goddard
Change-Id: Ic589e840234f3a809bcb112a807a87afe0bc25ca
Diffstat (limited to 'tests/auto/qsqlrelationaltablemodel')
-rw-r--r-- | tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp b/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp index cc4ab67..5f1a621 100644 --- a/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp +++ b/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp @@ -92,6 +92,7 @@ private slots: void escapedTableName(); void whiteSpaceInIdentifiers(); void psqlSchemaTest(); + void selectAfterUpdate(); private: void dropTestTables( QSqlDatabase db ); @@ -1467,5 +1468,27 @@ void tst_QSqlRelationalTableModel::psqlSchemaTest() QVERIFY_SQL(model, select()); } +void tst_QSqlRelationalTableModel::selectAfterUpdate() +{ + QFETCH_GLOBAL(QString, dbName); + QSqlDatabase db = QSqlDatabase::database(dbName); + CHECK_DATABASE(db); + + QSqlRelationalTableModel model(0, db); + model.setTable(reltest1); + model.setRelation(2, QSqlRelation(reltest2, "tid", "title")); + QVERIFY_SQL(model, select()); + QVERIFY(model.relationModel(2)->rowCount() == 2); + { + QSqlQuery q(db); + QVERIFY_SQL(q, exec("insert into " + reltest2 + " values(3, 'mrs')")); + model.relationModel(2)->select(); + } + QVERIFY(model.relationModel(2)->rowCount() == 3); + QVERIFY(model.setData(model.index(0,2), 3)); + QVERIFY(model.submitAll()); + QCOMPARE(model.data(model.index(0,2)), QVariant("mrs")); +} + QTEST_MAIN(tst_QSqlRelationalTableModel) #include "tst_qsqlrelationaltablemodel.moc" |