예제 #1
0
def getInsertedValue():
    sql = '''SELECT * 
             FROM message_log AS log 
             ORDER BY log.id desc
             LIMIT 1
           '''
    DataBaseUtilities.sendDataToFrontendFromDb(sqlStatement=sql)
예제 #2
0
def __handleIncomingMessage(ardCon, incomingByteArray):
    encryptionHandler = EncryptionHandler()
    decryptedMessage = encryptionHandler.decryptByteArray(incomingByteArray)
    if decryptedMessage != None:
        print("Decrpyted Message:", decryptedMessage)
        print("partnerId", ardCon.partnerId)
        DataBaseUtilities.insertMessageAndSender("mockup", decryptedMessage)
예제 #3
0
def createDataBase():
    sql = '''CREATE TABLE IF NOT EXISTS message_log(
        id INTEGER PRIMARY KEY AUTOINCREMENT ,
        sender TEXT NOT NULL,
        time TEXT NOT NULL,
        date TEXT NOT NULL,
        message TEXT NOT NULL
    ) '''
    DataBaseUtilities.insertIntoDb(sqlInsertStatement=sql)
예제 #4
0
def loadMoreEntrys(startID):
    sql = '''   SELECT * FROM (
                    SELECT * 
                    FROM message_log AS log
                    WHERE log.id < ?
                    ORDER BY id DESC
                    LIMIT 20)
                ORDER BY id ASC
          '''
    DataBaseUtilities.sendDataToFrontendFromDb(sql, startID)
예제 #5
0
def getInitialLoad():
    sql = ''' SELECT *
            FROM (
            SELECT * 
            FROM message_log AS log
            ORDER BY log.id DESC
            LIMIT 20 
            ) ORDER BY id ASC
        '''
    DataBaseUtilities.sendDataToFrontendFromDb(sqlStatement=sql)
예제 #6
0
def main():
    data = UniversalUtilities.read_in_stdin_json()
    if data[DictIndex.LOAD.value] == Action.INITIAL.value:
        createDataBase()
        createSettingsTable()
    elif data[DictIndex.LOAD.value] == Action.INSERT.value:
        message, sender = data[DictIndex.MESSAGE.value], data[DictIndex.SENDER.value]
        DataBaseUtilities.insertMessageAndSender(sender=sender, message=message)
        try:
             UniversalUtilities.connectAndSendTo_6200(message=message)
        except ConnectionError as e:
             UniversalUtilities.sendErrorMessageToFrontend(e)
예제 #7
0
 def _getKeyHandlerFromDb(self):
     '''Fetches the DiffieHellman JSON from the settings table and returns the decoded class'''
     statement = ''' SELECT value FROM settings WHERE key = 'keyHandlerJson' '''
     results = DataBaseUtilities.getValuesFromDb(statement)
     if len(results) == 0:
         return self._createAndSaveKeyHandler()
     return jsonpickle.decode(results[0]["value"])
예제 #8
0
def databaseState(lastMessageId, partnerID):
    sql = '''SELECT log.id
             FROM message_log AS log 
             ORDER BY log.id desc
             LIMIT 1
           '''
    newMessageId = DataBaseUtilities.getOneValueFromDb(
        sql)  # newest message-id in the database
    # calculate how many messages arrived since the last refresh of the frontend
    counterNewMessages = newMessageId['id'] - lastMessageId
    if counterNewMessages > 0:  # returns the messages, which arrived since the last refresh of the frontend
        sql = ''' SELECT *
              FROM (
                SELECT *
                FROM message_log AS log 
                ORDER BY log.id desc
                LIMIT ?
              ) ORDER BY id ASC
          '''
        newData = DataBaseUtilities.getValuesFromDb(sql, counterNewMessages)
        return True, newData
    else:
        return False, None
예제 #9
0
def createSettingsTable():
    sql = '''CREATE TABLE IF NOT EXISTS settings(
        key TEXT PRIMARY KEY,
        value TEXT NOT NULL
    ) '''
    DataBaseUtilities.insertIntoDb(sqlInsertStatement=sql)
예제 #10
0
 def _insertKeyHandlerIntoDb(self, keyHandler):
     '''Encodes a DiffieHellman class as JSON and saves it as a string into settings table'''
     keyHandlerJson = jsonpickle.encode(keyHandler)
     statement = '''INSERT OR REPLACE INTO settings (key, value) VALUES('keyHandlerJson', ?)'''
     DataBaseUtilities.insertIntoDb(statement, keyHandlerJson)
예제 #11
0
def sendDefaults():
    sql = '''SELECT * FROM settings'''
    DataBaseUtilities.sendDataToFrontendFromDb(sqlStatement=sql)
예제 #12
0
def insertThemeOnly(theme):
    sqlInsert = '''INSERT OR REPLACE INTO settings (key, value)
        VALUES('theme', ?)'''
    DataBaseUtilities.insertIntoDb(sqlInsert, str(theme))
예제 #13
0
def insertDefaults(uuid, theme):
    sqlInsert = '''INSERT OR REPLACE INTO settings (key, value)
        VALUES('uuid', ?), ('theme', ?)'''
    DataBaseUtilities.insertIntoDb(sqlInsert, str(uuid), str(theme))
예제 #14
0
def getThemeFromSettings():
    sql = '''SELECT value FROM settings WHERE key='theme' '''
    return DataBaseUtilities.getOneValueFromDb(sqlStatement=sql)