]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
fix to subquery parens
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 28 Apr 2006 15:02:49 +0000 (15:02 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 28 Apr 2006 15:02:49 +0000 (15:02 +0000)
lib/sqlalchemy/sql.py
test/select.py

index 1af02faaccdae405fbdc78eca7bf885ab1f89169..a6908a1b99a122f24b37ed9c1720c9cb3191dee1 100644 (file)
@@ -543,7 +543,6 @@ class CompareMixin(object):
                 return BooleanExpression(self._compare_self(), null(), 'IS')
             else:
                 obj = self._bind_param(obj)
-
         return BooleanExpression(self._compare_self(), obj, operator, type=self._compare_type(obj))
     def _operate(self, operator, obj):
         if _is_literal(obj):
@@ -884,9 +883,9 @@ class BinaryClause(ClauseElement):
         self.operator = operator
         self.type = sqltypes.to_instance(type)
         self.parens = False
-        if isinstance(self.left, BinaryClause):
+        if isinstance(self.left, BinaryClause) or isinstance(self.left, Selectable):
             self.left.parens = True
-        if isinstance(self.right, BinaryClause):
+        if isinstance(self.right, BinaryClause) or isinstance(self.right, Selectable):
             self.right.parens = True
     def copy_container(self):
         return BinaryClause(self.left.copy_container(), self.right.copy_container(), self.operator)
index 5038f8f138f60c85fd3b0bac36ab29190cb8bc64..fb136cfec78f955a13550f33bfd42b232efc33a1 100644 (file)
@@ -151,6 +151,7 @@ sq.myothertable_othername AS sq_myothertable_othername FROM (" + sqstring + ") A
         self.runtest(
             select([users, s.c.street], from_obj=[s]),
             """SELECT users.user_id, users.user_name, users.password, s.street FROM users, (SELECT addresses.street AS street FROM addresses WHERE addresses.user_id = users.user_id) AS s""")
+
         
     def testcolumnsubquery(self):
         s = select([table1.c.myid], scalar=True, correlate=False)
@@ -623,6 +624,11 @@ class CRUDTest(SQLTest):
         u = update(table1, table1.c.name == 'jack', values = {table1.c.name : s})
         self.runtest(u, "UPDATE mytable SET name=(SELECT myothertable.otherid, myothertable.othername FROM myothertable WHERE myothertable.otherid = mytable.myid) WHERE mytable.name = :mytable_name")
         
+        # test a correlated WHERE clause
+        s = select([table2.c.othername], table2.c.otherid == 7)
+        u = update(table1, table1.c.name==s)
+        self.runtest(u, "UPDATE mytable SET myid=:myid, name=:name, description=:description WHERE mytable.name = (SELECT myothertable.othername FROM myothertable WHERE myothertable.otherid = :myothertable_otherid)")
+        
     def testdelete(self):
         self.runtest(delete(table1, table1.c.myid == 7), "DELETE FROM mytable WHERE mytable.myid = :mytable_myid")