Ticket #1616: query.py.patch1

File query.py.patch1, 1.7 KB (added by rezzrovv, 18 years ago)

query.py patch

Line 
1Index: query.py
2===================================================================
3--- query.py (revision 2630)
4+++ query.py (working copy)
5@@ -414,22 +414,23 @@
6 if f == '?': # Special case.
7 order_by.append(backend.get_random_function_sql())
8 else:
9- if f.startswith('-'):
10- col_name = f[1:]
11- order = "DESC"
12+ if "." in f:
13+ table_prefix, col_name = f.split('.', 1)
14+ table_prefix = backend.quote_name(table_prefix) + '.'
15 else:
16 col_name = f
17- order = "ASC"
18- if "." in col_name:
19- table_prefix, col_name = col_name.split('.', 1)
20- table_prefix = backend.quote_name(table_prefix) + '.'
21- else:
22- # Use the database table as a column prefix if it wasn't given,
23- # and if the requested column isn't a custom SELECT.
24- if "." not in col_name and col_name not in [k[0] for k in (self._select or ())]:
25+ if col_name not in [k[0] for k in (self._select or ())]:
26 table_prefix = backend.quote_name(opts.db_table) + '.'
27 else:
28 table_prefix = ''
29+
30+
31+ if col_name.startswith('-'):
32+ col_name = col_name[1:]
33+ order = "DESC"
34+ else:
35+ order = "ASC"
36+
37 order_by.append('%s%s %s' % (table_prefix, backend.quote_name(orderfield2column(col_name, opts)), order))
38 if order_by:
39 sql.append("ORDER BY " + ", ".join(order_by))
Back to Top