MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_binds_that_match_columns

Method test_binds_that_match_columns

test/sql/test_update.py:382–424  ·  test/sql/test_update.py::UpdateTest.test_binds_that_match_columns

test bind params named after column names replace the normal SET/VALUES generation. See also test_compiler.py::CrudParamOverlapTest

(self)

Source from the content-addressed store, hash-verified

380 )
381
382 def test_binds_that_match_columns(self):
383 class="st">"""test bind params named after column names
384 replace the normal SET/VALUES generation.
385
386 See also test_compiler.py::CrudParamOverlapTest
387
388 class="st">"""
389
390 t = table(class="st">"foo", column(class="st">"x"), column(class="st">"y"))
391
392 u = t.update().where(t.c.x == bindparam(class="st">"x"))
393
394 assert_raises(exc.CompileError, u.compile)
395
396 self.assert_compile(u, class="st">"UPDATE foo SET WHERE foo.x = :x", params={})
397
398 assert_raises(exc.CompileError, u.values(x=7).compile)
399
400 self.assert_compile(
401 u.values(y=7), class="st">"UPDATE foo SET y=:y WHERE foo.x = :x"
402 )
403
404 assert_raises(
405 exc.CompileError, u.values(x=7).compile, column_keys=[class="st">"x", class="st">"y"]
406 )
407 assert_raises(exc.CompileError, u.compile, column_keys=[class="st">"x", class="st">"y"])
408
409 self.assert_compile(
410 u.values(x=3 + bindparam(class="st">"x")),
411 class="st">"UPDATE foo SET x=(:param_1 + :x) WHERE foo.x = :x",
412 )
413
414 self.assert_compile(
415 u.values(x=3 + bindparam(class="st">"x")),
416 class="st">"UPDATE foo SET x=(:param_1 + :x) WHERE foo.x = :x",
417 params={class="st">"x": 1},
418 )
419
420 self.assert_compile(
421 u.values(x=3 + bindparam(class="st">"x")),
422 class="st">"UPDATE foo SET x=(:param_1 + :x), y=:y WHERE foo.x = :x",
423 params={class="st">"x": 1, class="st">"y": 2},
424 )
425
426 def test_labels_no_collision(self):
427 t = table(class="st">"foo", column(class="st">"id"), column(class="st">"foo_id"))

Callers

nothing calls this directly

Calls 8

tableFunction · 0.90
columnFunction · 0.90
bindparamFunction · 0.90
assert_raisesFunction · 0.90
assert_compileMethod · 0.80
whereMethod · 0.45
updateMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected