diff options
Diffstat (limited to 'django/db/models/sql/compiler.py')
| -rw-r--r-- | django/db/models/sql/compiler.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 2877171fd2..e2788019f3 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -662,6 +662,20 @@ class SQLCompiler(object): columns = {} self.query.deferred_to_data(columns, self.query.deferred_to_columns_cb) 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): """ |
