summaryrefslogtreecommitdiff
path: root/test/dialect
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2016-02-20 20:22:38 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2016-02-20 20:22:38 -0500
commit8ad968f33100baeb3b13c7e0b724b6b79ab4277f (patch)
tree2a4081d4cec903327ce6b3c6d374858d3218a92a /test/dialect
parent60a9d2da25da68466130771afc3f35c9473aca02 (diff)
downloadsqlalchemy-8ad968f33100baeb3b13c7e0b724b6b79ab4277f.tar.gz
- reworked the way the "select_wraps_for" expression is
handled within visit_select(); this attribute was added in the 1.0 series to accommodate the subquery wrapping behavior of SQL Server and Oracle while also working with positional column targeting and no longer relying upon "key fallback" in order to target columns in such a statement. The IBM DB2 third-party dialect also has this use case, but its implementation is using regular expressions to rewrite the textual SELECT only and does not make use of a "wrapped" select at this time. The logic no longer attempts to reconcile proxy set collections as this was not deterministic, and instead assumes that the select() and the wrapper select() match their columns postionally, at least for the column positions they have in common, so it is now very simple and safe. fixes #3657. - as a side effect of #3657 it was also revealed that the strategy of calling upon a ResultProxy._getter was not correctly calling into NoSuchColumnError when an expected column was not present, and instead returned None up to loading.instances() to produce NoneType failures; added a raiseerr argument to _getter() which is called when we aren't expecting None, fixes #3658.
Diffstat (limited to 'test/dialect')
-rw-r--r--test/dialect/mssql/test_compiler.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/test/dialect/mssql/test_compiler.py b/test/dialect/mssql/test_compiler.py
index d91c79db2..b59ca4fd1 100644
--- a/test/dialect/mssql/test_compiler.py
+++ b/test/dialect/mssql/test_compiler.py
@@ -1,5 +1,5 @@
# -*- encoding: utf-8
-from sqlalchemy.testing import eq_
+from sqlalchemy.testing import eq_, is_
from sqlalchemy import schema
from sqlalchemy.sql import table, column
from sqlalchemy.databases import mssql
@@ -521,6 +521,30 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
assert t.c.x in set(c._create_result_map()['x'][1])
assert t.c.y in set(c._create_result_map()['y'][1])
+ def test_limit_offset_w_ambiguous_cols(self):
+ t = table('t', column('x', Integer), column('y', Integer))
+
+ cols = [t.c.x, t.c.x.label('q'), t.c.x.label('p'), t.c.y]
+ s = select(cols).where(t.c.x == 5).order_by(t.c.y).limit(10).offset(20)
+
+ self.assert_compile(
+ s,
+ "SELECT anon_1.x, anon_1.q, anon_1.p, anon_1.y "
+ "FROM (SELECT t.x AS x, t.x AS q, t.x AS p, t.y AS y, "
+ "ROW_NUMBER() OVER (ORDER BY t.y) AS mssql_rn "
+ "FROM t "
+ "WHERE t.x = :x_1) AS anon_1 "
+ "WHERE mssql_rn > :param_1 AND mssql_rn <= :param_2 + :param_1",
+ checkparams={'param_1': 20, 'param_2': 10, 'x_1': 5}
+ )
+ c = s.compile(dialect=mssql.MSDialect())
+ eq_(len(c._result_columns), 4)
+
+ result_map = c._create_result_map()
+
+ for col in cols:
+ is_(result_map[col.key][1][0], col)
+
def test_limit_offset_with_correlated_order_by(self):
t1 = table('t1', column('x', Integer), column('y', Integer))
t2 = table('t2', column('x', Integer), column('y', Integer))