I have following idea: user can edit database and when he will press exit from database he will be asked if he want to save edited database or if he edited something and then turned it back he wont be asked.
I think i should compare created database and database after editing when user press exit, but don’t know how.
This is my code for creating database
model = new QSqlRelationalTableModel(this, *db);
model->setTable("cv");
model->setFilter("cv_id = "+currentCV+"");
model->removeColumns(0,1);
model->select();
ui->tableView->show();
ui->tableView->setModel(model);
2
Answers
You have 2 options.
Create event triggers in the database. Event triggers work when users change database table structures or create tables or change columns. Thus, these triggers work when the user executes any DDL commands. (change table, add column, create index, drop table, etc.) You can insert these commands into your log tables using event triggers.
Your database structures (all tables, columns, indexes, etc.) are stored in
information_shema
. You can select the data of these tables and save it somewhere and then compare it with the data that has changed.Take in mind that no change to database is performed before you’re submitting the user changes. By default, sumbit is performed when changes occur, and this does not help you. But, you can set
At this point, changes are persisted only when the method
model.submitAll()
is called.All you have to do, at this point, is exploiting
dataChanged
signal of your model and use a flag variable to check if changes have been operated:Now you can adjust the logic of the code to serve your specific purpose