"QueryModel: geometry inconsistent with database" when deleting too many rows from querymodel
Added by John Davidson over 10 years ago
I have this code snippet for deleting from the database rows that are selected in a tableview/querymodel:
const Wt::WModelIndexSet selectedRows = tableView->selectedIndexes();
for (Wt::WModelIndexSet::iterator i = selectedRows.begin(); i != selectedRows.end(); ++i) {
index = *i;
queryModel->removeRow(index.row());
}
If the user highlights one or two rows, maybe around half a dozen (it's not the same every time, afaik) the code works OK.
However, if the user highlights too many rows - say, 20 - and presses the delete button, only some or none of the rows delete and the web session exits and reloads with this message:
[2014-May-20 18:18:33.355890] 856 [/ JmvMBN3UNZ0adB0N] [error] "Wt: error during event handling: QueryModel: geometry inconsistent with database"
[2014-May-20 18:18:33.366892] 856 [/ JmvMBN3UNZ0adB0N] [error] "Wt: fatal error: QueryModel: geometry inconsistent with database"
Web client has been de-registered
127.0.0.1 - - [2014-May-20 18:18:33.377893] "POST /?wtd=JmvMBN3UNZ0adB0N HTTP/1.1" 200 151WEB SESSION ENDED
Warning: Wt::Dbo::Session exiting with 14[2014-May-20 18:18:33.388894] 856 - [info] "WebRequest: took 183.019ms" dirty objects
[2014-May-20 18:18:33.455900] 856 [/ JmvMBN3UNZ0adB0N] [info] "Wt: session destroyed (#sessions = 2)"
What am I doing wrong?
thanks
John
Replies (4)
RE: "QueryModel: geometry inconsistent with database" when deleting too many rows from querymodel - Added by John Davidson over 10 years ago
I might add, I get the same problem if I delete rows from the database directly using a query rather than through the querymodel. If I delete a handful, no problem. If I delete a lot, the web session exits with the same messages. I hoped that using the querymodel would fix it, but no luck.
RE: "QueryModel: geometry inconsistent with database" when deleting too many rows from querymodel - Added by Koen Deforche over 10 years ago
Hey John,
It's like deleting elements from a vector while iterating through it: you need to mind the impact of each row on your indexes.
In this case you probably want to use a reverse_iterator instead of an iterator, since a WModelIndexSet is ordered.
Regards,
koen
RE: "QueryModel: geometry inconsistent with database" when deleting too many rows from querymodel - Added by Koen Deforche over 10 years ago
Hey,
For the second problem you need to refresh the query after you've modified the database: the query model will not automatically track database updates: use reload() for that.
Regards,
koen
RE: "QueryModel: geometry inconsistent with database" when deleting too many rows from querymodel - Added by John Davidson over 10 years ago
thanks Koen, that seems to have fixed it!