mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
Use savepoint in Edit Index dialog
Create a save point when opening the Edit Index dialog. This allows us to revert back to the last version when pressing the Cancel button.
This commit is contained in:
@@ -11,7 +11,8 @@ EditIndexDialog::EditIndexDialog(DBBrowserDB& db, const QString& indexName, bool
|
||||
curIndex(indexName),
|
||||
index(indexName),
|
||||
newIndex(createIndex),
|
||||
ui(new Ui::EditIndexDialog)
|
||||
ui(new Ui::EditIndexDialog),
|
||||
m_sRestorePointName(pdb.generateSavepointName("editindex"))
|
||||
{
|
||||
// Create UI
|
||||
ui->setupUi(this);
|
||||
@@ -52,6 +53,9 @@ EditIndexDialog::EditIndexDialog(DBBrowserDB& db, const QString& indexName, bool
|
||||
} else {
|
||||
tableChanged(ui->comboTableName->currentText(), false);
|
||||
}
|
||||
|
||||
// Create a savepoint to revert back to
|
||||
pdb.setSavepoint(m_sRestorePointName);
|
||||
}
|
||||
|
||||
EditIndexDialog::~EditIndexDialog()
|
||||
@@ -211,7 +215,7 @@ void EditIndexDialog::accept()
|
||||
// When editing an index, delete the old one first
|
||||
if(!newIndex)
|
||||
{
|
||||
if(!pdb.executeSQL(QString("DROP INDEX %1;").arg(sqlb::escapeIdentifier(curIndex))))
|
||||
if(!pdb.executeSQL(QString("DROP INDEX IF EXISTS %1;").arg(sqlb::escapeIdentifier(curIndex))))
|
||||
{
|
||||
QMessageBox::warning(this, qApp->applicationName(), tr("Deleting the old index failed:\n%1").arg(pdb.lastError()));
|
||||
return;
|
||||
@@ -225,6 +229,14 @@ void EditIndexDialog::accept()
|
||||
QMessageBox::warning(this, QApplication::applicationName(), tr("Creating the index failed:\n%1").arg(pdb.lastError()));
|
||||
}
|
||||
|
||||
void EditIndexDialog::reject()
|
||||
{
|
||||
// Rollback to our savepoint
|
||||
pdb.revertToSavepoint(m_sRestorePointName);
|
||||
|
||||
QDialog::reject();
|
||||
}
|
||||
|
||||
void EditIndexDialog::updateSqlText()
|
||||
{
|
||||
ui->sqlTextEdit->setText(index.sql());
|
||||
|
||||
@@ -22,6 +22,8 @@ public:
|
||||
|
||||
private slots:
|
||||
void accept();
|
||||
void reject();
|
||||
|
||||
void tableChanged(const QString& new_table, bool initialLoad = false);
|
||||
void checkInput();
|
||||
void addToIndex(const QModelIndex& idx = QModelIndex());
|
||||
@@ -33,6 +35,7 @@ private:
|
||||
sqlb::Index index;
|
||||
bool newIndex;
|
||||
Ui::EditIndexDialog* ui;
|
||||
QString m_sRestorePointName;
|
||||
|
||||
void updateColumnLists();
|
||||
void updateSqlText();
|
||||
|
||||
Reference in New Issue
Block a user