Ticket #9136: rownum.2.patch
File rownum.2.patch, 1.6 KB (added by , 16 years ago) |
---|
-
django/db/backends/oracle/query.py
97 97 sql, params = super(OracleQuery, self).as_sql(with_limits=False, 98 98 with_col_aliases=with_col_aliases) 99 99 else: 100 # `get_columns` needs to be called before `get_ordering` to101 # 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_alias112 opts = self.model._meta113 rn_orderby = '%s.%s' % (qn(opts.db_table),114 qn(opts.fields[0].db_column or opts.fields[0].column))115 116 100 # 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 119 103 sql, params = super(OracleQuery, self).as_sql(with_limits=False, 120 104 with_col_aliases=True) 121 105