Changeset 7643
- Timestamp:
- 06/15/08 22:15:04 (5 months ago)
- Files:
-
- django/trunk/django/db/backends/__init__.py (modified) (2 diffs)
- django/trunk/django/db/backends/mysql/base.py (modified) (1 diff)
- django/trunk/django/db/backends/mysql_old/base.py (modified) (1 diff)
- django/trunk/django/db/backends/oracle/base.py (modified) (1 diff)
- django/trunk/django/db/models/fields/__init__.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/db/backends/__init__.py
r7624 r7643 53 53 empty_fetchmany_value = [] 54 54 update_can_self_select = True 55 supports_usecs = True 56 time_field_needs_date = False 57 interprets_empty_strings_as_nulls = False 58 date_field_supports_time_value = True 55 59 56 60 class BaseDatabaseOperations(object): … … 267 271 """ 268 272 return None 273 274 def prep_for_like_query(self, x): 275 """Prepares a value for use in a LIKE query.""" 276 from django.utils.encoding import smart_unicode 277 return smart_unicode(x).replace("\\", "\\\\").replace("%", "\%").replace("_", "\_") django/trunk/django/db/backends/mysql/base.py
r7496 r7643 65 65 empty_fetchmany_value = () 66 66 update_can_self_select = False 67 supports_usecs = False 67 68 68 69 class DatabaseOperations(BaseDatabaseOperations): django/trunk/django/db/backends/mysql_old/base.py
r7496 r7643 69 69 empty_fetchmany_value = () 70 70 update_can_self_select = False 71 supports_usecs = False 71 72 72 73 class DatabaseOperations(BaseDatabaseOperations): django/trunk/django/db/backends/oracle/base.py
r7477 r7643 32 32 uses_case_insensitive_names = True 33 33 uses_custom_query_class = True 34 time_field_needs_date = True 35 interprets_empty_strings_as_nulls = True 36 date_field_supports_time_value = False 34 37 35 38 class DatabaseOperations(BaseDatabaseOperations): django/trunk/django/db/models/fields/__init__.py
r7494 r7643 8 8 from django.utils import _decimal as decimal # for Python 2.3 9 9 10 from django.db import get_creation_module10 from django.db import connection, get_creation_module 11 11 from django.db.models import signals 12 12 from django.db.models.query_utils import QueryWrapper … … 34 34 BLANK_CHOICE_NONE = [("", "None")] 35 35 36 # prepares a value for use in a LIKE query37 prep_for_like_query = lambda x: smart_unicode(x).replace("\\", "\\\\").replace("%", "\%").replace("_", "\_")38 39 36 # returns the <ul> class for a given radio_admin value 40 37 get_ul_class = lambda x: 'radiolist%s' % ((x == HORIZONTAL) and ' inline' or '') … … 98 95 # Oracle treats the empty string ('') as null, so coerce the null 99 96 # option whenever '' is a possible value. 100 if self.empty_strings_allowed and settings.DATABASE_ENGINE == 'oracle':97 if self.empty_strings_allowed and connection.features.interprets_empty_strings_as_nulls: 101 98 self.null = True 102 99 self.core, self.rel, self.default = core, rel, default … … 236 233 return value 237 234 elif lookup_type in ('contains', 'icontains'): 238 return ["%%%s%%" % prep_for_like_query(value)]235 return ["%%%s%%" % connection.ops.prep_for_like_query(value)] 239 236 elif lookup_type == 'iexact': 240 return [ prep_for_like_query(value)]237 return [connection.ops.prep_for_like_query(value)] 241 238 elif lookup_type in ('startswith', 'istartswith'): 242 return ["%s%%" % prep_for_like_query(value)]239 return ["%s%%" % connection.ops.prep_for_like_query(value)] 243 240 elif lookup_type in ('endswith', 'iendswith'): 244 return ["%%%s" % prep_for_like_query(value)]241 return ["%%%s" % connection.ops.prep_for_like_query(value)] 245 242 elif lookup_type == 'isnull': 246 243 return [] … … 253 250 first = '%s-01-01' 254 251 second = '%s-12-31 23:59:59.999999' 255 elif settings.DATABASE_ENGINE == 'oracle'and self.get_internal_type() == 'DateField':252 elif not connection.features.date_field_supports_time_value and self.get_internal_type() == 'DateField': 256 253 first = '%s-01-01' 257 254 second = '%s-12-31' 255 elif not connection.features.supports_usecs: 256 first = '%s-01-01 00:00:00' 257 second = '%s-12-31 23:59:59.99' 258 258 else: 259 259 first = '%s-01-01 00:00:00' … … 272 272 return self.default() 273 273 return force_unicode(self.default, strings_only=True) 274 if not self.empty_strings_allowed or (self.null and settings.DATABASE_ENGINE != 'oracle'):274 if not self.empty_strings_allowed or (self.null and not connection.features.interprets_empty_strings_as_nulls): 275 275 return None 276 276 return "" … … 630 630 # MySQL will throw a warning if microseconds are given, because it 631 631 # doesn't support microseconds. 632 if settings.DATABASE_ENGINE == 'mysql'and hasattr(value, 'microsecond'):632 if not connection.features.supports_usecs and hasattr(value, 'microsecond'): 633 633 value = value.replace(microsecond=0) 634 634 value = smart_unicode(value) … … 864 864 kwargs['max_length'] = kwargs.get('max_length', 100) 865 865 Field.__init__(self, verbose_name, name, **kwargs) 866 866 867 867 def formfield(self, **kwargs): 868 868 defaults = { … … 1072 1072 1073 1073 def get_db_prep_lookup(self, lookup_type, value): 1074 if settings.DATABASE_ENGINE == 'oracle':1074 if connection.features.time_field_needs_date: 1075 1075 # Oracle requires a date in order to parse. 1076 1076 def prep(value): … … 1099 1099 # MySQL will throw a warning if microseconds are given, because it 1100 1100 # doesn't support microseconds. 1101 if settings.DATABASE_ENGINE == 'mysql'and hasattr(value, 'microsecond'):1101 if not connection.features.supports_usecs and hasattr(value, 'microsecond'): 1102 1102 value = value.replace(microsecond=0) 1103 if settings.DATABASE_ENGINE == 'oracle':1103 if connection.features.time_field_needs_date: 1104 1104 # cx_Oracle expects a datetime.datetime to persist into TIMESTAMP field. 1105 1105 if isinstance(value, datetime.time):
