Issue #1511: failed deletion in the DB still deletes the rows from model

If the deletion of a record is rejected by the SQLite3, for example, due to
the presence of Foreign Key constraints, the corresponding rows must not
be deleted from the model.
This commit is contained in:
mgrojo
2018-08-24 17:50:44 +02:00
committed by Martin Kleusberg
parent ce032d95e6
commit 14106de34c

View File

@@ -507,21 +507,27 @@ bool SqliteTableModel::removeRows(int row, int count, const QModelIndex& parent)
return false;
}
beginRemoveRows(parent, row, row + count - 1);
QStringList rowids;
for(int i=count-1;i>=0;i--)
{
if(m_cache.count(row+i)) {
rowids.append(m_cache.at(row + i).at(0));
}
m_cache.erase(row + i);
m_currentRowCount--;
}
bool ok = m_db.deleteRecords(m_sTable, rowids, m_pseudoPk);
endRemoveRows();
if (ok) {
beginRemoveRows(parent, row, row + count - 1);
for(int i=count-1;i>=0;i--)
{
m_cache.erase(row + i);
m_currentRowCount--;
}
endRemoveRows();
}
return ok;
}