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):
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)
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)
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")