Ticket #4770: mysql_old.diff

File mysql_old.diff, 1.9 KB (added by mtredinnick, 8 years ago)

Broken patch that might act as inspiration.

  • db/backends/mysql_old/base.py

     
    1414from MySQLdb.constants import FIELD_TYPE
    1515import types
    1616import re
     17import weakref
    1718
    1819DatabaseError = Database.DatabaseError
    1920IntegrityError = Database.IntegrityError
     
    102103            kwargs.update(self.options)
    103104            self.connection = Database.connect(**kwargs)
    104105            cursor = self.connection.cursor()
    105             if self.connection.get_server_info() >= '4.1':
    106                 cursor.execute("SET NAMES 'utf8'")
    107                 cursor.execute("SET CHARACTER SET 'utf8'")
     106            if self.connection.get_server_info() >= '4.1' and not self.connection.character_set_name().startswith('utf8'):
     107                if hasattr(self.connection, 'charset'):
     108                    # MySQLdb prior to 1.2.1p2 backwards-compat hacks.
     109                    conn = self.connection
     110                    cursor.execute("SET NAMES 'utf8'")
     111                    cursor.execute("SET CHARACTER SET 'utf8'")
     112                    # XXX: At this point, conn.charset is still wrong, so we
     113                    # need to fix the converters. Writing to conn.charset gives
     114                    # the same errors as the following code, btw.
     115                    to_uni = lambda u, dummy=None, c=conn: c.literal(u.encode('utf-8'))
     116                    from_uni = lambda u: u.decode('utf-8')
     117                    conn.converter[unicode] = to_uni
     118                    django_conversions[FIELD_TYPE.STRING] = from_uni
     119                    django_conversions[FIELD_TYPE.VAR_STRING] = from_uni
     120                    # Note: we don't handle FIELD_TYPE.BLOB here.
     121                else:
     122                    self.connection.set_character_set('utf8')
    108123        else:
    109124            cursor = self.connection.cursor()
    110125        if settings.DEBUG:
Back to Top