def init_and_check_db(db_path): db = QSqlDatabase.addDatabase("QSQLITE", Setup.DB_CONNECTION) if not db.isValid(): return LedgerInitError(LedgerInitError.DbDriverFailure) db.setDatabaseName(get_dbfilename(db_path)) db.setConnectOptions("QSQLITE_ENABLE_REGEXP=1") db.open() tables = db.tables(QSql.Tables) if not tables: db.close() connection_name = db.connectionName() init_db_from_sql(get_dbfilename(db_path), db_path + Setup.INIT_SCRIPT_PATH) QSqlDatabase.removeDatabase(connection_name) return LedgerInitError(LedgerInitError.EmptyDbInitialized) schema_version = JalSettings().getValue('SchemaVersion') if schema_version < Setup.TARGET_SCHEMA: db.close() return LedgerInitError(LedgerInitError.OutdatedDbSchema) elif schema_version > Setup.TARGET_SCHEMA: db.close() return LedgerInitError(LedgerInitError.NewerDbSchema) _ = executeSQL("PRAGMA foreign_keys = ON") db_triggers_enable() return LedgerInitError(LedgerInitError.DbInitSuccess)
def setLogs(self): isLogChanged = self.settings.value('logChanged') if isLogChanged == 1 or self.initialRun: self.db.open() self.projectModel.setQuery( "select ID, Date, Time, LockedBy from allLogs order by id desc", self.db) self.db.close() QSqlDatabase.removeDatabase("QSQLITE") self.settings.setValue('logChanged', 0) self.initialRun = False
def setLogs(self): isLogChanged = self.settings.value('logChanged') if isLogChanged == 1 or self.initialRun: self.allLogsModel = QSqlQueryModel() dbAllLog = QSqlDatabase.addDatabase("QSQLITE") dbAllLog.setDatabaseName("caio.db") dbAllLog.open() self.allLogsModel.setQuery( "select * from allLogs order by id desc ", dbAllLog) dbAllLog.close() print(self.allLogsModel) self.settings.setValue('logChanged', 0) QSqlDatabase.removeDatabase("QSQLITE") self.initialRun = False