From b0fff23df8e00de7c783254f1dea51831b0ca6de Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 28 Apr 2006 15:02:49 +0000 Subject: [PATCH] fix to subquery parens --- lib/sqlalchemy/sql.py | 5 ++--- test/select.py | 6 ++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/sqlalchemy/sql.py b/lib/sqlalchemy/sql.py index 1af02faacc..a6908a1b99 100644 --- a/lib/sqlalchemy/sql.py +++ b/lib/sqlalchemy/sql.py @@ -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) diff --git a/test/select.py b/test/select.py index 5038f8f138..fb136cfec7 100644 --- a/test/select.py +++ b/test/select.py @@ -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") -- 2.47.2