Django

Code

Changeset 8646

Show
Ignore:
Timestamp:
08/28/08 00:42:05 (3 months ago)
Author:
mtredinnick
Message:

Fixed #8597 -- Allow the use of strings containing underscores and percentage
signs in "iexact" queries on PostgreSQL again (this case was missed in [8536]).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/backends/__init__.py

    r8314 r8646  
    302302        return smart_unicode(x).replace("\\", "\\\\").replace("%", "\%").replace("_", "\_") 
    303303 
     304    # Same as prep_for_like_query(), but called for "iexact" matches, which 
     305    # need not necessarily be implemented using "LIKE" in the backend. 
     306    prep_for_iexact_query = prep_for_like_query 
     307 
    304308    def value_to_db_date(self, value): 
    305309        """ 
  • django/trunk/django/db/backends/postgresql/operations.py

    r8536 r8646  
    143143        return "ROLLBACK TO SAVEPOINT %s" % sid 
    144144 
     145    def prep_for_iexact_query(self, x): 
     146        return x 
  • django/trunk/django/db/models/fields/__init__.py

    r8616 r8646  
    206206            return ["%%%s%%" % connection.ops.prep_for_like_query(value)] 
    207207        elif lookup_type == 'iexact': 
    208             return [connection.ops.prep_for_like_query(value)] 
     208            return [connection.ops.prep_for_iexact_query(value)] 
    209209        elif lookup_type in ('startswith', 'istartswith'): 
    210210            return ["%s%%" % connection.ops.prep_for_like_query(value)] 
  • django/trunk/tests/regressiontests/queries/models.py

    r8570 r8646  
    902902>>> _ = pickle.loads(pickle.dumps(qs)) 
    903903 
     904Bug #8597: regression tests for case-insensitive comparisons 
     905>>> _ = Item.objects.create(name="a_b", created=datetime.datetime.now(), creator=a2, note=n1) 
     906>>> _ = Item.objects.create(name="x%y", created=datetime.datetime.now(), creator=a2, note=n1) 
     907>>> Item.objects.filter(name__iexact="A_b") 
     908[<Item: a_b>] 
     909>>> Item.objects.filter(name__iexact="x%Y") 
     910[<Item: x%y>] 
     911>>> Item.objects.filter(name__istartswith="A_b") 
     912[<Item: a_b>] 
     913>>> Item.objects.filter(name__iendswith="A_b") 
     914[<Item: a_b>] 
     915 
    904916"""} 
    905917