Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#1121 closed defect (fixed)

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

Reported by: hipertracker@… Owned by: Adrian Holovaty
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: no UI/UX: no

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@… 19 years ago.
correctly formated code

Download all attachments as: .zip

Change History (6)

by hipertracker@…, 19 years ago

Attachment: patch.py added

correctly formated code

comment:1 by anonymous, 19 years ago

agreed

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

comment:2 by hipertracker@…, 19 years ago

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 by anonymous, 19 years ago

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 by hipertracker@…, 19 years ago

Yes, of course.

comment:5 by Adrian Holovaty, 19 years ago

Resolution: fixed
Status: newclosed

(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