Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
4.6.0
-
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();