def test_update_returning_w_type_coerce_expression(self, connection): table = self.tables.tables connection.execute( table.insert(), [ { "persons": 5, "goofy": "somegoofy1" }, { "persons": 3, "goofy": "somegoofy2" }, ], ) result = connection.execute(table.update().where( table.c.persons > 4).values(goofy="newgoofy").returning( type_coerce(table.c.goofy, String))) eq_(result.fetchall(), [("FOOnewgoofy", )]) result2 = connection.execute( select(table.c.id, table.c.goofy).order_by(table.c.id)) eq_( result2.fetchall(), [(1, "FOOnewgoofyBAR"), (2, "FOOsomegoofy2BAR")], )
def test_update_returning_w_expression_one(self, connection): table = self.tables.tables connection.execute( table.insert(), [ { "persons": 5, "full": False, "strval": "str1" }, { "persons": 3, "full": False, "strval": "str2" }, ], ) result = connection.execute(table.update().where( table.c.persons > 4).values(full=True).returning(table.c.strval + "hi")) eq_(result.fetchall(), [("str1hi", )]) result2 = connection.execute( select(table.c.id, table.c.strval).order_by(table.c.id)) eq_(result2.fetchall(), [(1, "str1"), (2, "str2")])
def test_update_ordered_parameters_fire_onupdate(self): table = self.tables.update_w_default values = [(table.c.y, table.c.x + 5), ('x', 10)] self.assert_compile( table.update(preserve_parameter_order=True).values(values), "UPDATE update_w_default SET ycol=(update_w_default.x + :x_1), " "x=:x, data=:data")
def test_update_ordered_parameters_fire_onupdate(self): table = self.tables.update_w_default values = [(table.c.y, table.c.x + 5), ("x", 10)] self.assert_compile( table.update(preserve_parameter_order=True).values(values), "UPDATE update_w_default SET ycol=(update_w_default.x + :x_1), " "x=:x, data=:data", )
def test_update_ordered_parameters_override_onupdate(self): table = self.tables.update_w_default values = [ (table.c.y, table.c.x + 5), (table.c.data, table.c.x + 10), ('x', 10) ] self.assert_compile( table.update(preserve_parameter_order=True).values(values), "UPDATE update_w_default SET ycol=(update_w_default.x + :x_1), " "data=(update_w_default.x + :x_2), x=:x" )
def test_update_ordered_parameters_override_onupdate(self): table = self.tables.update_w_default values = [ (table.c.y, table.c.x + 5), (table.c.data, table.c.x + 10), ("x", 10), ] self.assert_compile( table.update(preserve_parameter_order=True).values(values), "UPDATE update_w_default SET ycol=(update_w_default.x + :x_1), " "data=(update_w_default.x + :x_2), x=:x", )
def test_update_full_returning(self, connection): table = self.tables.tables connection.execute( table.insert(), [{ "persons": 5, "full": False }, { "persons": 3, "full": False }], ) result = connection.execute(table.update().where( table.c.persons > 2).values(full=True).returning( table.c.id, table.c.full)) eq_(result.fetchall(), [(1, True), (2, True)])
def test_update_returning(self, connection): table = self.tables.tables connection.execute( table.insert(), [{ "persons": 5, "full": False }, { "persons": 3, "full": False }], ) result = connection.execute(table.update().values( dict(full=True)).where(table.c.persons > 4).returning(table.c.id)) eq_(result.fetchall(), [(1, )]) result2 = connection.execute( select(table.c.id, table.c.full).order_by(table.c.id)) eq_(result2.fetchall(), [(1, True), (2, False)])