test that bound parameters between the UPDATE and FROM clauses order correctly in different SQL compilation scenarios.
(self, paramstyle)
| 991 | |
| 992 | @testing.variation("paramstyle", ["qmark", "format", "numeric"]) |
| 993 | def test_update_bound_ordering(self, paramstyle): |
| 994 | """test that bound parameters between the UPDATE and FROM clauses |
| 995 | order correctly in different SQL compilation scenarios. |
| 996 | |
| 997 | """ |
| 998 | table1 = self.tables.mytable |
| 999 | table2 = self.tables.myothertable |
| 1000 | sel = select(table2).where(table2.c.otherid == 5).alias() |
| 1001 | upd = ( |
| 1002 | table1.update() |
| 1003 | .where(table1.c.name == sel.c.othername) |
| 1004 | .values(name="foo") |
| 1005 | ) |
| 1006 | |
| 1007 | if paramstyle.qmark: |
| 1008 | dialect = default.StrCompileDialect(paramstyle="qmark") |
| 1009 | self.assert_compile( |
| 1010 | upd, |
| 1011 | "UPDATE mytable SET name=? FROM (SELECT " |
| 1012 | "myothertable.otherid AS otherid, " |
| 1013 | "myothertable.othername AS othername " |
| 1014 | "FROM myothertable " |
| 1015 | "WHERE myothertable.otherid = ?) AS anon_1 " |
| 1016 | "WHERE mytable.name = anon_1.othername", |
| 1017 | checkpositional=("foo", 5), |
| 1018 | dialect=dialect, |
| 1019 | ) |
| 1020 | elif paramstyle.format: |
| 1021 | self.assert_compile( |
| 1022 | upd, |
| 1023 | "UPDATE mytable, (SELECT myothertable.otherid AS otherid, " |
| 1024 | "myothertable.othername AS othername " |
| 1025 | "FROM myothertable " |
| 1026 | "WHERE myothertable.otherid = %s) AS anon_1 " |
| 1027 | "SET mytable.name=%s " |
| 1028 | "WHERE mytable.name = anon_1.othername", |
| 1029 | checkpositional=(5, "foo"), |
| 1030 | dialect=mysql.dialect(), |
| 1031 | ) |
| 1032 | elif paramstyle.numeric: |
| 1033 | dialect = default.StrCompileDialect(paramstyle="numeric") |
| 1034 | self.assert_compile( |
| 1035 | upd, |
| 1036 | "UPDATE mytable SET name=:1 FROM (SELECT " |
| 1037 | "myothertable.otherid AS otherid, " |
| 1038 | "myothertable.othername AS othername " |
| 1039 | "FROM myothertable " |
| 1040 | "WHERE myothertable.otherid = :2) AS anon_1 " |
| 1041 | "WHERE mytable.name = anon_1.othername", |
| 1042 | checkpositional=("foo", 5), |
| 1043 | dialect=dialect, |
| 1044 | ) |
| 1045 | else: |
| 1046 | paramstyle.fail() |
| 1047 | |
| 1048 | |
| 1049 | class UpdateFromCompileTest( |