def __query(self, query_string, instance=None): with self.mysqldb(instance=instance) as client: try: LOG.debug("query_string: %s" % query_string) client.query(query_string) r = client.store_result() if r is not None: return r.fetch_row(maxrows=0, how=1) except _mysql_exceptions.ProgrammingError as e: LOG.error("__query ProgrammingError: %s" % e) if e.args[0] == ER_DB_CREATE_EXISTS: raise DatabaseAlreadyExists(e.args[1]) else: raise GenericDriverError(e.args) except _mysql_exceptions.OperationalError as e: LOG.error("__query OperationalError: %s" % e) if e.args[0] == ER_DB_DROP_EXISTS: raise DatabaseDoesNotExist(e.args[1]) elif e.args[0] == ER_CANNOT_USER: raise InvalidCredential(e.args[1]) elif e.args[0] == ER_WRONG_STRING_LENGTH: raise InvalidCredential(e.args[1]) else: raise GenericDriverError(e.args) except Exception as e: GenericDriverError(e.args)
def mysqldb(self, instance=None, database=None): client = None try: yield self.__mysql_client__(instance) except _mysql_exceptions.OperationalError as e: if e.args[0] == ER_ACCESS_DENIED_ERROR: raise AuthenticationError(e.args[1]) elif e.args[0] == ER_CAN_NOT_CONNECT: raise ConnectionError(e.args[1]) elif e.args[0] == LOST_CONNECTION: raise ConnectionError(e.args[1]) else: raise GenericDriverError(e.args) finally: try: if client: LOG.debug( 'Disconnecting mysql databaseinfra %s', self.databaseinfra) client.close() except: LOG.warn('Error disconnecting from databaseinfra %s. Ignoring...', self.databaseinfra, exc_info=True)