Changeset 9469
- Timestamp:
- 11/16/08 02:57:10 (2 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/releases/1.0.X/django/db/backends/mysql/base.py
r8802 r9469 30 30 from django.db.backends.mysql.introspection import DatabaseIntrospection 31 31 from django.db.backends.mysql.validation import DatabaseValidation 32 from django.utils.safestring import SafeString, SafeUnicode 32 33 33 34 # Raise exceptions for database warnings if DEBUG is on … … 40 41 IntegrityError = Database.IntegrityError 41 42 42 # MySQLdb-1.2.1 supports the Python boolean type, and only uses datetime 43 # module for time-related columns; older versions could have used mx.DateTime 44 # or strings if there were no datetime module. However, MySQLdb still returns 45 # TIME columns as timedelta -- they are more like timedelta in terms of actual 46 # behavior as they are signed and include days -- and Django expects time, so 47 # we still need to override that. 43 # MySQLdb-1.2.1 returns TIME columns as timedelta -- they are more like 44 # timedelta in terms of actual behavior as they are signed and include days -- 45 # and Django expects time, so we still need to override that. We also need to 46 # add special handling for SafeUnicode and SafeString as MySQLdb's type 47 # checking is too tight to catch those (see Django ticket #6052). 48 48 django_conversions = conversions.copy() 49 49 django_conversions.update({ … … 175 175 if value is None: 176 176 return None 177 177 178 178 # MySQL doesn't support tz-aware datetimes 179 179 if value.tzinfo is not None: … … 186 186 if value is None: 187 187 return None 188 188 189 189 # MySQL doesn't support tz-aware datetimes 190 190 if value.tzinfo is not None: 191 191 raise ValueError("MySQL backend does not support timezone-aware datetimes.") 192 192 193 193 # MySQL doesn't support microseconds 194 194 return unicode(value.replace(microsecond=0)) … … 261 261 kwargs.update(self.options) 262 262 self.connection = Database.connect(**kwargs) 263 self.connection.encoders[SafeUnicode] = self.connection.encoders[unicode] 264 self.connection.encoders[SafeString] = self.connection.encoders[str] 263 265 cursor = CursorWrapper(self.connection.cursor()) 264 266 return cursor django/branches/releases/1.0.X/tests/modeltests/field_defaults/models.py
r8532 r9469 1 # coding: utf-8 1 2 """ 2 3 32. Callable defaults … … 20 21 return self.headline 21 22 22 __test__ = {'API_TESTS': """23 __test__ = {'API_TESTS': u""" 23 24 >>> from datetime import datetime 24 25 … … 52 53 # make sure that SafeString/SafeUnicode fields work 53 54 >>> from django.utils.safestring import SafeUnicode, SafeString 54 >>> a.headline = SafeUnicode(u' SafeUnicode Headline')55 >>> a.headline = SafeUnicode(u'Iñtërnâtiônàlizætiøn1') 55 56 >>> a.save() 56 >>> a.headline = SafeString(u' SafeString Headline')57 >>> a.headline = SafeString(u'Iñtërnâtiônàlizætiøn1'.encode('utf-8')) 57 58 >>> a.save() 58 59 """}
