Django

Code

Changeset 3552

Show
Ignore:
Timestamp:
08/11/06 00:20:31 (2 years ago)
Author:
adrian
Message:

Fixed #2458 -- DB API now properly escapes backslashes, so you don't have to double-escape them. Thanks, tom@eggdrop.ch

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/AUTHORS

    r3549 r3552  
    126126    David Schein 
    127127    sopel 
     128    Thomas Steinacher <tom@eggdrop.ch> 
    128129    Radek Å varz <http://www.svarz.cz/translate/> 
    129130    Swaroop C H <http://www.swaroopch.info> 
  • django/trunk/django/db/models/fields/__init__.py

    r3508 r3552  
    2121 
    2222# prepares a value for use in a LIKE query 
    23 prep_for_like_query = lambda x: str(x).replace("%", "\%").replace("_", "\_") 
     23prep_for_like_query = lambda x: str(x).replace("\\", "\\\\").replace("%", "\%").replace("_", "\_") 
    2424 
    2525# returns the <ul> class for a given radio_admin value 
  • django/trunk/tests/modeltests/lookup/models.py

    r3223 r3552  
    1616        return self.headline 
    1717 
    18 API_TESTS = """ 
     18API_TESTS = r""" 
    1919# Create a couple of Articles. 
    2020>>> from datetime import datetime 
     
    162162 
    163163# Underscores and percent signs have special meaning in the underlying 
    164 # database library, but Django handles the quoting of them automatically. 
     164# SQL code, but Django handles the quoting of them automatically. 
    165165>>> a8 = Article(headline='Article_ with underscore', pub_date=datetime(2005, 11, 20)) 
    166166>>> a8.save() 
     
    169169>>> Article.objects.filter(headline__startswith='Article_') 
    170170[<Article: Article_ with underscore>] 
     171 
    171172>>> a9 = Article(headline='Article% with percent sign', pub_date=datetime(2005, 11, 21)) 
    172173>>> a9.save() 
     
    183184>>> Article.objects.exclude(headline="Article 7") 
    184185[<Article: Article% with percent sign>, <Article: Article_ with underscore>, <Article: Article 5>, <Article: Article 6>, <Article: Article 4>, <Article: Article 2>, <Article: Article 3>, <Article: Article 1>] 
     186 
     187# Backslashes also have special meaning in the underlying SQL code, but Django 
     188# automatically quotes them appropriately. 
     189>>> a10 = Article(headline='Article with \\ backslash', pub_date=datetime(2005, 11, 22)) 
     190>>> a10.save() 
     191>>> Article.objects.filter(headline__contains='\\') 
     192[<Article: Article with \ backslash>] 
     193 
    185194"""