Author: mtredinnick
Date: 2008-08-28 00:42:05 -0500 (Thu, 28 Aug 2008)
New Revision: 8646

Modified:
   django/trunk/django/db/backends/__init__.py
   django/trunk/django/db/backends/postgresql/operations.py
   django/trunk/django/db/models/fields/__init__.py
   django/trunk/tests/regressiontests/queries/models.py
Log:
Fixed #8597 -- Allow the use of strings containing underscores and percentage
signs in "iexact" queries on PostgreSQL again (this case was missed in [8536]).


Modified: django/trunk/django/db/backends/__init__.py
===================================================================
--- django/trunk/django/db/backends/__init__.py 2008-08-28 05:16:48 UTC (rev 
8645)
+++ django/trunk/django/db/backends/__init__.py 2008-08-28 05:42:05 UTC (rev 
8646)
@@ -301,6 +301,10 @@
         from django.utils.encoding import smart_unicode
         return smart_unicode(x).replace("\\", "\\\\").replace("%", 
"\%").replace("_", "\_")
 
+    # Same as prep_for_like_query(), but called for "iexact" matches, which
+    # need not necessarily be implemented using "LIKE" in the backend.
+    prep_for_iexact_query = prep_for_like_query
+
     def value_to_db_date(self, value):
         """
         Transform a date value to an object compatible with what is expected

Modified: django/trunk/django/db/backends/postgresql/operations.py
===================================================================
--- django/trunk/django/db/backends/postgresql/operations.py    2008-08-28 
05:16:48 UTC (rev 8645)
+++ django/trunk/django/db/backends/postgresql/operations.py    2008-08-28 
05:42:05 UTC (rev 8646)
@@ -142,3 +142,5 @@
     def savepoint_rollback_sql(self, sid):
         return "ROLLBACK TO SAVEPOINT %s" % sid
 
+    def prep_for_iexact_query(self, x):
+        return x

Modified: django/trunk/django/db/models/fields/__init__.py
===================================================================
--- django/trunk/django/db/models/fields/__init__.py    2008-08-28 05:16:48 UTC 
(rev 8645)
+++ django/trunk/django/db/models/fields/__init__.py    2008-08-28 05:42:05 UTC 
(rev 8646)
@@ -205,7 +205,7 @@
         elif lookup_type in ('contains', 'icontains'):
             return ["%%%s%%" % connection.ops.prep_for_like_query(value)]
         elif lookup_type == 'iexact':
-            return [connection.ops.prep_for_like_query(value)]
+            return [connection.ops.prep_for_iexact_query(value)]
         elif lookup_type in ('startswith', 'istartswith'):
             return ["%s%%" % connection.ops.prep_for_like_query(value)]
         elif lookup_type in ('endswith', 'iendswith'):

Modified: django/trunk/tests/regressiontests/queries/models.py
===================================================================
--- django/trunk/tests/regressiontests/queries/models.py        2008-08-28 
05:16:48 UTC (rev 8645)
+++ django/trunk/tests/regressiontests/queries/models.py        2008-08-28 
05:42:05 UTC (rev 8646)
@@ -901,6 +901,18 @@
 >>> qs = Item.objects.dates('created', 'month')
 >>> _ = pickle.loads(pickle.dumps(qs))
 
+Bug #8597: regression tests for case-insensitive comparisons
+>>> _ = Item.objects.create(name="a_b", created=datetime.datetime.now(), 
creator=a2, note=n1)
+>>> _ = Item.objects.create(name="x%y", created=datetime.datetime.now(), 
creator=a2, note=n1)
+>>> Item.objects.filter(name__iexact="A_b")
+[<Item: a_b>]
+>>> Item.objects.filter(name__iexact="x%Y")
+[<Item: x%y>]
+>>> Item.objects.filter(name__istartswith="A_b")
+[<Item: a_b>]
+>>> Item.objects.filter(name__iendswith="A_b")
+[<Item: a_b>]
+
 """}
 
 # In Python 2.3 and the Python 2.6 beta releases, exceptions raised in __len__


--~--~---------~--~----~------------~-------~--~----~
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