From 95eb68c98fe2dc95277d4e26a0316d856dc868dd Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Mon, 8 Jul 2013 11:05:08 -0400 Subject: Fixed #17339 -- Factor out has_result into database backend. Thanks jonash. --- django/db/models/sql/compiler.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'django/db/models/sql/compiler.py') diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 0b12bd1552..e17cb3f616 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -750,6 +750,16 @@ class SQLCompiler(object): 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): """ Run the query against the database and returns the result(s). The -- cgit v1.3