Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-4199

QSqlTableModel cannot remove a row if a column was removed

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 4.6.0
    • 4.5.0
    • SQL Support
    • 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

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              wallison Warwick Allison (closed Nokia identity) (Inactive)
              poulain Benjamin Poulain (closed Nokia identity) (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes