From: Mike Bayer Date: Tue, 4 Jun 2013 23:52:53 +0000 (-0400) Subject: - if the select() does not have use_labels on, then we just render X-Git-Tag: rel_0_9_0b1~294^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=92e599f42f4a7dde1662fe0ae428d32bb4e8cc42;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - 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. --- diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 116fb39716..af70d13fac 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 4034484925..701d258879 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"""