From 74064ce9fd8e08619fb376ac506311d96a7ba85e Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 10 Oct 2007 02:30:00 +0000 Subject: [PATCH] - fixed Oracle non-ansi join syntax --- CHANGES | 2 ++ lib/sqlalchemy/databases/oracle.py | 16 +++++++++++----- test/dialect/oracle.py | 3 +++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index 2723504ef9..30ae3cc5c0 100644 --- a/CHANGES +++ b/CHANGES @@ -55,6 +55,8 @@ CHANGES - Added an option to the _ScopedExt mapper extension to not automatically save new objects to session on object initialization. +- fixed Oracle non-ansi join syntax + 0.4.0beta6 ---------- diff --git a/lib/sqlalchemy/databases/oracle.py b/lib/sqlalchemy/databases/oracle.py index 951f97e38d..848a68ff35 100644 --- a/lib/sqlalchemy/databases/oracle.py +++ b/lib/sqlalchemy/databases/oracle.py @@ -577,12 +577,18 @@ class OracleCompiler(compiler.DefaultCompiler): binary.left = _OuterJoinColumn(binary.left) elif binary.right.table is join.right: binary.right = _OuterJoinColumn(binary.right) - - if where is not None: - self.__wheres[join.left] = self.__wheres[parentjoin] = (sql.and_(VisitOn().traverse(join.onclause, clone=True), where), parentjoin) + + if join.isouter: + if where is not None: + self.__wheres[join.left] = self.__wheres[parentjoin] = (sql.and_(VisitOn().traverse(join.onclause, clone=True), where), parentjoin) + else: + self.__wheres[join.left] = self.__wheres[join] = (VisitOn().traverse(join.onclause, clone=True), join) else: - self.__wheres[join.left] = self.__wheres[join] = (VisitOn().traverse(join.onclause, clone=True), join) - + if where is not None: + self.__wheres[join.left] = self.__wheres[parentjoin] = (sql.and_(join.onclause, where), parentjoin) + else: + self.__wheres[join.left] = self.__wheres[join] = (join.onclause, join) + return self.process(join.left, asfrom=True) + ", " + self.process(join.right, asfrom=True) def get_whereclause(self, f): diff --git a/test/dialect/oracle.py b/test/dialect/oracle.py index f993536167..2ad0c4bebb 100644 --- a/test/dialect/oracle.py +++ b/test/dialect/oracle.py @@ -97,6 +97,9 @@ myothertable.othername != :myothertable_othername OR EXISTS (select yay from foo query = table1.outerjoin(table2, table1.c.myid==table2.c.otherid).outerjoin(table3, table3.c.userid==table2.c.otherid) self.assert_compile(query.select(), "SELECT mytable.myid, mytable.name, mytable.description, myothertable.otherid, myothertable.othername, thirdtable.userid, thirdtable.otherstuff FROM mytable LEFT OUTER JOIN myothertable ON mytable.myid = myothertable.otherid LEFT OUTER JOIN thirdtable ON thirdtable.userid = myothertable.otherid") self.assert_compile(query.select(), "SELECT mytable.myid, mytable.name, mytable.description, myothertable.otherid, myothertable.othername, thirdtable.userid, thirdtable.otherstuff FROM mytable, myothertable, thirdtable WHERE mytable.myid = myothertable.otherid(+) AND thirdtable.userid(+) = myothertable.otherid", dialect=oracle.dialect(use_ansi=False)) + + query = table1.join(table2, table1.c.myid==table2.c.otherid).join(table3, table3.c.userid==table2.c.otherid) + self.assert_compile(query.select(), "SELECT mytable.myid, mytable.name, mytable.description, myothertable.otherid, myothertable.othername, thirdtable.userid, thirdtable.otherstuff FROM mytable, myothertable, thirdtable WHERE mytable.myid = myothertable.otherid AND thirdtable.userid = myothertable.otherid", dialect=oracle.dialect(use_ansi=False)) def test_alias_outer_join(self): address_types = table('address_types', -- 2.47.3