test that bound parameters between the UPDATE and FROM clauses order correctly in different SQL compilation scenarios.
(self, paramstyle)
| 966 | |
| 967 | @testing.variation("paramstyle", ["qmark", "format", "numeric"]) |
| 968 | def test_update_bound_ordering(self, paramstyle): |
| 969 | """test that bound parameters between the UPDATE and FROM clauses |
| 970 | order correctly in different SQL compilation scenarios. |
| 971 | |
| 972 | """ |
| 973 | table1 = self.tables.mytable |
| 974 | table2 = self.tables.myothertable |
| 975 | sel = select(table2).where(table2.c.otherid == 5).alias() |
| 976 | upd = ( |
| 977 | table1.update() |
| 978 | .where(table1.c.name == sel.c.othername) |
| 979 | .values(name="foo") |
| 980 | ) |
| 981 | |
| 982 | if paramstyle.qmark: |
| 983 | dialect = default.StrCompileDialect(paramstyle="qmark") |
| 984 | self.assert_compile( |
| 985 | upd, |
| 986 | "UPDATE mytable SET name=? FROM (SELECT " |
| 987 | "myothertable.otherid AS otherid, " |
| 988 | "myothertable.othername AS othername " |
| 989 | "FROM myothertable " |
| 990 | "WHERE myothertable.otherid = ?) AS anon_1 " |
| 991 | "WHERE mytable.name = anon_1.othername", |
| 992 | checkpositional=("foo", 5), |
| 993 | dialect=dialect, |
| 994 | ) |
| 995 | elif paramstyle.format: |
| 996 | self.assert_compile( |
| 997 | upd, |
| 998 | "UPDATE mytable, (SELECT myothertable.otherid AS otherid, " |
| 999 | "myothertable.othername AS othername " |
| 1000 | "FROM myothertable " |
| 1001 | "WHERE myothertable.otherid = %s) AS anon_1 " |
| 1002 | "SET mytable.name=%s " |
| 1003 | "WHERE mytable.name = anon_1.othername", |
| 1004 | checkpositional=(5, "foo"), |
| 1005 | dialect=mysql.dialect(), |
| 1006 | ) |
| 1007 | elif paramstyle.numeric: |
| 1008 | dialect = default.StrCompileDialect(paramstyle="numeric") |
| 1009 | self.assert_compile( |
| 1010 | upd, |
| 1011 | "UPDATE mytable SET name=:1 FROM (SELECT " |
| 1012 | "myothertable.otherid AS otherid, " |
| 1013 | "myothertable.othername AS othername " |
| 1014 | "FROM myothertable " |
| 1015 | "WHERE myothertable.otherid = :2) AS anon_1 " |
| 1016 | "WHERE mytable.name = anon_1.othername", |
| 1017 | checkpositional=("foo", 5), |
| 1018 | dialect=dialect, |
| 1019 | ) |
| 1020 | else: |
| 1021 | paramstyle.fail() |
| 1022 | |
| 1023 | |
| 1024 | class FromDMLColumnTest( |