mirror of https://github.com/django/django.git
Fixed #7302: Corrected quoting of columns in extra_group_by. Thanks to Ivan Sagalaev for the patch and initial test.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8794 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
823263429f
commit
f55b834c2f
|
@ -629,7 +629,7 @@ class Query(object):
|
|||
result.append('%s %s' % (elt, order))
|
||||
else:
|
||||
col, order = get_order_dir(field, asc)
|
||||
elt = qn(col)
|
||||
elt = qn2(col)
|
||||
if distinct and elt not in select_aliases:
|
||||
ordering_aliases.append(elt)
|
||||
result.append('%s %s' % (elt, order))
|
||||
|
|
|
@ -77,4 +77,13 @@ __test__ = {'API_TESTS':"""
|
|||
# take the first two).
|
||||
>>> Article.objects.all().reverse()[:2]
|
||||
[<Article: Article 1>, <Article: Article 3>]
|
||||
|
||||
# Ordering can be based on fields included from an 'extra' clause
|
||||
>>> Article.objects.extra(select={'foo': 'pub_date'}, order_by=['foo', 'headline'])
|
||||
[<Article: Article 1>, <Article: Article 2>, <Article: Article 3>, <Article: Article 4>]
|
||||
|
||||
# If the extra clause uses an SQL keyword for a name, it will be protected by quoting.
|
||||
>>> Article.objects.extra(select={'order': 'pub_date'}, order_by=['order', 'headline'])
|
||||
[<Article: Article 1>, <Article: Article 2>, <Article: Article 3>, <Article: Article 4>]
|
||||
|
||||
"""}
|
||||
|
|
|
@ -220,6 +220,13 @@ class Join(models.Model):
|
|||
a = models.ForeignKey(LeafA)
|
||||
b = models.ForeignKey(LeafB)
|
||||
|
||||
class ReservedName(models.Model):
|
||||
name = models.CharField(max_length=20)
|
||||
order = models.IntegerField()
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
__test__ = {'API_TESTS':"""
|
||||
>>> t1 = Tag.objects.create(name='t1')
|
||||
>>> t2 = Tag.objects.create(name='t2', parent=t1)
|
||||
|
@ -919,6 +926,15 @@ Bug #8597: regression tests for case-insensitive comparisons
|
|||
>>> Item.objects.filter(name__iendswith="A_b")
|
||||
[<Item: a_b>]
|
||||
|
||||
Bug #7302: reserved names are appropriately escaped
|
||||
>>> _ = ReservedName.objects.create(name='a',order=42)
|
||||
>>> _ = ReservedName.objects.create(name='b',order=37)
|
||||
>>> ReservedName.objects.all().order_by('order')
|
||||
[<ReservedName: b>, <ReservedName: a>]
|
||||
|
||||
>>> ReservedName.objects.extra(select={'stuff':'name'}, order_by=('order','stuff'))
|
||||
[<ReservedName: b>, <ReservedName: a>]
|
||||
|
||||
"""}
|
||||
|
||||
# In Python 2.3 and the Python 2.6 beta releases, exceptions raised in __len__
|
||||
|
|
Loading…
Reference in New Issue