def __init__( self, hostName, userName, passwd, dbName, maxQueueSize = 3 ): """ set MySQL connection parameters and try to connect """ global gInstancesCount gInstancesCount += 1 self._connected = False if 'logger' not in dir( self ): self.logger = gLogger.getSubLogger( 'MySQL' ) # let the derived class decide what to do with if is not 1 self._threadsafe = MySQLdb.thread_safe() self.logger.debug( 'thread_safe = %s' % self._threadsafe ) _checkQueueSize( maxQueueSize ) self.__hostName = str( hostName ) self.__userName = str( userName ) self.__passwd = str( passwd ) self.__dbName = str( dbName ) # Create the connection Queue to reuse connections self.__connectionQueue = Queue.Queue( maxQueueSize ) # Create the connection Semaphore to limit total number of open connection self.__connectionSemaphore = threading.Semaphore( maxQueueSize ) self.__initialized = True self._connect()
def __init__(self): if has_mysqldb: self._mysql_version = \ 'server: (not-connected), client: "%s", thread-safe: %s' % \ (MySQLdb.get_client_info(), MySQLdb.thread_safe()) else: self._mysql_version = None self.error = None
def get_connection(self, path, log=None, user=None, password=None, host=None, port=None, params={}): cnx = MySQLConnection(path, log, user, password, host, port, params) if not self.required: self._mysql_version = \ 'server: "%s", client: "%s", thread-safe: %s' \ % (cnx.cnx.get_server_info(), MySQLdb.get_client_info(), MySQLdb.thread_safe()) self.required = True return cnx
def get_connection(self, path, log=None, user=None, password=None, host=None, port=None, params={}): cnx = MySQLConnection(path, log, user, password, host, port, params) if not self._version: self._version = get_pkginfo(MySQLdb).get("version", MySQLdb.__version__) mysql_info = 'server: "%s", client: "%s", thread-safe: %s' % ( cnx.cnx.get_server_info(), MySQLdb.get_client_info(), MySQLdb.thread_safe(), ) self.env.systeminfo.extend([("MySQL", mysql_info), ("MySQLdb", self._version)]) self.required = True return cnx
def get_connection(self, path, log=None, user=None, password=None, host=None, port=None, params={}): cnx = MySQLConnection(path, log, user, password, host, port, params) if not self._version: self._version = get_pkginfo(MySQLdb).get('version', MySQLdb.__version__) mysql_info = 'server: "%s", client: "%s", thread-safe: %s' % \ (cnx.cnx.get_server_info(), MySQLdb.get_client_info(), MySQLdb.thread_safe()) self.env.systeminfo.extend([('MySQL', mysql_info), ('MySQLdb', self._version)]) self.required = True return cnx