Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #10071 -- Changed some internal database data representations.

We now pass numbers used in data queries as actualy numbers (integers) to the
database backends, rather than string forms. This is easier for some of the
less flexible backeds.

Based on a patch from Leo Soto and Ramiro Morales.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10530 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a584a6b40f8f685f5809eb77de2c7be0b150aeda 1 parent 1aa0d1b
Malcolm Tredinnick authored April 12, 2009
5  django/db/backends/postgresql/operations.py
@@ -27,9 +27,8 @@ def _get_postgres_version(self):
27 27
     def date_extract_sql(self, lookup_type, field_name):
28 28
         # http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT
29 29
         if lookup_type == 'week_day':
30  
-            # Using EXTRACT(), PostgreSQL days are indexed as Sunday=0, Saturday=6.
31  
-            # If we instead us TO_CHAR, they're indexed with Sunday=1, Saturday=7
32  
-            return "TO_CHAR(%s, 'D')" % field_name
  30
+            # For consistency across backends, we return Sunday=1, Saturday=7.
  31
+            return "EXTRACT('dow' FROM %s) + 1" % field_name
33 32
         else:
34 33
             return "EXTRACT('%s' FROM %s)" % (lookup_type, field_name)
35 34
 
4  django/db/backends/sqlite3/base.py
@@ -211,9 +211,9 @@ def _sqlite_extract(lookup_type, dt):
211 211
     except (ValueError, TypeError):
212 212
         return None
213 213
     if lookup_type == 'week_day':
214  
-        return unicode((dt.isoweekday() % 7) + 1)
  214
+        return (dt.isoweekday() % 7) + 1
215 215
     else:
216  
-        return unicode(getattr(dt, lookup_type))
  216
+        return getattr(dt, lookup_type)
217 217
 
218 218
 def _sqlite_date_trunc(lookup_type, dt):
219 219
     try:
6  django/db/models/fields/__init__.py
@@ -500,10 +500,10 @@ def contribute_to_class(self, cls, name):
500 500
                 curry(cls._get_next_or_previous_by_FIELD, field=self, is_next=False))
501 501
 
502 502
     def get_db_prep_lookup(self, lookup_type, value):
503  
-        # For "__month", "__day", and "__week_day" lookups, convert the value 
504  
-        # to a string so the database backend always sees a consistent type.
  503
+        # For "__month", "__day", and "__week_day" lookups, convert the value
  504
+        # to an int so the database backend always sees a consistent type.
505 505
         if lookup_type in ('month', 'day', 'week_day'):
506  
-            return [force_unicode(value)]
  506
+            return [int(value)]
507 507
         return super(DateField, self).get_db_prep_lookup(lookup_type, value)
508 508
 
509 509
     def get_db_prep_value(self, value):

0 notes on commit a584a6b

Please sign in to comment.
Something went wrong with that request. Please try again.