Ticket #9136: rownum.2.patch

File rownum.2.patch, 1.6 KB (added by Guillaume Taglang <guillaume.taglang@…>, 10 years ago)

Updated patch

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

     
    9797                sql, params = super(OracleQuery, self).as_sql(with_limits=False,
    9898                        with_col_aliases=with_col_aliases)
    9999            else:
    100                 # `get_columns` needs to be called before `get_ordering` to
    101                 # populate `_select_alias`.
    102                 self.pre_sql_setup()
    103                 self.get_columns()
    104                 ordering = self.get_ordering()
    105 
    106                 # Oracle's ROW_NUMBER() function requires an ORDER BY clause.
    107                 if ordering:
    108                     rn_orderby = ', '.join(ordering)
    109                 else:
    110                     # Create a default ORDER BY since none was specified.
    111                     qn = self.quote_name_unless_alias
    112                     opts = self.model._meta
    113                     rn_orderby = '%s.%s' % (qn(opts.db_table),
    114                         qn(opts.fields[0].db_column or opts.fields[0].column))
    115 
    116100                # Ensure the base query SELECTs our special "_RN" column
    117                 self.extra_select['_RN'] = ('ROW_NUMBER() OVER (ORDER BY %s)'
    118                                             % rn_orderby, '')
     101                self.extra_select['_RN'] = ('ROWNUM', '')
     102               
    119103                sql, params = super(OracleQuery, self).as_sql(with_limits=False,
    120104                                                        with_col_aliases=True)
    121105
Back to Top