diff -r d7d4f0dccb5e django/contrib/sessions/backends/db.py
a
|
b
|
from django.contrib.sessions.models impo
|
2 | 2 | from django.contrib.sessions.models import Session |
3 | 3 | from django.contrib.sessions.backends.base import SessionBase |
4 | 4 | from django.core.exceptions import SuspiciousOperation |
| 5 | from django.db import connection |
5 | 6 | import datetime |
6 | 7 | |
7 | 8 | class SessionStore(SessionBase): |
… |
… |
class SessionStore(SessionBase):
|
13 | 14 | |
14 | 15 | def load(self): |
15 | 16 | try: |
| 17 | datetime_now = datetime.datetime.now() |
| 18 | if connection.features.supports_usecs and hasattr(datetime_now, 'microsecond'): |
| 19 | datetime_now = datetime_now.replace(microsecond=0) |
16 | 20 | s = Session.objects.get( |
17 | 21 | session_key = self.session_key, |
18 | | expire_date__gt=datetime.datetime.now() |
| 22 | expire_date__gt=datetime_now |
19 | 23 | ) |
20 | 24 | return self.decode(s.session_data) |
21 | 25 | except (Session.DoesNotExist, SuspiciousOperation): |
diff -r d7d4f0dccb5e django/db/backends/__init__.py
a
|
b
|
class BaseDatabaseFeatures(object):
|
52 | 52 | uses_custom_query_class = False |
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): |
57 | 61 | """ |
… |
… |
class BaseDatabaseOperations(object):
|
266 | 270 | tablespaces. |
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 | |
| 278 | return smart_unicode(x).replace("\\", "\\\\").replace("%", "\%").replace("_", "\_") |
diff -r d7d4f0dccb5e django/db/backends/mysql/base.py
a
|
b
|
class DatabaseFeatures(BaseDatabaseFeatu
|
64 | 64 | inline_fk_references = False |
65 | 65 | empty_fetchmany_value = () |
66 | 66 | update_can_self_select = False |
| 67 | supports_usecs = False |
67 | 68 | |
68 | 69 | class DatabaseOperations(BaseDatabaseOperations): |
69 | 70 | def date_extract_sql(self, lookup_type, field_name): |
diff -r d7d4f0dccb5e django/db/backends/mysql_old/base.py
a
|
b
|
class DatabaseFeatures(BaseDatabaseFeatu
|
68 | 68 | inline_fk_references = False |
69 | 69 | empty_fetchmany_value = () |
70 | 70 | update_can_self_select = False |
| 71 | supports_usecs = False |
71 | 72 | |
72 | 73 | class DatabaseOperations(BaseDatabaseOperations): |
73 | 74 | def date_extract_sql(self, lookup_type, field_name): |
diff -r d7d4f0dccb5e django/db/backends/oracle/base.py
a
|
b
|
class DatabaseFeatures(BaseDatabaseFeatu
|
31 | 31 | supports_tablespaces = True |
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): |
36 | 39 | def autoinc_sql(self, table, column): |
diff -r d7d4f0dccb5e django/db/models/fields/__init__.py
a
|
b
|
except ImportError:
|
7 | 7 | except ImportError: |
8 | 8 | from django.utils import _decimal as decimal # for Python 2.3 |
9 | 9 | |
10 | | from django.db import get_creation_module |
| 10 | 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 |
13 | 13 | from django.dispatch import dispatcher |
… |
… |
HORIZONTAL, VERTICAL = 1, 2
|
32 | 32 | # The values to use for "blank" in SelectFields. Will be appended to the start of most "choices" lists. |
33 | 33 | BLANK_CHOICE_DASH = [("", "---------")] |
34 | 34 | BLANK_CHOICE_NONE = [("", "None")] |
35 | | |
36 | | # prepares a value for use in a LIKE query |
37 | | prep_for_like_query = lambda x: smart_unicode(x).replace("\\", "\\\\").replace("%", "\%").replace("_", "\_") |
38 | 35 | |
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 '') |
… |
… |
class Field(object):
|
97 | 94 | self.blank, self.null = blank, null |
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 |
103 | 100 | self.editable = editable |
… |
… |
class Field(object):
|
235 | 232 | elif lookup_type in ('range', 'in'): |
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 [] |
247 | 244 | elif lookup_type == 'year': |
… |
… |
class Field(object):
|
252 | 249 | if settings.DATABASE_ENGINE == 'sqlite3': |
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' |
260 | 260 | second = '%s-12-31 23:59:59.999999' |
… |
… |
class Field(object):
|
271 | 271 | if callable(self.default): |
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 "" |
277 | 277 | |
… |
… |
class DateTimeField(DateField):
|
629 | 629 | if value is not None: |
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) |
635 | 635 | return Field.get_db_prep_save(self, value) |
… |
… |
class FilePathField(Field):
|
863 | 863 | self.path, self.match, self.recursive = path, match, recursive |
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 = { |
869 | 869 | 'path': self.path, |
… |
… |
class TimeField(Field):
|
1071 | 1071 | return "TimeField" |
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): |
1077 | 1077 | if isinstance(value, datetime.time): |
… |
… |
class TimeField(Field):
|
1098 | 1098 | if value is not None: |
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): |
1106 | 1106 | value = datetime.datetime(1900, 1, 1, value.hour, value.minute, |