Skip to content

Commit

Permalink
Fixed #17339 -- Factor out has_result into database backend.
Browse files Browse the repository at this point in the history
Thanks jonash.
  • Loading branch information
timgraham committed Jul 9, 2013
1 parent c0a4894 commit 95eb68c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 10 additions & 0 deletions django/db/models/sql/compiler.py
Expand Up @@ -750,6 +750,16 @@ def results_iter(self):


yield row yield row


def has_results(self):
"""
Backends (e.g. NoSQL) can override this in order to use optimized
versions of "query has any results."
"""
# This is always executed on a query clone, so we can modify self.query
self.query.add_extra({'a': 1}, None, None, None, None, None)
self.query.set_extra_mask(['a'])
return bool(self.execute_sql(SINGLE))

def execute_sql(self, result_type=MULTI): def execute_sql(self, result_type=MULTI):
""" """
Run the query against the database and returns the result(s). The Run the query against the database and returns the result(s). The
Expand Down
4 changes: 1 addition & 3 deletions django/db/models/sql/query.py
Expand Up @@ -401,12 +401,10 @@ def get_count(self, using):
def has_results(self, using): def has_results(self, using):
q = self.clone() q = self.clone()
q.clear_select_clause() q.clear_select_clause()
q.add_extra({'a': 1}, None, None, None, None, None)
q.set_extra_mask(['a'])
q.clear_ordering(True) q.clear_ordering(True)
q.set_limits(high=1) q.set_limits(high=1)
compiler = q.get_compiler(using=using) compiler = q.get_compiler(using=using)
return bool(compiler.execute_sql(SINGLE)) return compiler.has_results()


def combine(self, rhs, connector): def combine(self, rhs, connector):
""" """
Expand Down

0 comments on commit 95eb68c

Please sign in to comment.