# Path: myDevices/utils/logger.py
# def exception(message):
#     if checkFlood(message):
#         return
#     LOGGER.exception(message)
# 
# def info(message):
#     # if checkFlood(message):
#     #     return
#     LOGGER.info(message)
# 
# def warn(message):
#     if checkFlood(message):
#         return
#     LOGGER.warn(message)
# 
# def error(message, *args, **kwargs):
#     if checkFlood(message):
#         return
#     LOGGER.error(message, *args, **kwargs)
# 
# def debug(message):
#     outerFrame = getouterframes(currentframe())[1][0]
#     (args, _, _, values) = getargvalues(outerFrame)
#     argsValue = ''
#     
#     for i in args:
#         if i is 'self':
#             continue
#         argsValue += "(%s=%s)" % (i, str(values[i]))
#     
#     stack = extract_stack()
#     (filename, line, procname, text) = stack[-2]
#     LOGGER.debug(str(filename) + ' ' + str(procname) + str(argsValue) + ':' + str(line) + '> '  + str(message))
# 
# def setDebug():
#     LOGGER.setLevel(DEBUG)
#     return
# 
# Path: myDevices/utils/singleton.py
# class Singleton(_Singleton('SingletonMeta', (object,), {})): pass


from sqlite3 import connect
from myDevices.utils.logger import exception, info, warn, error, debug, setDebug
from threading import RLock
from time import sleep
from myDevices.utils.singleton import Singleton
                    del actual_columns
                cursor.execute('CREATE TABLE IF NOT EXISTS ' + tablename + ' ('+ str(columns) +')')
                connection.commit()
                # sleep(5)
        except Exception as ex:
            error("Failed to CreateTable: " + tablename + " " + str(ex))
            return False
        return True
    def Insert(tablename, *values):
        if not cursor or not connection:
            return
        with mutex:
            statement = 'INSERT INTO ' + tablename + ' VALUES '
            if len(values) == 1:
                statement = statement + '(\'' + str(values[0]) + '\')'
            else:
                statement = statement + str(values)
            #print(statement)
            cursor.execute(statement)
            connection.commit()
            return cursor.lastrowid
    def Update(tablename, setClause, setValue, whereClause, whereValue):
        if not cursor or not connection:
            return False
        with mutex:
            try:
                statement = 'UPDATE ' + tablename + ' SET ' + setClause + ' WHERE ' + whereClause
                cursor.execute(statement, (setValue, whereValue))
                connection.commit()
            except Exception as ex:

# Path: myDevices/utils/logger.py
# def exception(message):
#     if checkFlood(message):
#         return
#     LOGGER.exception(message)
# 
# def info(message):
#     # if checkFlood(message):
#     #     return
#     LOGGER.info(message)
# 
# def warn(message):
#     if checkFlood(message):
#         return
#     LOGGER.warn(message)
# 
# def error(message, *args, **kwargs):
#     if checkFlood(message):
#         return
#     LOGGER.error(message, *args, **kwargs)
# 
# def debug(message):
#     outerFrame = getouterframes(currentframe())[1][0]
#     (args, _, _, values) = getargvalues(outerFrame)
#     argsValue = ''
#     
#     for i in args:
#         if i is 'self':
#             continue
#         argsValue += "(%s=%s)" % (i, str(values[i]))
#     
#     stack = extract_stack()
#     (filename, line, procname, text) = stack[-2]
#     LOGGER.debug(str(filename) + ' ' + str(procname) + str(argsValue) + ':' + str(line) + '> '  + str(message))
# 
# def setDebug():
#     LOGGER.setLevel(DEBUG)
#     return
# 
# Path: myDevices/utils/singleton.py
# class Singleton(_Singleton('SingletonMeta', (object,), {})): pass


# Path: myDevices/cloud/dbmanager.py
from sqlite3 import connect
from myDevices.utils.logger import exception, info, warn, error, debug, setDebug
from threading import RLock
from time import sleep
from myDevices.utils.singleton import Singleton

                    del actual_columns
                cursor.execute('CREATE TABLE IF NOT EXISTS ' + tablename + ' ('+ str(columns) +')')
                connection.commit()
                # sleep(5)
        except Exception as ex:
            error("Failed to CreateTable: " + tablename + " " + str(ex))
            return False
        return True
    def Insert(tablename, *values):
        if not cursor or not connection:
            return
        with mutex:
            statement = 'INSERT INTO ' + tablename + ' VALUES '
            if len(values) == 1:
                statement = statement + '(\'' + str(values[0]) + '\')'
            else:
                statement = statement + str(values)
            #print(statement)
            cursor.execute(statement)
            connection.commit()
            return cursor.lastrowid
    def Update(tablename, setClause, setValue, whereClause, whereValue):
        if not cursor or not connection:
            return False
        with mutex:
            try:
                statement = 'UPDATE ' + tablename + ' SET ' + setClause + ' WHERE ' + whereClause
                cursor.execute(statement, (setValue, whereValue))
                connection.commit()
            except Exception as ex:

                exception('DbManager::Update except ' + str(ex))