Author: mtredinnick
Date: 2009-04-11 21:00:58 -0500 (Sat, 11 Apr 2009)
New Revision: 10530

Modified:
   django/trunk/django/db/backends/postgresql/operations.py
   django/trunk/django/db/backends/sqlite3/base.py
   django/trunk/django/db/models/fields/__init__.py
Log:
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.

Modified: django/trunk/django/db/backends/postgresql/operations.py
===================================================================
--- django/trunk/django/db/backends/postgresql/operations.py    2009-04-12 
02:00:36 UTC (rev 10529)
+++ django/trunk/django/db/backends/postgresql/operations.py    2009-04-12 
02:00:58 UTC (rev 10530)
@@ -27,9 +27,8 @@
     def date_extract_sql(self, lookup_type, field_name):
         # 
http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT
         if lookup_type == 'week_day':
-            # Using EXTRACT(), PostgreSQL days are indexed as Sunday=0, 
Saturday=6.
-            # If we instead us TO_CHAR, they're indexed with Sunday=1, 
Saturday=7
-            return "TO_CHAR(%s, 'D')" % field_name
+            # For consistency across backends, we return Sunday=1, Saturday=7.
+            return "EXTRACT('dow' FROM %s) + 1" % field_name
         else:
             return "EXTRACT('%s' FROM %s)" % (lookup_type, field_name)
 

Modified: django/trunk/django/db/backends/sqlite3/base.py
===================================================================
--- django/trunk/django/db/backends/sqlite3/base.py     2009-04-12 02:00:36 UTC 
(rev 10529)
+++ django/trunk/django/db/backends/sqlite3/base.py     2009-04-12 02:00:58 UTC 
(rev 10530)
@@ -211,9 +211,9 @@
     except (ValueError, TypeError):
         return None
     if lookup_type == 'week_day':
-        return unicode((dt.isoweekday() % 7) + 1)
+        return (dt.isoweekday() % 7) + 1
     else:
-        return unicode(getattr(dt, lookup_type))
+        return getattr(dt, lookup_type)
 
 def _sqlite_date_trunc(lookup_type, dt):
     try:

Modified: django/trunk/django/db/models/fields/__init__.py
===================================================================
--- django/trunk/django/db/models/fields/__init__.py    2009-04-12 02:00:36 UTC 
(rev 10529)
+++ django/trunk/django/db/models/fields/__init__.py    2009-04-12 02:00:58 UTC 
(rev 10530)
@@ -500,10 +500,10 @@
                 curry(cls._get_next_or_previous_by_FIELD, field=self, 
is_next=False))
 
     def get_db_prep_lookup(self, lookup_type, value):
-        # For "__month", "__day", and "__week_day" lookups, convert the value 
-        # to a string so the database backend always sees a consistent type.
+        # For "__month", "__day", and "__week_day" lookups, convert the value
+        # to an int so the database backend always sees a consistent type.
         if lookup_type in ('month', 'day', 'week_day'):
-            return [force_unicode(value)]
+            return [int(value)]
         return super(DateField, self).get_db_prep_lookup(lookup_type, value)
 
     def get_db_prep_value(self, value):


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to