Ticket #17339: factor-out-has_results.patch

File factor-out-has_results.patch, 1.4 KB (added by Jonas H., 13 years ago)
  • django/db/models/sql/compiler.py

    e11d846 has_results
    diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
    index cebd77f..037d72d 100644
    a b class SQLCompiler(object):  
    729729
    730730                yield row
    731731
     732    def has_results(self):
     733        # This is always executed on a query clone, so we can modify self.query
     734        self.query.add_extra({'a': 1}, None, None, None, None, None)
     735        self.query.set_extra_mask(('a',))
     736        return bool(self.execute_sql(SINGLE))
     737
    732738    def execute_sql(self, result_type=MULTI):
    733739        """
    734740        Run the query against the database and returns the result(s). The
  • django/db/models/sql/query.py

    diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
    index 4afe288..25b0727 100644
    a b class Query(object):  
    425425
    426426    def has_results(self, using):
    427427        q = self.clone()
    428         q.add_extra({'a': 1}, None, None, None, None, None)
    429428        q.select = []
    430429        q.select_fields = []
    431430        q.default_cols = False
    432431        q.select_related = False
    433         q.set_extra_mask(('a',))
    434432        q.set_aggregate_mask(())
    435433        q.clear_ordering(True)
    436434        q.set_limits(high=1)
    437435        compiler = q.get_compiler(using=using)
    438         return bool(compiler.execute_sql(SINGLE))
     436        return compiler.has_results()
    439437
    440438    def combine(self, rhs, connector):
    441439        """
Back to Top