Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/sqlitedb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2080,6 +2080,7 @@ QString DBBrowserDB::getPragma(const std::string& pragma) const

bool DBBrowserDB::setPragma(const std::string& pragma, const QString& value)
{
bool res;
// Set the pragma value
std::string sql = "PRAGMA " + pragma + " = '" + value.toStdString() + "';";

Expand All @@ -2090,15 +2091,35 @@ bool DBBrowserDB::setPragma(const std::string& pragma, const QString& value)
if(pragma != "defer_foreign_keys")
releaseSavepoint();

bool res = executeSQL(sql, false, true); // PRAGMA statements are usually not transaction bound, so we can't revert
bool backToWal = false;
if (pragma == "page_size")
{
QString journal_mode = getPragma("journal_mode");
if (journal_mode.toLower() == "wal") // change page_size won't work in WAL
{
backToWal = true;
res = executeSQL("PRAGMA journal_mode = DELETE;", false, true);
if (!res)
{
qWarning() << tr("Error setting pragma journal_mode to DELETE for setting page_size: %1").arg(lastErrorMessage);
return false;
}
}
}
res = executeSQL(sql, false, true); // PRAGMA statements are usually not transaction bound, so we can't revert
if( !res )
qWarning() << tr("Error setting pragma %1 to %2: %3").arg(QString::fromStdString(pragma), value, lastErrorMessage);

// If this is the page_size or the auto_vacuum pragma being set, we need to execute the vacuum command right after the pragma statement or the new
// settings won't be saved.
if(res && (pragma == "page_size" || pragma == "auto_vacuum"))
res = executeSQL("VACUUM;", false, true);

if (res && backToWal)
{
res = executeSQL("PRAGMA journal_mode = WAL;", false, true);
if (!res)
qWarning() << tr("Error setting pragma journal_mode back to WAL: %1").arg(lastErrorMessage);
}
return res;
}

Expand Down