mirror of
https://github.com/django/django.git
synced 2025-07-05 10:19:20 +00:00
[soc2009/multidb] Made filter SQL generation lazy when we aren't filtering on a specific field, also added additional tests
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/multidb@10923 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
fbb6fda5f6
commit
91520ec364
@ -68,11 +68,8 @@ class WhereNode(tree.Node):
|
||||
super(WhereNode, self).add((obj, lookup_type, annotation, value),
|
||||
connector)
|
||||
return
|
||||
else:
|
||||
# TODO: Make this lazy just like the above code for constraints.
|
||||
params = Field().get_db_prep_lookup(lookup_type, value)
|
||||
|
||||
super(WhereNode, self).add((obj, lookup_type, annotation, params),
|
||||
super(WhereNode, self).add((obj, lookup_type, annotation, value),
|
||||
connector)
|
||||
|
||||
def as_sql(self, qn, connection):
|
||||
@ -149,7 +146,7 @@ class WhereNode(tree.Node):
|
||||
except EmptyShortCircuit:
|
||||
raise EmptyResultSet
|
||||
else:
|
||||
params = params_or_value
|
||||
params = Field().get_db_prep_lookup(lookup_type, params_or_value)
|
||||
if isinstance(lvalue, tuple):
|
||||
# A direct database column lookup.
|
||||
field_sql = self.sql_for_columns(lvalue, qn, connection)
|
||||
|
@ -2,6 +2,10 @@ from django.db import models
|
||||
|
||||
class Book(models.Model):
|
||||
title = models.CharField(max_length=100)
|
||||
published = models.DateField()
|
||||
|
||||
def __unicode__(self):
|
||||
return self.title
|
||||
|
||||
class Meta:
|
||||
ordering = ('title',)
|
||||
|
@ -1,3 +1,5 @@
|
||||
import datetime
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import connections
|
||||
from django.test import TestCase
|
||||
@ -18,13 +20,32 @@ class DatabaseSettingTestCase(TestCase):
|
||||
connections['default'].cursor()
|
||||
connections['__test_db'].cursor()
|
||||
|
||||
class ConnectionTestCase(TestCase):
|
||||
def test_queries(self):
|
||||
class QueryTestCase(TestCase):
|
||||
def test_basic_queries(self):
|
||||
for db in connections:
|
||||
Book.objects.using(db).create(title="Dive into Python")
|
||||
Book.objects.using(db).create(title="Dive into Python",
|
||||
published=datetime.date(2009, 5, 4))
|
||||
|
||||
for db in connections:
|
||||
books = Book.objects.all().using(db)
|
||||
self.assertEqual(books.count(), 1)
|
||||
self.assertEqual(len(books), 1)
|
||||
self.assertEqual(books[0].title, "Dive into Python")
|
||||
self.assertEqual(books[0].published, datetime.date(2009, 5, 4))
|
||||
|
||||
for db in connections:
|
||||
book = Book(title="Pro Django", published=datetime.date(2008, 12, 16))
|
||||
book.save(using=db)
|
||||
|
||||
for db in connections:
|
||||
books = Book.objects.all().using(db)
|
||||
self.assertEqual(books.count(), 2)
|
||||
self.assertEqual(len(books), 2)
|
||||
self.assertEqual(books[0].title, "Dive into Python")
|
||||
self.assertEqual(books[1].title, "Pro Django")
|
||||
|
||||
pro = Book.objects.using(db).get(published=datetime.date(2008, 12, 16))
|
||||
self.assertEqual(pro.title, "Pro Django")
|
||||
|
||||
dive = Book.objects.using(db).get(title__icontains="dive")
|
||||
self.assertEqual(dive.title, "Dive into Python")
|
||||
|
Loading…
x
Reference in New Issue
Block a user