Changeset 5623
- Timestamp:
- 07/06/07 03:04:04 (1 year ago)
- Files:
-
- django/trunk/django/db/backends/mysql_old/base.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/db/backends/mysql_old/base.py
r5609 r5623 6 6 7 7 from django.db.backends import util 8 from django.utils.encoding import force_unicode 8 9 try: 9 10 import MySQLdb as Database … … 26 27 FIELD_TYPE.TIME: util.typecast_time, 27 28 FIELD_TYPE.DECIMAL: util.typecast_decimal, 29 FIELD_TYPE.STRING: force_unicode, 30 FIELD_TYPE.VAR_STRING: force_unicode, 31 # Note: We don't add a convertor for BLOB here. Doesn't seem to be required. 28 32 }) 29 33 … … 88 92 if not self._valid_connection(): 89 93 kwargs = { 94 # Note: use_unicode intentonally not set to work around some 95 # backwards-compat issues. We do it manually. 90 96 'user': settings.DATABASE_USER, 91 97 'db': settings.DATABASE_NAME, 92 98 'passwd': settings.DATABASE_PASSWORD, 93 99 'conv': django_conversions, 94 'use_unicode': True,95 100 } 96 101 if settings.DATABASE_HOST.startswith('/'): … … 103 108 self.connection = Database.connect(**kwargs) 104 109 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'") 110 if self.connection.get_server_info() >= '4.1' and not self.connection.character_set_name().startswith('utf8'): 111 if hasattr(self.connection, 'charset'): 112 # MySQLdb < 1.2.1 backwards-compat hacks. 113 conn = self.connection 114 cursor.execute("SET NAMES 'utf8'") 115 cursor.execute("SET CHARACTER SET 'utf8'") 116 to_str = lambda u, dummy=None, c=conn: c.literal(u.encode('utf-8')) 117 conn.converter[unicode] = to_str 118 else: 119 self.connection.set_character_set('utf8') 108 120 else: 109 121 cursor = self.connection.cursor()
