Ticket #14857: has_results.diff

File has_results.diff, 1.4 KB (added by Waldemar Kornewald, 13 years ago)

patch against trunk

  • django/db/models/sql/compiler.py

    diff -r 9b24e08becc2 django/db/models/sql/compiler.py
    a b  
    703703
    704704                yield row
    705705
     706    def has_results(self):
     707        # This is always executed on a query clone, so we can modify self.query
     708        self.query.add_extra({'a': 1}, None, None, None, None, None)
     709        self.query.set_extra_mask(('a',))
     710        return bool(self.execute_sql(SINGLE))
     711
    706712    def execute_sql(self, result_type=MULTI):
    707713        """
    708714        Run the query against the database and returns the result(s). The
  • django/db/models/sql/query.py

    diff -r 9b24e08becc2 django/db/models/sql/query.py
    a b  
    404404
    405405    def has_results(self, using):
    406406        q = self.clone()
    407         q.add_extra({'a': 1}, None, None, None, None, None)
    408407        q.select = []
    409408        q.select_fields = []
    410409        q.default_cols = False
    411410        q.select_related = False
    412         q.set_extra_mask(('a',))
    413411        q.set_aggregate_mask(())
    414412        q.clear_ordering(True)
    415413        q.set_limits(high=1)
    416414        compiler = q.get_compiler(using=using)
    417         return bool(compiler.execute_sql(SINGLE))
     415        return compiler.has_results()
    418416
    419417    def combine(self, rhs, connector):
    420418        """
Back to Top