diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-08-12 21:07:24 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-08-12 21:07:24 -0400 |
| commit | 8340361bfa93dab71b18827fa0b7e7dc91b1d736 (patch) | |
| tree | cdf93e83cf4d2055510f507196b7194cf7ea115f /lib | |
| parent | daf286fc33e4008499f5aea14dc44630c3709c11 (diff) | |
| download | sqlalchemy-8340361bfa93dab71b18827fa0b7e7dc91b1d736.tar.gz | |
- [bug] Fixed compiler bug whereby a given
select() would be modified if it had an "offset"
attribute, causing the construct to not compile
correctly a second time. [ticket:2545]
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sqlalchemy/dialects/mssql/base.py | 9 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/oracle/base.py | 2 |
2 files changed, 6 insertions, 5 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index 91f396d23..cc50fbe6b 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -787,7 +787,7 @@ class MSSQLCompiler(compiler.SQLCompiler): so tries to wrap it in a subquery with ``row_number()`` criterion. """ - if not getattr(select, '_mssql_visit', None) and select._offset: + if select._offset and not getattr(select, '_mssql_visit', None): # to use ROW_NUMBER(), an ORDER BY is required. orderby = self.process(select._order_by_clause) if not orderby: @@ -796,6 +796,7 @@ class MSSQLCompiler(compiler.SQLCompiler): _offset = select._offset _limit = select._limit + select = select._generate() select._mssql_visit = True select = select.column( sql.literal_column("ROW_NUMBER() OVER (ORDER BY %s)" \ @@ -804,10 +805,10 @@ class MSSQLCompiler(compiler.SQLCompiler): mssql_rn = sql.column('mssql_rn') limitselect = sql.select([c for c in select.c if - c.key!='mssql_rn']) - limitselect.append_whereclause(mssql_rn> _offset) + c.key != 'mssql_rn']) + limitselect.append_whereclause(mssql_rn > _offset) if _limit is not None: - limitselect.append_whereclause(mssql_rn<=(_limit + _offset)) + limitselect.append_whereclause(mssql_rn <= (_limit + _offset)) return self.process(limitselect, iswrapper=True, **kwargs) else: return compiler.SQLCompiler.visit_select(self, select, **kwargs) diff --git a/lib/sqlalchemy/dialects/oracle/base.py b/lib/sqlalchemy/dialects/oracle/base.py index cbeac7791..3c6ec55af 100644 --- a/lib/sqlalchemy/dialects/oracle/base.py +++ b/lib/sqlalchemy/dialects/oracle/base.py @@ -566,7 +566,7 @@ class OracleCompiler(compiler.SQLCompiler): if not self.dialect.use_binds_for_limits: max_row = sql.literal_column("%d" % max_row) limitselect.append_whereclause( - sql.literal_column("ROWNUM")<=max_row) + sql.literal_column("ROWNUM") <= max_row) # If needed, add the ora_rn, and wrap again with offset. if select._offset is None: |
