ui, db: fixed loading db type from saved configuration

If a db from disk was being used, and the user changed it to in-memory,
we were still loading the file from disk.
This commit is contained in:
Gustavo Iñiguez Goia 2021-04-12 17:59:14 +02:00
parent 03e97903d6
commit f288078c0b
2 changed files with 5 additions and 2 deletions

View file

@ -20,11 +20,13 @@ class Database:
self.db_file = Database.DB_IN_MEMORY
self.db_name = dbname
def initialize(self, dbfile):
def initialize(self, dbtype=DB_TYPE_MEMORY, dbfile=DB_IN_MEMORY):
if dbtype != Database.DB_TYPE_MEMORY:
self.db_file = dbfile
if self.db != None:
QSqlDatabase.removeDatabase(self.db_name)
self.close()
self.db_file = dbfile
self.db = QSqlDatabase.addDatabase("QSQLITE", self.db_name)
self.db.setDatabaseName(self.db_file)

View file

@ -38,6 +38,7 @@ class UIService(ui_pb2_grpc.UIServicer, QtWidgets.QGraphicsObject):
self._cfg = Config.init()
self._db = Database.instance()
self._db.initialize(
dbtype=self._cfg.getInt(self._cfg.DEFAULT_DB_TYPE_KEY),
dbfile=self._cfg.getSettings(self._cfg.DEFAULT_DB_FILE_KEY)
)
self._db_sqlite = self._db.get_db()