Ticket #5012: negative_sliced_querysets_oracle.patch

File negative_sliced_querysets_oracle.patch, 2.9 KB (added by ian.g.kelly@…, 17 years ago)

Negative indexing patch of django/db/backends/oracle/base.py

  • django/db/backends/oracle/base.py

     
    3030    # Import copy of _thread_local.py from Python 2.4
    3131    from django.utils._threading_local import local
    3232
     33try:
     34    reversed
     35except NameError:
     36    from django.utils.itercompat import reversed   # Python 2.3 fallback
     37
    3338class DatabaseWrapper(local):
    3439    def __init__(self, **kwargs):
    3540        self.connection = None
     
    183188
    184189def get_limit_offset_sql(limit, offset=None):
    185190    # Limits and offset are too complicated to be handled here.
    186     # Instead, they are handled in django/db/backends/oracle/query.py.
     191    # Instead, they are handled in the OracleQuerySet class.
    187192    return ""
    188193
    189194def get_random_function_sql():
     
    310315
    311316    class OracleQuerySet(DefaultQuerySet):
    312317
    313         def iterator(self):
     318        def _iterator(self):
    314319            "Performs the SELECT database lookup of this QuerySet."
    315320
    316321            from django.db.models.query import get_cached_row
     
    328333                    select, sql, params = self._get_sql_clause()
    329334            except EmptyResultSet:
    330335                raise StopIteration
     336            if self._limit == 0:
     337                raise StopIteration
    331338            if not full_query:
    332339                full_query = "SELECT %s%s\n%s" % \
    333340                             ((self._distinct and "DISTINCT " or ""),
     
    405412
    406413            # ORDER BY clause
    407414            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):
     415            for f in handle_legacy_orderlist(self._get_ordering()):
    413416                if f == '?': # Special case.
    414417                    order_by.append(backend.get_random_function_sql())
    415418                else:
     
    452455                order_by_clause = " OVER (ORDER BY %s )" % (", ".join(order_by))
    453456            else:
    454457                #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'"
     458                #So we need to define a stable order-by, since none was provided.
     459                order_by_clause = " OVER (ORDER BY 1)"
    462460
     461            # limit_and_offset_clause
    463462            if self._offset is not None:
    464463                offset = int(self._offset)
    465464            else:
Back to Top