diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-04-30 19:06:26 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-04-30 19:06:26 -0400 |
commit | 5da667e017276f6dc48aa8698c899f6abae0f6ca (patch) | |
tree | e98fee6f25c9718f8f0eaa2f80f42d043ce2c9d7 /test | |
parent | 6022ac3097f6389226d50ec2555d9029dbbffef4 (diff) | |
download | sqlalchemy-konsta_3022.tar.gz |
- Fixed bug where the combination of "limit" rendering askonsta_3022
"SELECT FIRST n ROWS" using a bound parameter (only firebird has both),
combined with column-level subqueries
which also feature "limit" as well as "positional" bound parameters
(e.g. qmark style) would erroneously assign the subquery-level positions
before that of the enclosing SELECT, thus returning parameters which
are out of order. Fixes #3038
Diffstat (limited to 'test')
-rw-r--r-- | test/dialect/test_firebird.py | 7 | ||||
-rw-r--r-- | test/sql/test_compiler.py | 29 |
2 files changed, 34 insertions, 2 deletions
diff --git a/test/dialect/test_firebird.py b/test/dialect/test_firebird.py index 222e34b93..86464c8cb 100644 --- a/test/dialect/test_firebird.py +++ b/test/dialect/test_firebird.py @@ -415,8 +415,8 @@ class MiscTest(fixtures.TestBase): @testing.provide_metadata def test_rowcount_flag(self): metadata = self.metadata - engine = engines.testing_engine(options={'enable_rowcount' - : True}) + engine = engines.testing_engine( + options={'enable_rowcount': True}) assert engine.dialect.supports_sane_rowcount metadata.bind = engine t = Table('t1', metadata, Column('data', String(10))) @@ -431,6 +431,7 @@ class MiscTest(fixtures.TestBase): r = \ t.delete().execution_options(enable_rowcount=False).execute() eq_(r.rowcount, -1) + engine.dispose() engine = engines.testing_engine(options={'enable_rowcount' : False}) assert not engine.dialect.supports_sane_rowcount @@ -444,6 +445,8 @@ class MiscTest(fixtures.TestBase): eq_(r.rowcount, -1) r = t.delete().execution_options(enable_rowcount=True).execute() eq_(r.rowcount, 1) + r.close() + engine.dispose() def test_percents_in_text(self): for expr, result in (text("select '%' from rdb$database"), '%' diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index b1c807df6..8b02d12a9 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -28,6 +28,7 @@ from sqlalchemy.engine import default from sqlalchemy.dialects import mysql, mssql, postgresql, oracle, \ sqlite, sybase from sqlalchemy.ext.compiler import compiles +from sqlalchemy.sql import compiler table1 = table('mytable', column('myid', Integer), @@ -181,6 +182,34 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): checkparams=params ) + def test_select_precol_compile_ordering(self): + s1 = select([column('x')]).select_from('a').limit(5).as_scalar() + s2 = select([s1]).limit(10) + + class MyCompiler(compiler.SQLCompiler): + def get_select_precolumns(self, select): + result = "" + if select._limit: + result += "FIRST %s " % self.process(literal(select._limit)) + if select._offset: + result += "SKIP %s " % self.process(literal(select._offset)) + return result + + def limit_clause(self, select): + return "" + + dialect = default.DefaultDialect() + dialect.statement_compiler = MyCompiler + dialect.paramstyle = 'qmark' + dialect.positional = True + self.assert_compile( + s2, + "SELECT FIRST ? (SELECT FIRST ? x FROM a) AS anon_1", + checkpositional=(10, 5), + dialect=dialect + ) + + def test_from_subquery(self): """tests placing select statements in the column clause of another select, for the |