#1121 closed defect (fixed)
Wrong default-character-set in MySQL 4.1x/5.x (win32)
Reported by: | 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)
Change History (6)
by , 19 years ago
comment:2 by , 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 , 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:5 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
correctly formated code