Ticket #3370: mysql-utf8-complete.2.patch

File mysql-utf8-complete.2.patch, 1.3 KB (added by anton@…, 12 years ago)

Better patch that fix the issue and should work correctly with MySQL 4.0

  • django/db/models/base.py

     
    7777        return getattr(self, self._meta.pk.attname)
    7878
    7979    def __repr__(self):
    80         return '<%s: %s>' % (self.__class__.__name__, self)
     80        try:
     81            return '<%s: %s>' % (self.__class__.__name__, self)
     82        except UnicodeEncodeError:
     83            return '<%s: %s>' % (self.__class__.__name__, self.__str__().encode(settings.DEFAULT_CHARSET))
    8184
    8285    def __str__(self):
    8386        return '%s object' % self.__class__.__name__
  • django/db/backends/mysql/base.py

     
    9898                kwargs['port'] = int(settings.DATABASE_PORT)
    9999            kwargs.update(self.options)
    100100            self.connection = Database.connect(**kwargs)
     101            if self.connection.get_server_info() >= '4.1':
     102                self.connection.charset = 'utf8'
    101103            cursor = self.connection.cursor()
    102104            if self.connection.get_server_info() >= '4.1':
    103105                cursor.execute("SET NAMES 'utf8'")
Back to Top