Allow undoing also the last SQL execution performed in Execute SQL tabs

Some clean-up of the code, so there is only references to the undo
savepoint name in a single file.

See issue #3345.
This commit is contained in:
mgrojo
2023-09-06 20:06:59 +02:00
parent 864bfc1c89
commit f08ec63779
5 changed files with 12 additions and 5 deletions

View File

@@ -1490,7 +1490,7 @@ void MainWindow::fileRevert()
void MainWindow::undo()
{
if (db.isOpen()) {
db.revertToSavepoint("DB4S_UNDO");
db.revertToUndoSavepoint();
refreshTableBrowsers();
}
}

View File

@@ -1271,13 +1271,13 @@ You can drag SQL statements from the Schema column and drop them into the SQL ed
<string>&amp;Undo</string>
</property>
<property name="toolTip">
<string>Undo last change to a cell in the browser</string>
<string>Undo last change to the database</string>
</property>
<property name="statusTip">
<string>Undo last change to a cell in the browser</string>
<string>Undo last change to the database</string>
</property>
<property name="whatsThis">
<string>This action is used to undo the last change performed to a cell in the database browser. Redoing is not possible.</string>
<string>This action undoes the last change performed to the database in the Database Browser or in Execute SQL. Redoing is not possible.</string>
</property>
<property name="menuRole">
<enum>QAction::NoRole</enum>

View File

@@ -148,6 +148,9 @@ bool RunSql::executeNextStatement()
// We have to start a transaction before we create the prepared statement otherwise every executed
// statement will get committed after the prepared statement gets finalized
releaseDbAccess();
// Allow later undoing of this single execution with a non-unique savepoint.
db.setUndoSavepoint();
// And set the unique savepoint (if not already set) for the full current transaction.
db.setSavepoint();
acquireDbAccess();
savepoint_created = true;

View File

@@ -129,6 +129,10 @@ public:
bool releaseAllSavepoints();
bool revertAll();
// Set a non-unique savepoint for the general undoing mechanism (undoing only last write).
bool setUndoSavepoint() { return setSavepoint("UNDOPOINT", /* unique */ false); };
bool revertToUndoSavepoint() { return revertToSavepoint("UNDOPOINT"); };
bool dump(const QString& filename, const std::vector<std::string>& tablesToDump,
bool insertColNames, bool insertNew, bool keepOriginal, bool exportSchema, bool exportData, bool keepOldSchema) const;

View File

@@ -484,7 +484,7 @@ bool SqliteTableModel::setTypedData(const QModelIndex& index, bool isBlob, const
return false;
}
m_db.setSavepoint("DB4S_UNDO", false);
m_db.setUndoSavepoint();
if(index.isValid() && role == Qt::EditRole)
{