Edgewall Software

Ticket #986: mysql_charset_patch.diff

File mysql_charset_patch.diff, 1.5 KB (added by Jim Nanney <jnanney@…>, 2 years ago)

diff for patching my changes above

  • trac/db/mysql_backend.py

     
    5656         
    5757        Some Versions of MySQL limit each index prefix to 500 bytes total, with 
    5858        a max of 255 bytes per column. 
     59 
     60        1000 bytes was the limit for mine, but for utf8 charset that means 4 bytes 
     61        per character.  So I brought it down to 250 
    5962        """ 
    6063        cols = [] 
    61         limit = 500 / len(columns) 
    62         if limit > 255: 
    63             limit = 255 
     64        limit = 250 / len(columns) 
     65        if limit > 250: 
     66            limit = 250 
    6467        for c in columns: 
    6568            name = '`%s`' % c 
    6669            table_col = filter((lambda x: x.name == c), table.columns) 
     
    8588        if len(table.key) > 0: 
    8689            coldefs.append('    PRIMARY KEY (%s)' % 
    8790                           self._collist(table, table.key)) 
    88         sql.append(',\n'.join(coldefs) + '\n)') 
     91        sql.append(',\n'.join(coldefs) + '\n) DEFAULT CHARSET=utf8') 
    8992        yield '\n'.join(sql) 
    9093 
    9194        for index in table.indices: 
     
    116119        vers = tuple([ int(n) for n in cnx.get_server_info().split('.')[:2] ]) 
    117120        if vers < (4, 1): 
    118121            raise TracError, 'MySQL servers older than 4.1 are not supported!' 
     122        cnx.query('SET CHARACTER SET UTF8'); 
     123        cnx.store_result() 
    119124        cnx.query('SET NAMES %s' % charset) 
    120125        cnx.store_result() 
    121126        cnx.charset = charset