Skip to content

Commit

Permalink
Improve handling of SQLite savepoints (sqlitebrowser#878) (sqlitebrow…
Browse files Browse the repository at this point in the history
…ser#836)

Previously all savepoints were added to and deleted from
`savepointList`, so some savepoints could not be released, which lead to
warnings and errors, e.g. it was impossible to save database or to move
newly created row in 'Edit Table' window.
  • Loading branch information
prutz1311 committed Dec 5, 2016
1 parent 4ac9318 commit 86dd6af
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/sqlitedb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,19 @@ bool DBBrowserDB::setSavepoint(const QString& pointname)
bool DBBrowserDB::releaseSavepoint(const QString& pointname)
{
if(!isOpen() || savepointList.contains(pointname) == false)
return false;
// If there is no such savepoint in the list,
// we have already released it, so in this case
// the operation should be successfull
return true;

QString query = QString("RELEASE %1;").arg(pointname);
if(!executeSQL(query, false, false))
return false;
savepointList.removeAll(pointname);
// SQLite releases all savepoints that were created between
// creation of given savepoint and releasing of it,
// so we should too
int point_index = savepointList.lastIndexOf(pointname);
savepointList.erase(savepointList.begin()+point_index, savepointList.end());
emit dbChanged(getDirty());

return true;
Expand All @@ -305,7 +312,11 @@ bool DBBrowserDB::revertToSavepoint(const QString& pointname)
executeSQL(query, false, false);
query = QString("RELEASE %1;").arg(pointname);
executeSQL(query, false, false);
savepointList.removeAll(pointname);
// SQLite releases all savepoints that were created between
// creation of given savepoint and releasing of it,
// so we should too
int point_index = savepointList.lastIndexOf(pointname);
savepointList.erase(savepointList.begin()+point_index, savepointList.end());
emit dbChanged(getDirty());

return true;
Expand Down

0 comments on commit 86dd6af

Please sign in to comment.