mirror of
https://github.com/django/django.git
synced 2025-07-04 17:59:13 +00:00
[soc2010/query-refactor] Moved has_results (implementation of exists()) onto the compiler, where it belongs.
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/query-refactor@13334 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
8690f66f4a
commit
b564f6c661
@ -493,7 +493,7 @@ class QuerySet(object):
|
|||||||
|
|
||||||
def exists(self):
|
def exists(self):
|
||||||
if self._result_cache is None:
|
if self._result_cache is None:
|
||||||
return self.query.has_results(using=self.db)
|
return self.query.get_compiler(self.db).has_results()
|
||||||
return bool(self._result_cache)
|
return bool(self._result_cache)
|
||||||
|
|
||||||
##################################################
|
##################################################
|
||||||
|
@ -662,6 +662,20 @@ class SQLCompiler(object):
|
|||||||
columns = {}
|
columns = {}
|
||||||
self.query.deferred_to_data(columns, self.query.deferred_to_columns_cb)
|
self.query.deferred_to_data(columns, self.query.deferred_to_columns_cb)
|
||||||
return columns
|
return columns
|
||||||
|
|
||||||
|
def has_results(self):
|
||||||
|
q = self.query.clone()
|
||||||
|
q.add_extra({'a': 1}, None, None, None, None, None)
|
||||||
|
q.select = []
|
||||||
|
q.select_fields = []
|
||||||
|
q.default_cols = False
|
||||||
|
q.select_related = False
|
||||||
|
q.set_extra_mask(('a',))
|
||||||
|
q.set_aggregate_mask(())
|
||||||
|
q.clear_ordering(True)
|
||||||
|
q.set_limits(high=1)
|
||||||
|
compiler = q.get_compiler(using=self.using)
|
||||||
|
return bool(compiler.execute_sql(SINGLE))
|
||||||
|
|
||||||
def results_iter(self):
|
def results_iter(self):
|
||||||
"""
|
"""
|
||||||
|
@ -402,20 +402,6 @@ class Query(object):
|
|||||||
|
|
||||||
return number
|
return number
|
||||||
|
|
||||||
def has_results(self, using):
|
|
||||||
q = self.clone()
|
|
||||||
q.add_extra({'a': 1}, None, None, None, None, None)
|
|
||||||
q.select = []
|
|
||||||
q.select_fields = []
|
|
||||||
q.default_cols = False
|
|
||||||
q.select_related = False
|
|
||||||
q.set_extra_mask(('a',))
|
|
||||||
q.set_aggregate_mask(())
|
|
||||||
q.clear_ordering(True)
|
|
||||||
q.set_limits(high=1)
|
|
||||||
compiler = q.get_compiler(using=using)
|
|
||||||
return bool(compiler.execute_sql(SINGLE))
|
|
||||||
|
|
||||||
def combine(self, rhs, connector):
|
def combine(self, rhs, connector):
|
||||||
"""
|
"""
|
||||||
Merge the 'rhs' query into the current one (with any 'rhs' effects
|
Merge the 'rhs' query into the current one (with any 'rhs' effects
|
||||||
|
Loading…
x
Reference in New Issue
Block a user