mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
Extend the entire savepoint logic to allow multiple active savepoints
Allow multiple savepoints in DBBrowserDB, i.e. setRestorePoint() doesn't simply return if the DB is already set to dirty but creates an additional savepoint. Track the names of all savepoints which have not been either saved or reverted yet. Finally, and that's the whole point of this commit, change the savepoint logic of the EditTableDialog. We used to have a transaction started when opening a database which was only committed when the file was closed again. This way the EditFileDialog could savely create a savepoint when being opened and just release it when OK was clicked or revert to it when cancel was clicked. Getting rid of the transaction broke this logic. The dialog still worked but as the savepoint was released when the changes were applied all changes made via the dialog were immediately committed to the database. So clicking the revert button had no effect on those changes. This is at best an unexpected behaviour but could also be a problem when some changes are reverted while others aren't. So, having the option now of keeping multiple savepoints opened this problem can be fixed by just creating a new savepoint every time the dialog is opened, reverting to it when it is cancelled and _not_ releasing it when OK is clicked. I hope this works!
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QComboBox>
|
||||
#include <QDateTime>
|
||||
|
||||
#include "sqlitedb.h"
|
||||
|
||||
@@ -13,7 +14,8 @@ EditTableDialog::EditTableDialog(DBBrowserDB* db, const QString& tableName, QWid
|
||||
pdb(db),
|
||||
curTable(tableName),
|
||||
m_table(tableName),
|
||||
m_bNewTable(true)
|
||||
m_bNewTable(true),
|
||||
m_sRestorePointName(QString("edittable_%1_save_%2").arg(curTable).arg(QDateTime::currentMSecsSinceEpoch()))
|
||||
{
|
||||
// Create UI
|
||||
ui->setupUi(this);
|
||||
@@ -33,7 +35,7 @@ EditTableDialog::EditTableDialog(DBBrowserDB* db, const QString& tableName, QWid
|
||||
}
|
||||
|
||||
// And create a savepoint
|
||||
pdb->executeSQL(QString("SAVEPOINT edittable_%1_save;").arg(curTable), false);
|
||||
pdb->setRestorePoint(m_sRestorePointName);
|
||||
|
||||
// Update UI
|
||||
ui->editTableName->setText(curTable);
|
||||
@@ -106,7 +108,7 @@ void EditTableDialog::accept()
|
||||
{
|
||||
// Creation of new table
|
||||
// we commit immediatly so no need to setdirty
|
||||
if(!pdb->executeSQL(m_table.sql(), false))
|
||||
if(!pdb->executeSQL(m_table.sql()))
|
||||
{
|
||||
QMessageBox::warning(
|
||||
this,
|
||||
@@ -142,16 +144,13 @@ void EditTableDialog::accept()
|
||||
}
|
||||
}
|
||||
|
||||
// Release the savepoint
|
||||
pdb->executeSQL(QString("RELEASE SAVEPOINT edittable_%1_save;").arg(curTable), false);
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void EditTableDialog::reject()
|
||||
{
|
||||
// Then rollback to our savepoint
|
||||
pdb->executeSQL(QString("ROLLBACK TO SAVEPOINT edittable_%1_save;").arg(curTable), false);
|
||||
pdb->revert(m_sRestorePointName);
|
||||
|
||||
QDialog::reject();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user