[sqlserver2005] accept different types of arguments in sql_add_limit_offset (closes #70253)

authorAlexandre Fayolle <alexandre.fayolle@logilab.fr>
changesetc3cf9b35da61
branchstable
phasepublic
hiddenno
parent revision#37d856bfd6f3 Make sqlite backup and restore commands work (closes #69607)
child revision#48262d635773 add wrapper for fetchmany (used by recent versions of CW), #37206cda878e backport stable
files modified by this revision
sqlserver2005.py
# HG changeset patch
# User Alexandre Fayolle <alexandre.fayolle@logilab.fr>
# Date 1309420193 -7200
# Thu Jun 30 09:49:53 2011 +0200
# Branch stable
# Node ID c3cf9b35da61b9b9b738c209ac828dca583666f2
# Parent 37d856bfd6f3527b33dc8e7ebe07b9f46fd4da78
[sqlserver2005] accept different types of arguments in sql_add_limit_offset (closes #70253)

diff --git a/sqlserver2005.py b/sqlserver2005.py
@@ -167,13 +167,17 @@
1          outer_aliases = ', '.join(alias for _colname, alias in aliases_cols)
2          if orderby is None:
3              order_by = outer_aliases
4          else:
5              order_by = []
6 -            for term in orderby:
7 +            for i, term in enumerate(orderby):
8                  split = term.split()
9 -                split[0] = aliases_cols[int(split[0])-1][1]
10 +                try:
11 +                    idx = int(split[0]) - 1 
12 +                except ValueError:
13 +                    idx = i
14 +                split[0] = aliases_cols[idx][1]
15                  order_by.append(' '.join(split))
16              order_by = ', '.join(order_by)
17          new_query = ['WITH orderedrows AS (',
18                       'SELECT ', outer_aliases, ', '
19                       "ROW_NUMBER() OVER (ORDER BY %s) AS __RowNumber" % order_by,