1. Victor Shih
  2. django-mssql


Michael Manfre  committed 46d8d58

Don't execute a query that is sliced to have no results. E.g. LIMIT 0

  • Participants
  • Parent commits 966df69
  • Branches default

Comments (0)

Files changed (2)

File docs/changelog.txt

View file
   This relies upon the ``with_col_aliases`` argument to ``SQLCompiler.as_sql`` only being ``True`` when the query 
   is a subquery, which is currently the case for all usages in Django 1.5 master. :issue:`18`
 - UPDATE statements will now return the number of rows affected, instead of -1. :issue:`19`
+- Apply fix for :djangoticket:`12192`. If QuerySet slicing would result in ``LIMIT 0``, then it shouldn't reach
+  the database because there will be no response.

File sqlserver_ado/compiler.py

View file
                     self.query.aggregate_select[alias].sql_function = 'VARP'
     def as_sql(self, with_limits=True, with_col_aliases=False):
+        # Django #12192 - Don't execute any DB query when QS slicing results in limit 0
+        if with_limits and self.query.low_mark == self.query.high_mark:
+            return '', ()
         self._using_row_number = False