]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- add a flag to DefaultDialect for this so that people will have some
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 4 Jun 2013 22:43:59 +0000 (18:43 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 4 Jun 2013 22:43:59 +0000 (18:43 -0400)
workaround

lib/sqlalchemy/engine/default.py
test/sql/test_join_rewriting.py

index 94f59d388721f5eac5cea83c47fe1a448557e522..7d558f5ff582cc552fa9fa40c7e810245c365807 100644 (file)
@@ -106,6 +106,7 @@ class DefaultDialect(interfaces.Dialect):
     def __init__(self, convert_unicode=False,
                  encoding='utf-8', paramstyle=None, dbapi=None,
                  implicit_returning=None,
+                 supports_right_nested_joins=None,
                  case_sensitive=True,
                  label_length=None, **kwargs):
 
@@ -130,6 +131,8 @@ class DefaultDialect(interfaces.Dialect):
         self.positional = self.paramstyle in ('qmark', 'format', 'numeric')
         self.identifier_preparer = self.preparer(self)
         self.type_compiler = self.type_compiler(self)
+        if supports_right_nested_joins is not None:
+            self.supports_right_nested_joins = supports_right_nested_joins
 
         self.case_sensitive = case_sensitive
 
index ba54acb0549169e80a1408b980b4a41341cbbb50..2cf98be3ff25ded4d21612eaf5e3347ce6e6881b 100644 (file)
@@ -3,7 +3,6 @@ from sqlalchemy.testing import fixtures, AssertsCompiledSQL
 from sqlalchemy import util
 from sqlalchemy.engine import default
 
-
 m = MetaData()
 
 a = Table('a', m,
@@ -110,3 +109,31 @@ class JoinRewriteTest(fixtures.TestBase, AssertsCompiledSQL):
                 "FROM b JOIN c ON b.id = c.b_id) AS anon_2 "
             "ON a_1.id = anon_2.b_a_id ORDER BY anon_2.b_id"
         )
+
+    def test_dialect_flag(self):
+        d1 = default.DefaultDialect(supports_right_nested_joins=True)
+        d2 = default.DefaultDialect(supports_right_nested_joins=False)
+
+        j1 = b.join(c)
+        j2 = a.join(j1)
+
+        s = select([a, b, c], use_labels=True).\
+            select_from(j2)
+
+        self.assert_compile(
+            s,
+            "SELECT a.id AS a_id, 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 a JOIN (b JOIN c ON b.id = c.b_id) "
+            "ON a.id = b.a_id",
+            dialect=d1
+        )
+        self.assert_compile(
+            s,
+            "SELECT a.id AS a_id, anon_1.b_id AS b_id, "
+            "anon_1.b_a_id AS b_a_id, "
+            "anon_1.c_id AS c_id, anon_1.c_b_id AS c_b_id "
+            "FROM a 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.id = anon_1.b_a_id",
+            dialect=d2
+        )