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

Method test_binds_that_match_columns

test/sql/test_update.py:382–424  ·  view source on GitHub ↗

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