diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-06-04 19:52:53 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-06-04 19:52:53 -0400 |
commit | 92e599f42f4a7dde1662fe0ae428d32bb4e8cc42 (patch) | |
tree | f025e564b851cc0e6808d88e418c35363684d167 | |
parent | d8a38839483aede934b6cbeb6d0828d362767a4d (diff) | |
download | sqlalchemy-92e599f42f4a7dde1662fe0ae428d32bb4e8cc42.tar.gz |
- if the select() does not have use_labels on, then we just render
the joins as is, regardless of the dialect not supporting it. use_labels=True
indicates a higher level of automation and also can maintain the labels
between rewritten and not. use_labels=False indicates a manual use case.
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 1 | ||||
-rw-r--r-- | test/sql/test_join_rewriting.py | 51 |
2 files changed, 52 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 116fb3971..af70d13fa 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -1164,6 +1164,7 @@ class SQLCompiler(engine.Compiled): nested_join_translation=False, **kwargs): needs_nested_translation = \ + select.use_labels and \ not nested_join_translation and \ not self.stack and \ not self.dialect.supports_right_nested_joins diff --git a/test/sql/test_join_rewriting.py b/test/sql/test_join_rewriting.py index 403448492..701d25887 100644 --- a/test/sql/test_join_rewriting.py +++ b/test/sql/test_join_rewriting.py @@ -188,6 +188,57 @@ class JoinPlainTest(_JoinRewriteTestBase, fixtures.TestBase): "ON a_1.id = anon_1.b_a_id ORDER BY anon_1.b_id" ) +class JoinNoUseLabelsTest(_JoinRewriteTestBase, fixtures.TestBase): + @util.classproperty + def __dialect__(cls): + dialect = default.DefaultDialect() + dialect.supports_right_nested_joins = False + return dialect + + def _test(self, s, assert_): + s.use_labels = False + self.assert_compile( + s, + assert_ + ) + + _a__b_dc = ( + "SELECT a.id, b.id, " + "b.a_id, c.id, " + "c.b_id, d.id, " + "d.c_id " + "FROM a JOIN (b JOIN (c JOIN d ON c.id = d.c_id) " + "ON b.id = c.b_id) ON a.id = b.a_id " + "WHERE b.id = :id_1 AND c.id = :id_2 AND " + "d.id = :id_3 " + "ORDER BY a.id, b.id, c.id, d.id" + ) + + _a_bc = ( + "SELECT a.id, b.id, " + "b.a_id, c.id, " + "c.b_id FROM a JOIN " + "(b JOIN c ON b.id = c.b_id) " + "ON a.id = b.a_id " + "WHERE b.id = :id_1 AND c.id = :id_2 " + "ORDER BY a.id, b.id, c.id" + ) + + _a_bc_comma_a1_selbc = ( + "SELECT a.id, a_1.id, b.id, " + "b.a_id, c.id, " + "c.b_id, anon_1.b_id, " + "anon_1.b_a_id, anon_1.c_id, " + "anon_1.c_b_id FROM a " + "JOIN (b JOIN c ON b.id = c.b_id) " + "ON a.id = b.a_id, " + "a AS a_1 JOIN " + "(SELECT b.id AS b_id, b.a_id AS b_a_id, " + "c.id AS c_id, c.b_id AS c_b_id " + "FROM b JOIN c ON b.id = c.b_id) AS anon_1 " + "ON a_1.id = anon_1.b_a_id ORDER BY anon_1.b_id" + ) + class JoinExecTest(_JoinRewriteTestBase, fixtures.TestBase): """invoke the SQL on the current backend to ensure compatibility""" |