MCPcopy Index your code
hub / github.com/sqlalchemy/sqlalchemy / test_update_no_params

Method test_update_no_params

test/sql/test_update.py:129–178  ·  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

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