diff options
author | Mark Brand <mabrand@mabrand.nl> | 2012-03-15 11:23:27 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-15 15:35:43 +0100 |
commit | 26450fe6a6340b09b1e3fa49c35028aa15ef223f (patch) | |
tree | 3c39e9d1aebb649953e6a758c0820702083e502c /tests/auto/sql/models | |
parent | 108748404beb607538ea965a21fa932d275eecdd (diff) |
QSqlTableModel::removeRows() enforce edit strategy
For OnFieldChange and OnRowChange, we don't want more than one row in
the cache with uncommitted changes. This could happen if deletion in
the database fails while other changes are pending.
Chosen solution is to return false if other rows have pending changes.
Also, we only allow 1 row removed at a time.
Updated test, changes and documentation.
Change-Id: I68baf6d221789b4754e891535070011c759a2155
Reviewed-by: Honglei Zhang <honglei.zhang@nokia.com>
Diffstat (limited to 'tests/auto/sql/models')
-rw-r--r-- | tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp b/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp index 8bc71257e3..afe2c59144 100644 --- a/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp +++ b/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp @@ -592,6 +592,8 @@ void tst_QSqlTableModel::insertRowFailure() QCOMPARE(model.data(model.index(1, 1)).toString(), QString("blah")); QFAIL_SQL(model, insertRow(2)); QCOMPARE(model.rowCount(), 2); + QFAIL_SQL(model, removeRow(1)); + QCOMPARE(model.rowCount(), 2); } else { QVERIFY_SQL(model, setData(model.index(1, 1), QString("eggs"))); QCOMPARE(model.data(model.index(1, 1)).toString(), QString("eggs")); @@ -599,6 +601,8 @@ void tst_QSqlTableModel::insertRowFailure() QCOMPARE(model.data(model.index(1, 1)).toString(), QString("spam")); QVERIFY_SQL(model, insertRow(2)); QCOMPARE(model.rowCount(), 3); + QVERIFY_SQL(model, removeRow(1)); + QCOMPARE(model.rowCount(), 3); } // restore empty table @@ -795,8 +799,10 @@ void tst_QSqlTableModel::removeRows() QVERIFY(!model.removeRows(1, 0)); // zero count QVERIFY(!model.removeRows(5, 1)); // past end (DOESN'T causes a beforeDelete to be emitted) QVERIFY(!model.removeRows(1, 0, model.index(2, 0))); // can't pass a valid modelindex + QFAIL_SQL(model, removeRows(0, 2)); // more than 1 row on OnFieldChange - QVERIFY_SQL(model, removeRows(0, 2)); + QVERIFY_SQL(model, removeRows(0, 1)); + QVERIFY_SQL(model, removeRows(1, 1)); QCOMPARE(beforeDeleteSpy.count(), 2); QVERIFY(beforeDeleteSpy.at(0).at(0).toInt() == 0); QVERIFY(beforeDeleteSpy.at(1).at(0).toInt() == 1); @@ -1079,6 +1085,7 @@ void tst_QSqlTableModel::isDirty() QFAIL_SQL(model, setData(model.index(1, 1), QString("sam i am"))); QFAIL_SQL(model, setRecord(1, model.record(1))); QFAIL_SQL(model, insertRow(1)); + QFAIL_SQL(model, removeRow(1)); QFAIL_SQL(model, isDirty(model.index(1, 1))); model.revertAll(); |