Code

Ticket #5012: negative_sliced_querysets_oracle.2.patch

File negative_sliced_querysets_oracle.2.patch, 2.6 KB (added by ian.g.kelly@…, 7 years ago)
  • django/db/backends/oracle/base.py

     
    183183 
    184184def get_limit_offset_sql(limit, offset=None): 
    185185    # Limits and offset are too complicated to be handled here. 
    186     # Instead, they are handled in django/db/backends/oracle/query.py. 
     186    # Instead, they are handled in the OracleQuerySet class. 
    187187    return "" 
    188188 
    189189def get_random_function_sql(): 
     
    310310 
    311311    class OracleQuerySet(DefaultQuerySet): 
    312312 
    313         def iterator(self): 
     313        def _iterator(self): 
    314314            "Performs the SELECT database lookup of this QuerySet." 
    315315 
    316316            from django.db.models.query import get_cached_row 
     
    328328                    select, sql, params = self._get_sql_clause() 
    329329            except EmptyResultSet: 
    330330                raise StopIteration 
     331            if self._limit == 0: 
     332                raise StopIteration 
    331333            if not full_query: 
    332334                full_query = "SELECT %s%s\n%s" % \ 
    333335                             ((self._distinct and "DISTINCT " or ""), 
     
    405407 
    406408            # ORDER BY clause 
    407409            order_by = [] 
    408             if self._order_by is not None: 
    409                 ordering_to_use = self._order_by 
    410             else: 
    411                 ordering_to_use = opts.ordering 
    412             for f in handle_legacy_orderlist(ordering_to_use): 
     410            for f in handle_legacy_orderlist(self._get_ordering()): 
    413411                if f == '?': # Special case. 
    414412                    order_by.append(backend.get_random_function_sql()) 
    415413                else: 
     
    452450                order_by_clause = " OVER (ORDER BY %s )" % (", ".join(order_by)) 
    453451            else: 
    454452                #Oracle's row_number() function always requires an order-by clause. 
    455                 #So we need to define a default order-by, since none was provided. 
    456                 order_by_clause = " OVER (ORDER BY %s.%s)" % \ 
    457                     (backend.quote_name(opts.db_table), 
    458                     backend.quote_name(opts.fields[0].db_column or opts.fields[0].column)) 
    459             # limit_and_offset_clause 
    460             if self._limit is None: 
    461                 assert self._offset is None, "'offset' is not allowed without 'limit'" 
     453                #So we need to define a stable order-by, since none was provided. 
     454                order_by_clause = " OVER (ORDER BY 1)" 
    462455 
     456            # limit_and_offset_clause 
    463457            if self._offset is not None: 
    464458                offset = int(self._offset) 
    465459            else: