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 driver_errors.DatabaseAlreadyExists(e.args[1])
             else:
                 raise driver_errors.GenericDriverError(e.args)
         except _mysql_exceptions.OperationalError as e:
             LOG.error("__query OperationalError: %s" % e)
             if e.args[0] == ER_DB_DROP_EXISTS:
                 raise driver_errors.DatabaseDoesNotExist(e.args[1])
             elif e.args[0] == ER_CANNOT_USER:
                 raise driver_errors.InvalidCredential(e.args[1])
             elif e.args[0] == ER_WRONG_STRING_LENGTH:
                 raise driver_errors.InvalidCredential(e.args[1])
             else:
                 raise driver_errors.GenericDriverError(e.args)
         except Exception as e:
             raise driver_errors.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 driver_errors.AuthenticationError(e.args[1])
         elif e.args[0] == ER_CAN_NOT_CONNECT:
             raise driver_errors.ConnectionError(e.args[1])
         elif e.args[0] == LOST_CONNECTION:
             raise driver_errors.ConnectionError(e.args[1])
         else:
             raise driver_errors.GenericDriverError(e.args)
     finally:
         try:
             if client:
                 LOG.debug(
                     'Disconnecting mysql databaseinfra %s',
                     self.databaseinfra
                 )
                 client.close()
         except Exception:
             LOG.warn(
                 'Error disconnecting from databaseinfra %s. Ignoring...',
                 self.databaseinfra,
                 exc_info=True
             )