Skip to content

Commit c655727

Browse files
committed
Don't automatically commit all changes when editing a table column
Editing a table column in the Edit Table dialog accidentally committed all prior changes to the database, effectively clicking the 'Write Changes' button while working on the table. This is no problem if your working on a clean database, but is a problem if you have made other changes before. In the latter case you lose the ability to roll them back and you can't use the Cancel button in the Edit Table dialog anymore. See issue #1116.
1 parent 9b77055 commit c655727

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎src/sqlitedb.cpp‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,13 @@ bool DBBrowserDB::setPragma(const QString& pragma, const QString& value)
14141414
// Set the pragma value
14151415
QString sql = QString("PRAGMA %1 = \"%2\";").arg(pragma).arg(value);
14161416

1417-
releaseSavepoint();
1417+
// In general, we want to commit changes before running pragmas because most of them can't be rolled back and some of them
1418+
// even fail when run in a transaction. However, the defer_foreign_keys pragma has neither problem and we need it to be settable
1419+
// inside transactions (see the renameColumn() function where it is set and reset at some point and where we don't want the changes
1420+
// to be committed just because of this pragma).
1421+
if(pragma != "defer_foreign_keys")
1422+
releaseSavepoint();
1423+
14181424
bool res = executeSQL(sql, false, true); // PRAGMA statements are usually not transaction bound, so we can't revert
14191425
if( !res )
14201426
qWarning() << tr("Error setting pragma %1 to %2: %3").arg(pragma).arg(value).arg(lastErrorMessage);

0 commit comments

Comments
 (0)