]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- if the select() does not have use_labels on, then we just render
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 4 Jun 2013 23:52:53 +0000 (19:52 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 4 Jun 2013 23:52:53 +0000 (19:52 -0400)
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.

lib/sqlalchemy/sql/compiler.py
test/sql/test_join_rewriting.py

index 116fb397164ed60e1b6da08b5e3e3f4ecd865454..af70d13facae73be248b781b885ec2982a5217ad 100644 (file)
@@ -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
index 403448492563c8d2136e8c440f7860cd02e2340f..701d2588793e7694fe5466623318f504aba0ae29 100644 (file)
@@ -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"""