]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- use_ansi=False won't leak into the FROM/WHERE clause of
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 30 Jan 2010 19:00:40 +0000 (19:00 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 30 Jan 2010 19:00:40 +0000 (19:00 +0000)
a statement that's selecting from a subquery that also
uses JOIN/OUTERJOIN.

CHANGES
lib/sqlalchemy/dialects/oracle/base.py
test/dialect/test_oracle.py

diff --git a/CHANGES b/CHANGES
index fa9d2366d984ecf722982f52041e9e392df3a371..b1b82715851275434a35ff3cde426d691524b3d3 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -728,6 +728,10 @@ CHANGES
 
     - an NCLOB type is added to the base types.
     
+    - use_ansi=False won't leak into the FROM/WHERE clause of
+      a statement that's selecting from a subquery that also
+      uses JOIN/OUTERJOIN.
+      
     - added native INTERVAL type to the dialect.  This supports
       only the DAY TO SECOND interval type so far due to lack 
       of support in cx_oracle for YEAR TO MONTH. [ticket:1467]
index bb9ed325069692189dcf0a1ba707584437650080..5f7a3029292ad08804bc00ac4c5d045c5a71a3c0 100644 (file)
@@ -351,9 +351,14 @@ class OracleCompiler(compiler.SQLCompiler):
                 clauses.append(visitors.cloned_traverse(join.onclause, {}, {'binary':visit_binary}))
             else:
                 clauses.append(join.onclause)
-
+            
+            for j in join.left, join.right:
+                if isinstance(j, expression.Join):
+                    visit_join(j)
+                
         for f in froms:
-            visitors.traverse(f, {}, {'join':visit_join})
+            if isinstance(f, expression.Join):
+                visit_join(f)
         return sql.and_(*clauses)
 
     def visit_outer_join_column(self, vc):
@@ -404,7 +409,7 @@ class OracleCompiler(compiler.SQLCompiler):
                     existingfroms = self.stack[-1]['from']
                 else:
                     existingfroms = None
-
+                
                 froms = select._get_display_froms(existingfroms)
                 whereclause = self._get_nonansi_join_whereclause(froms)
                 if whereclause is not None:
index 5378280af9c3793d3d3d032d6d095280340e1043..a6c3c19bcd3e069f391ce57932f33979c39ceadc 100644 (file)
@@ -203,6 +203,24 @@ AND mytable.myid = myothertable.otherid(+)",
             "mytable.myid = myothertable.otherid ORDER BY mytable.name) WHERE "
             "ROWNUM <= :ROWNUM_1) WHERE ora_rn > :ora_rn_1", dialect=oracle.dialect(use_ansi=False))
 
+        subq = select([table1]).\
+                    select_from(table1.outerjoin(table2, table1.c.myid==table2.c.otherid)).alias()
+        q = select([table3]).select_from(table3.outerjoin(subq, table3.c.userid==subq.c.myid))
+
+        self.assert_compile(q, "SELECT thirdtable.userid, thirdtable.otherstuff "
+                        "FROM thirdtable LEFT OUTER JOIN (SELECT mytable.myid AS myid, mytable.name"
+                        " AS name, mytable.description AS description "
+                        "FROM mytable LEFT OUTER JOIN myothertable ON mytable.myid = "           
+                        "myothertable.otherid) anon_1 ON thirdtable.userid = anon_1.myid",
+                                dialect=oracle.dialect(use_ansi=True))
+    
+        self.assert_compile(q, "SELECT thirdtable.userid, thirdtable.otherstuff "
+                            "FROM thirdtable, (SELECT mytable.myid AS myid, mytable.name AS name, "
+                            "mytable.description AS description FROM mytable, myothertable "
+                            "WHERE mytable.myid = myothertable.otherid(+)) anon_1 "
+                            "WHERE thirdtable.userid = anon_1.myid(+)", 
+                            dialect=oracle.dialect(use_ansi=False))
+        
     def test_alias_outer_join(self):
         address_types = table('address_types',
                     column('id'),