PDA

View Full Version : Model/View programming support for database locks!



graciano
11th December 2013, 21:52
Hi
When i use Model/View programming, is there a way to lock a register in the database when it is being edited on the view?
I tested with two instances of the same program, accessing the same database. On the first, while editing a row, i remove it in the other. Then i loose consistance until i update the model.
And what about transactions! Does it support?

ChrisW67
12th December 2013, 03:11
When i use Model/View programming, is there a way to lock a register in the database when it is being edited on the view?
No. Lock on read is general a bad thing with a view that might sit open forever.

And what about transactions! Does it support?
QSqlTableModel does not explicitly create a transaction itself.

The model inserts/updates/delete will be part of a database transaction if you create one with QSqlDatabase::transaction() on the database connection. You then call QSqlDatabase::commit() or rollback() as required. This mechanism would work best with OnManualSubmit where you start the transaction, call QSqlTableModel::submitAll(), and commit() or rollback() based on the success of submitAll(). Read the note on SqlTableModel::submitAll() about failures.