summaryrefslogtreecommitdiff
path: root/django/db/models/sql
diff options
context:
space:
mode:
Diffstat (limited to 'django/db/models/sql')
-rw-r--r--django/db/models/sql/query.py9
-rw-r--r--django/db/models/sql/where.py8
2 files changed, 16 insertions, 1 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 87104f0d13..f021d571e9 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -25,7 +25,7 @@ from django.db.models.sql.constants import (QUERY_TERMS, ORDER_DIR, SINGLE,
from django.db.models.sql.datastructures import EmptyResultSet, Empty, MultiJoin
from django.db.models.sql.expressions import SQLEvaluator
from django.db.models.sql.where import (WhereNode, Constraint, EverythingNode,
- ExtraWhere, AND, OR)
+ ExtraWhere, AND, OR, EmptyWhere)
from django.core.exceptions import FieldError
__all__ = ['Query', 'RawQuery']
@@ -1511,6 +1511,13 @@ class Query(object):
self.add_filter(('%s__isnull' % trimmed_prefix, False), negate=True,
can_reuse=can_reuse)
+ def set_empty(self):
+ self.where = EmptyWhere()
+ self.having = EmptyWhere()
+
+ def is_empty(self):
+ return isinstance(self.where, EmptyWhere) or isinstance(self.having, EmptyWhere)
+
def set_limits(self, low=None, high=None):
"""
Adjusts the limits on the rows retrieved. We use low/high to set these,
diff --git a/django/db/models/sql/where.py b/django/db/models/sql/where.py
index 47f4ffaba9..02847b1f54 100644
--- a/django/db/models/sql/where.py
+++ b/django/db/models/sql/where.py
@@ -272,6 +272,14 @@ class WhereNode(tree.Node):
if hasattr(child[3], 'relabel_aliases'):
child[3].relabel_aliases(change_map)
+class EmptyWhere(WhereNode):
+
+ def add(self, data, connector):
+ return
+
+ def as_sql(self, qn=None, connection=None):
+ raise EmptyResultSet
+
class EverythingNode(object):
"""
A node that matches everything.