예제 #1
0
파일: helpers.py 프로젝트: kostafey/jal
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)
예제 #2
0
 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
예제 #3
0
 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