def __init__(self,*args,**kwargs): """Initializer function""" def _callback(conn_obj): wikipedia.output(u'Connection has been. Reconnecting in %i seconds (attempt %i/%i)' % (conn_obj, conn_obj.current_retry*conn_obj.retry_timeout, conn_obj.current_retry, conn_obj.max_retries)) newkwargs = { 'read_default_file': os.path.expanduser('~' + os.sep + '.my.cnf'), #read toolserver database information (please make sure the host is listed in the file) 'cursorclass': MySQLdb.cursors.DictCursor, 'retry_timeout': 5, 'max_retries': 4, 'callback': _callback, } newkwargs.update(kwargs) self.db = mysql_autoconnection.connect(*args, **newkwargs)
def connect_mysql(self, host): # A bug in MySQLdb 1.2.1_p will force you to set # all your connections to use_unicode = False. # Please upgrade to MySQLdb 1.2.2 or higher. if self.use_autoconn: database = mysql_autoconnection.connect( use_unicode = False, host = host, retry_timeout = self.mysql_retry_timeout, max_retries = self.mysql_max_retries, callback = self.mysql_callback, **self.mysql_kwargs) else: database = MySQLdb.connect(use_unicode = False, host = host, **self.mysql_kwargs) cursor = database.cursor() self.connections.append((database, cursor)) return database, cursor
def connect_database(): engine = config.CommonsDelinker['sql_engine'] kwargs = config.CommonsDelinker['sql_config'].copy() if engine == 'mysql': import mysql_autoconnection # This setting is required for MySQL kwargs['charset'] = 'utf8' # Work around for a bug in MySQLdb 1.2.1_p. This version will # set use_unicode for all connections to the value of the first # initialized connection. This bug is not relevant for MySQLdb # versions 1.2.2 and upwards. The connection character set must # be set to utf8 however, to prevent INSERTs to be converted to # the standard MySQL character set. kwargs['use_unicode'] = False kwargs['callback'] = wait_callback return mysql_autoconnection.connect(**kwargs) # TODO: Add support for sqlite3 raise RuntimeError('Unsupported database engine %s' % engine)
def __init__(self, *args, **kwargs): """Initializer function""" def _callback(conn_obj): wikipedia.output( u'Connection has been. Reconnecting in %i seconds (attempt %i/%i)' % (conn_obj, conn_obj.current_retry * conn_obj.retry_timeout, conn_obj.current_retry, conn_obj.max_retries)) newkwargs = { 'read_default_file': os.path.expanduser('~' + os.sep + '.my.cnf'), #read toolserver database information (please make sure the host is listed in the file) 'cursorclass': MySQLdb.cursors.DictCursor, 'retry_timeout': 5, 'max_retries': 4, 'callback': _callback, } newkwargs.update(kwargs) self.db = mysql_autoconnection.connect(*args, **newkwargs)