Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#1121 closed defect (fixed)

Wrong default-character-set in MySQL 4.1x/5.x (win32)

Reported by: hipertracker@… Owned by: adrian
Component: Core (Other) Version: 0.90
Severity: major Keywords: mysql, encoding
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Django do not correctly display content from MySQL 4.1x, 5.x for win32. It always assume using latin1_swedish_ci
as default encoding instead of using settings (default-character-set=utf8) in my.ini.

Solution:

In Django-0.90-py2.4.egg\django\core\db\backends\mysql.py
change method cursor():

def cursor(self):

...

# OLD code:

# if DEBUG:
# return base.CursorDebugWrapper(MysqlDebugWrapper(self.connection.cursor()), self)
#return self.connection.cursor()


# NEW code:
if self.connection.get_server_info() >= '4.1':

cursor = self.connection.cursor()
cursor.execute("SET NAMES utf8")
if DEBUG:

return base.CursorDebugWrapper(MysqlDebugWrapper(cursor), self)

return cursor

Attachments (1)

patch.py (538 bytes) - added by hipertracker@… 10 years ago.
correctly formated code

Download all attachments as: .zip

Change History (6)

Changed 10 years ago by hipertracker@…

correctly formated code

comment:1 Changed 10 years ago by anonymous

agreed

doing this patch by hands each svn-update :-)

comment:2 Changed 10 years ago by hipertracker@…

The corrected code (cursor should be defined above if ...):

cursor = self.connection.cursor()
if self.connection.get_server_info() >= '4.1':
    cursor.execute("SET NAMES utf8")
    if DEBUG:
        return base.CursorDebugWrapper(MysqlDebugWrapper(cursor), self)
return cursor  

comment:3 Changed 10 years ago by anonymous

Shouldn't the debug conditional be outside the server version conditonal?

cursor = self.connection.cursor()
if self.connection.get_server_info() >= '4.1':
    cursor.execute("SET NAMES utf8")
if DEBUG:
    return base.CursorDebugWrapper(MysqlDebugWrapper(cursor), self)
return cursor

?

comment:4 Changed 9 years ago by hipertracker@…

Yes, of course.

comment:5 Changed 9 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

(In [1878]) Fixed #1121 -- Changed MySQL backend to use correct character set in MySQL 4.1x/5.x on Win32. Thanks, hipertracker@…

Note: See TracTickets for help on using tickets.
Back to Top