Details
-
Bug
-
Resolution: Done
-
P2: Important
-
4.5.0
-
None
Description
QSqlTableModel cannot remove a row if a column was removed.
Here is the test to reproduce the issue:
diff --git a/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp b/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp index 0e7355e..80913f0 100644 --- a/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp +++ b/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp @@ -117,6 +117,8 @@ private slots: void sqlite_attachedDatabase_data() { generic_data("QSQLITE"); } void sqlite_attachedDatabase(); // For task 130799 + void removeColumnAndRow_data() { generic_data(); } + void removeColumnAndRow(); // task 256032 private: void generic_data(const QString& engine=QString()); }; @@ -927,5 +929,33 @@ void tst_QSqlTableModel::sqlite_attachedDatabase() QCOMPARE(model.data(model.index(0, 1), Qt::DisplayRole).toString(), QLatin1String("main")); } +void tst_QSqlTableModel::removeColumnAndRow() +{ + QFETCH(QString, dbName); + QSqlDatabase db = QSqlDatabase::database(dbName); + CHECK_DATABASE(db); + + QSqlTableModel model(0, db); + model.setTable(qTableName("test")); + model.setEditStrategy(QSqlTableModel::OnManualSubmit); + QVERIFY_SQL(model, select()); + QCOMPARE(model.rowCount(), 3); + QCOMPARE(model.columnCount(), 3); + + QVERIFY(model.removeColumn(0)); + QVERIFY(model.removeRow(0)); + QVERIFY(model.submitAll()); + QCOMPARE(model.rowCount(), 2); + QCOMPARE(model.columnCount(), 2); + + // check with another table because the model has been modified + // but not the sql table + QSqlTableModel model2(0, db); + model2.setTable(qTableName("test")); + QVERIFY_SQL(model2, select()); + QCOMPARE(model2.rowCount(), 2); + QCOMPARE(model2.columnCount(), 2); +} + QTEST_MAIN(tst_QSqlTableModel) #include "tst_qsqltablemodel.moc"
Attachments
Issue Links
- replaces
-
QTBUG-2140 Deletes and updates fail in a QSqlTableModel when not all the columns in the model are shown.
-
- Closed
-