Esempio n. 1
0
 def wrapper(*args, **kwargs):
     connection = None
     try:
         connection = kwargs['conn'] = sqlite3.connect(SQLITE_DB_FILE)
         return function(*args, **kwargs)
     except (Exception, sqlite3.Error) as error:
         if connection:
             connection.close()
             LOGGER.error(error)
         raise error
Esempio n. 2
0
 def wrapper(*args, **kwargs):
     connection = None
     try:
         connection = kwargs['conn'] = psycopg2.connect(DSN)
         return function(*args, **kwargs)
     except (Exception, psycopg2.DatabaseError,
             psycopg2.errors.UndefinedTable) as error:
         if connection:
             connection.rollback()
             connection.close()
             LOGGER.error(error)
         raise error
Esempio n. 3
0
    def wrapper(*args, **kwargs):
        connection = None
        try:

            connection = kwargs['conn'] = MySQLConnection(
                host=DB_URL.hostname,
                user=DB_URL.username,
                port=DB_URL.port or 3306,
                password=DB_URL.password,
                database=DB_URL.path.strip('/'))
            return function(*args, **kwargs)
        except (Exception, errors.Error) as error:
            if connection:
                connection.rollback()
                connection.close()
                LOGGER.error(error)
            raise error