mirror of
https://github.com/django/django.git
synced 2025-12-01 07:48:28 +00:00
Fixed #19173 -- Made EmptyQuerySet a marker class only
The guarantee that no queries will be made when accessing results is done by new EmptyWhere class which is used for query.where and having. Thanks to Simon Charette for reviewing and valuable suggestions.
This commit is contained in:
parent
a843539af2
commit
a2396a4c8f
11 changed files with 96 additions and 177 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue