MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / test_update_no_params

Method test_update_no_params

test/sql/test_update.py:127–176  ·  view source on GitHub ↗

test issue identified while doing #9721 UPDATE with empty VALUES but multiple tables would raise a NoneType error; fixed this to emit an empty "SET" the way a single table UPDATE currently does. both cases should probably raise CompileError, however this could

(self, values, twotable)

Source from the content-addressed store, hash-verified

125 @testing.variation("twotable", [True, False])
126 @testing.variation("values", ["none", "blank"])
127 def test_update_no_params(self, values, twotable):
128 """test issue identified while doing #9721
129
130 UPDATE with empty VALUES but multiple tables would raise a
131 NoneType error; fixed this to emit an empty "SET" the way a single
132 table UPDATE currently does.
133
134 both cases should probably raise CompileError, however this could
135 be backwards incompatible with current use cases (such as other test
136 suites)
137
138 """
139
140 table1 = self.tables.mytable
141 table2 = self.tables.myothertable
142
143 stmt = table1.update().where(table1.c.name == "jill")
144 if twotable:
145 stmt = stmt.where(table2.c.otherid == table1.c.myid)
146
147 if values.blank:
148 stmt = stmt.values()
149
150 if twotable:
151 if values.blank:
152 self.assert_compile(
153 stmt,
154 "UPDATE mytable SET FROM myothertable "
155 "WHERE mytable.name = :name_1 "
156 "AND myothertable.otherid = mytable.myid",
157 )
158 elif values.none:
159 self.assert_compile(
160 stmt,
161 "UPDATE mytable SET myid=:myid, name=:name, "
162 "description=:description FROM myothertable "
163 "WHERE mytable.name = :name_1 "
164 "AND myothertable.otherid = mytable.myid",
165 )
166 elif values.blank:
167 self.assert_compile(
168 stmt,
169 "UPDATE mytable SET WHERE mytable.name = :name_1",
170 )
171 elif values.none:
172 self.assert_compile(
173 stmt,
174 "UPDATE mytable SET myid=:myid, name=:name, "
175 "description=:description WHERE mytable.name = :name_1",
176 )
177
178 def test_update_literal_binds(self):
179 table1 = self.tables.mytable

Callers

nothing calls this directly

Calls 4

assert_compileMethod · 0.80
whereMethod · 0.45
updateMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected