diff --git a/ui/opensnitch/database/__init__.py b/ui/opensnitch/database/__init__.py index 9e9446ea82..a2a35076b0 100644 --- a/ui/opensnitch/database/__init__.py +++ b/ui/opensnitch/database/__init__.py @@ -7,7 +7,7 @@ class Database: db = None __instance = None - DB_IN_MEMORY = ":memory:" + DB_IN_MEMORY = "file::memory:" DB_TYPE_MEMORY = 0 DB_TYPE_FILE = 1 DB_JRNL_WAL = False @@ -50,6 +50,8 @@ def initialize(self, dbtype=DB_TYPE_MEMORY, dbfile=DB_IN_MEMORY, dbjrnl_wal=DB_J self.db = QSqlDatabase.addDatabase("QSQLITE", self.db_name) self.db.setDatabaseName(self.db_file) + if dbtype == Database.DB_TYPE_MEMORY: + self.db.setConnectOptions("QSQLITE_OPEN_URI;QSQLITE_ENABLE_SHARED_CACHE") if not self.db.open(): print("\n ** Error opening DB: SQLite driver not loaded. DB name: %s\n" % self.db_file) print("\n Available drivers: ", QSqlDatabase.drivers()) @@ -103,6 +105,7 @@ def get_db_name(self): return self.db_name def _create_tables(self): + # https://www.sqlite.org/wal.html if self.db_file == Database.DB_IN_MEMORY: self.set_schema_version(self.DB_VERSION) # Disable journal (default) diff --git a/ui/opensnitch/dialogs/preferences.py b/ui/opensnitch/dialogs/preferences.py index 7f789b5d8b..5ed63c44f9 100644 --- a/ui/opensnitch/dialogs/preferences.py +++ b/ui/opensnitch/dialogs/preferences.py @@ -73,6 +73,7 @@ def __init__(self, parent=None, appicon=None): self.setupUi(self) self.setWindowIcon(appicon) + self.checkDBMaxDays.setEnabled(True) self.dbFileButton.setVisible(False) self.dbLabel.setVisible(False) self.dbType = None @@ -792,6 +793,7 @@ def _reset_status_message(self): self._hide_status_label() def _enable_db_cleaner_options(self, enable, db_max_days): + self.checkDBMaxDays.setChecked(enable) self.spinDBMaxDays.setEnabled(enable) self.spinDBPurgeInterval.setEnabled(enable) self.labelDBPurgeInterval.setEnabled(enable) @@ -842,8 +844,7 @@ def _cb_db_type_changed(self): isDBMem = self.comboDBType.currentIndex() == Database.DB_TYPE_MEMORY self.dbFileButton.setVisible(not isDBMem) self.dbLabel.setVisible(not isDBMem) - self.checkDBMaxDays.setEnabled(not isDBMem) - self.checkDBMaxDays.setChecked(not isDBMem) + self.checkDBMaxDays.setChecked(self._cfg.getBool(Config.DEFAULT_DB_PURGE_OLDEST)) self.checkDBJrnlWal.setEnabled(not isDBMem) self.checkDBJrnlWal.setChecked(False)