Edgewall Software

Ticket #5120: mysql.cnf.hack.patch

File mysql.cnf.hack.patch, 1.9 KB (added by dekimsey@…, 12 months ago)

this is a patch to add parameter support to source:/trunk/trac/db/mysql_backend.py@6299

  • trac/db/mysql_backend.py

     
    148148 
    149149        if path.startswith('/'): 
    150150            path = path[1:] 
    151         if password == None: 
    152             password = '' 
    153         if port == None: 
    154             port = 3306 
    155151 
    156152        # python-mysqldb 1.2.1 added a 'charset' arg that is required for 
    157153        # unicode stuff.  We hack around that here for older versions; at 
    158154        # some point, this hack should be removed, and a strict requirement 
    159155        # on 1.2.1 made.  -dilinger 
     156         
     157        # the 'params' variable really should be passed to mysqldb 
     158        # this is a hack to add my.cnf support 
     159        change_charset = 0 
    160160        if (self._mysqldb_gt_or_eq((1, 2, 1))): 
    161             cnx = MySQLdb.connect(db=path, user=user, passwd=password, 
    162                                   host=host, port=port, charset='utf8') 
     161            params['charset'] = 'utf8' 
    163162        else: 
    164             cnx = MySQLdb.connect(db=path, user=user, passwd=password, 
    165                                   host=host, port=port, use_unicode=True) 
     163            change_charset = 1 
     164            params['use_unicode'] = True 
     165 
     166        # don't want to pass these if they are None, the library will complain. 
     167        if password != None: 
     168            params['passwd'] = password 
     169        if user != None: 
     170            params['user'] = user 
     171        if host != None: 
     172            params['host'] = host 
     173        if port != None: 
     174            params['port'] = port 
     175        if path != None: 
     176            params['db'] = path 
     177 
     178        # removes encoding? 
     179        strparams = dict([(str(x),params[x]) for x in params.keys()]) 
     180        cnx = MySQLdb.connect( **strparams ) 
     181         
     182        if change_charset: 
    166183            self._set_character_set(cnx, 'utf8') 
     184 
    167185        ConnectionWrapper.__init__(self, cnx) 
    168186        self._is_closed = False 
    169187