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

revertAll() on a QSqlTableModel does not seem to revert changes if an sql error occured

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.0.0
    • 4.6.0
    • SQL Support
    • None
    • mingw- winXP
    • 83c9ebbd6692cde99ee692e6549c591100f12545 or before

    Description

      Removing any row in a tablemodel (with SQLite) will fail if I have
      before tried to remove a row referenced with an ON DELETE RESTRICT constraint.

      It seems like revertAll() does not clear the models "cache" and it tries
      to resubmit the failing remove. Even a select() afterwards does not help.

      QSqlQuery q;
      q.exec("PRAGMA foreign_keys=1");

      q.exec("CREATE TABLE tbl1 (id INTEGER PRIMARY KEY)");
      q.exec("CREATE TABLE tbl2 (fk INTEGER NOT NULL CONSTRAINT fk
      REFERENCES tbl1 (id) ON DELETE RESTRICT)");

      q.exec("INSERT INTO tbl1 (id) VALUES(1)");
      q.exec("INSERT INTO tbl1 (id) VALUES(2)");
      q.exec("INSERT INTO tbl2 (fk) VALUES(1)");

      QSqlTableModel m;
      m.setTable("tbl1");
      m.select();
      m.setEditStrategy(QSqlTableModel::OnManualSubmit);

      qDebug() << m.rowCount();
      qDebug() << m.removeRow(0);
      qDebug() << m.submitAll();
      qDebug() << m.lastError().text();

      m.revertAll();

      qDebug() << m.rowCount();
      qDebug() << m.removeRow(1);
      qDebug() << m.submitAll(); //fails. without rows 32-34 it wont fail
      qDebug() << m.lastError().text();

      Attachments

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

        Activity

          People

            mabrand Mark Brand
            jan Jan
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes