Ticket #9596: dj_date_lookup_b.patch

File dj_date_lookup_b.patch, 6.6 KB (added by Scott <django@…>, 13 years ago)

patch b

Line 
1diff -rcB django.orig/db/backends/__init__.py django/db/backends/__init__.py
2*** django.orig/db/backends/__init__.py 2008-08-31 21:49:03.000000000 -0300
3--- django/db/backends/__init__.py      2008-11-13 11:37:13.000000000 -0300
4***************
5*** 92,99 ****
6 
7      def date_extract_sql(self, lookup_type, field_name):
8          """
9!         Given a lookup_type of 'year', 'month' or 'day', returns the SQL that
10!         extracts a value from the given date field field_name.
11          """
12          raise NotImplementedError()
13 
14--- 92,99 ----
15 
16      def date_extract_sql(self, lookup_type, field_name):
17          """
18!         Given a lookup_type of 'year', 'month', 'day' or 'date' returns
19!         the SQL that extracts a value from the given date field field_name.
20          """
21          raise NotImplementedError()
22 
23Only in django/db/backends/mysql: .base.py.swp
24diff -rcB django.orig/db/backends/mysql/base.py django/db/backends/mysql/base.py
25*** django.orig/db/backends/mysql/base.py       2008-09-01 14:48:39.000000000 -0300
26--- django/db/backends/mysql/base.py    2008-11-13 12:28:18.000000000 -0300
27***************
28*** 115,120 ****
29--- 115,122 ----
30  class DatabaseOperations(BaseDatabaseOperations):
31      def date_extract_sql(self, lookup_type, field_name):
32          # http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html
33+         if lookup_type.lower() == 'date':
34+             return "DATE(%s)" % field_name
35          return "EXTRACT(%s FROM %s)" % (lookup_type.upper(), field_name)
36 
37      def date_trunc_sql(self, lookup_type, field_name):
38Only in django/db/backends/oracle: .base.py.swp
39diff -rcB django.orig/db/backends/oracle/base.py django/db/backends/oracle/base.py
40*** django.orig/db/backends/oracle/base.py      2008-09-01 16:58:41.000000000 -0300
41--- django/db/backends/oracle/base.py   2008-11-13 12:33:42.000000000 -0300
42***************
43*** 66,71 ****
44--- 66,74 ----
45          return sequence_sql, trigger_sql
46 
47      def date_extract_sql(self, lookup_type, field_name):
48+         # http://download-east.oracle.com/docs/cd/B10501_01/server.920/a96540/functions134a.htm#1009326
49+         if lookup_type.lower() == 'date':
50+             return "TO_CHAR(%S, 'YYYY-MM-DD')" % field_name
51          # http://download-east.oracle.com/docs/cd/B10501_01/server.920/a96540/functions42a.htm#1017163
52          return "EXTRACT(%s FROM %s)" % (lookup_type, field_name)
53 
54Only in django/db/backends/postgresql: .base.py.swp
55Only in django/db/backends/postgresql: .operations.py.swp
56diff -rcB django.orig/db/backends/postgresql/operations.py django/db/backends/postgresql/operations.py
57*** django.orig/db/backends/postgresql/operations.py    2008-08-28 02:42:05.000000000 -0300
58--- django/db/backends/postgresql/operations.py 2008-11-13 12:29:20.000000000 -0300
59***************
60*** 25,30 ****
61--- 25,33 ----
62      postgres_version = property(_get_postgres_version)
63 
64      def date_extract_sql(self, lookup_type, field_name):
65+         # http://www.postgresql.org/docs/8.3/static/typeconv-func.html#FTN.AEN17316
66+         if lookup_type.lower() == 'date':
67+             return 'CAST(%s AS DATE)' % field_name
68          # http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT
69          return "EXTRACT('%s' FROM %s)" % (lookup_type, field_name)
70 
71Only in django/db/backends/sqlite3: .base.py.swp
72diff -rcB django.orig/db/backends/sqlite3/base.py django/db/backends/sqlite3/base.py
73*** django.orig/db/backends/sqlite3/base.py     2008-08-23 15:01:16.000000000 -0300
74--- django/db/backends/sqlite3/base.py  2008-11-13 12:27:44.000000000 -0300
75***************
76*** 58,63 ****
77--- 58,66 ----
78 
79  class DatabaseOperations(BaseDatabaseOperations):
80      def date_extract_sql(self, lookup_type, field_name):
81+         # http://www.sqlite.org/lang_datefunc.html
82+         if lookup_type.lower() == 'date':
83+             return 'DATE(%s)' % field_name
84          # sqlite doesn't support extract, so we fake it with the user-defined
85          # function django_extract that's registered in connect().
86          return 'django_extract("%s", %s)' % (lookup_type.lower(), field_name)
87diff -rcB django.orig/db/models/fields/__init__.py django/db/models/fields/__init__.py
88*** django.orig/db/models/fields/__init__.py    2008-09-01 19:15:35.000000000 -0300
89--- django/db/models/fields/__init__.py 2008-11-13 02:41:03.000000000 -0300
90***************
91*** 212,217 ****
92--- 212,219 ----
93              return ["%%%s" % connection.ops.prep_for_like_query(value)]
94          elif lookup_type == 'isnull':
95              return []
96+         elif lookup_type == 'date':
97+             return [connection.ops.value_to_db_date(value)]
98          elif lookup_type == 'year':
99              try:
100                  value = int(value)
101Only in django/db/models/sql: .where.py.swp
102diff -rcB django.orig/db/models/sql/constants.py django/db/models/sql/constants.py
103*** django.orig/db/models/sql/constants.py      2008-09-01 23:16:41.000000000 -0300
104--- django/db/models/sql/constants.py   2008-11-13 02:41:03.000000000 -0300
105***************
106*** 4,10 ****
107  QUERY_TERMS = dict([(x, None) for x in (
108      'exact', 'iexact', 'contains', 'icontains', 'gt', 'gte', 'lt', 'lte', 'in',
109      'startswith', 'istartswith', 'endswith', 'iendswith', 'range', 'year',
110!     'month', 'day', 'isnull', 'search', 'regex', 'iregex',
111      )])
112 
113  # Size of each "chunk" for get_iterator calls.
114--- 4,10 ----
115  QUERY_TERMS = dict([(x, None) for x in (
116      'exact', 'iexact', 'contains', 'icontains', 'gt', 'gte', 'lt', 'lte', 'in',
117      'startswith', 'istartswith', 'endswith', 'iendswith', 'range', 'year',
118!     'month', 'day', 'isnull', 'search', 'regex', 'iregex', 'date'
119      )])
120 
121  # Size of each "chunk" for get_iterator calls.
122diff -rcB django.orig/db/models/sql/where.py django/db/models/sql/where.py
123*** django.orig/db/models/sql/where.py  2008-07-23 03:12:15.000000000 -0300
124--- django/db/models/sql/where.py       2008-11-13 12:25:14.000000000 -0300
125***************
126*** 162,168 ****
127                      params)
128          elif lookup_type in ('range', 'year'):
129              return ('%s BETWEEN %%s and %%s' % field_sql, params)
130!         elif lookup_type in ('month', 'day'):
131              return ('%s = %%s' % connection.ops.date_extract_sql(lookup_type,
132                      field_sql), params)
133          elif lookup_type == 'isnull':
134--- 163,169 ----
135                      params)
136          elif lookup_type in ('range', 'year'):
137              return ('%s BETWEEN %%s and %%s' % field_sql, params)
138!         elif lookup_type in ('month', 'day', 'date'):
139              return ('%s = %%s' % connection.ops.date_extract_sql(lookup_type,
140                      field_sql), params)
141          elif lookup_type == 'isnull':
Back to Top