diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-10-23 01:08:02 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-10-23 01:08:02 +0000 |
| commit | a43a0e8b68c28b72404e85e4b4e8999443dd3fc5 (patch) | |
| tree | f203e49eb40aaa6858eb969f625eeb899ac9c3c6 /test/sql/test_select.py | |
| parent | 9ae821ee660a2d03cae591798c05cfdbd8bb3ca6 (diff) | |
| download | sqlalchemy-a43a0e8b68c28b72404e85e4b4e8999443dd3fc5.tar.gz | |
- insert() and update() constructs can now embed bindparam()
objects using names that match the keys of columns. These
bind parameters will circumvent the usual route to those
keys showing up in the VALUES or SET clause of the generated
SQL. [ticket:1579]
Diffstat (limited to 'test/sql/test_select.py')
| -rw-r--r-- | test/sql/test_select.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/sql/test_select.py b/test/sql/test_select.py index 3dc09c9df..1db2559bc 100644 --- a/test/sql/test_select.py +++ b/test/sql/test_select.py @@ -1574,7 +1574,35 @@ class CRUDTest(TestBase, AssertsCompiledSQL): s = select([table2.c.othername], table2.c.otherid == table1.c.myid) u = table1.delete(table1.c.name==s) self.assert_compile(u, "DELETE FROM mytable WHERE mytable.name = (SELECT myothertable.othername FROM myothertable WHERE myothertable.otherid = mytable.myid)") + + def test_binds_that_match_columns(self): + """test bind params named after column names replace the normal SET/VALUES generation.""" + + t = table('foo', column('x'), column('y')) + u = t.update().where(t.c.x==bindparam('x')) + + self.assert_compile(u, "UPDATE foo SET y=:y WHERE foo.x = :x") + self.assert_compile(u, "UPDATE foo SET WHERE foo.x = :x", params={}) + self.assert_compile(u.values(x=7), "UPDATE foo SET x=:x WHERE foo.x = :x") + self.assert_compile(u.values(y=7), "UPDATE foo SET y=:y WHERE foo.x = :x") + self.assert_compile(u.values(x=7), "UPDATE foo SET x=:x, y=:y WHERE foo.x = :x", params={'x':1, 'y':2}) + self.assert_compile(u, "UPDATE foo SET y=:y WHERE foo.x = :x", params={'x':1, 'y':2}) + + self.assert_compile(u.values(x=3 + bindparam('x')), "UPDATE foo SET x=(:param_1 + :x) WHERE foo.x = :x") + self.assert_compile(u.values(x=3 + bindparam('x')), "UPDATE foo SET x=(:param_1 + :x) WHERE foo.x = :x", params={'x':1}) + self.assert_compile(u.values(x=3 + bindparam('x')), "UPDATE foo SET x=(:param_1 + :x), y=:y WHERE foo.x = :x", params={'x':1, 'y':2}) + + i = t.insert().values(x=3 + bindparam('x')) + self.assert_compile(i, "INSERT INTO foo (x) VALUES ((:param_1 + :x))") + self.assert_compile(i, "INSERT INTO foo (x, y) VALUES ((:param_1 + :x), :y)", params={'x':1, 'y':2}) + + i = t.insert().values(x=3 + bindparam('x2')) + self.assert_compile(i, "INSERT INTO foo (x) VALUES ((:param_1 + :x2))") + self.assert_compile(i, "INSERT INTO foo (x) VALUES ((:param_1 + :x2))", params={}) + self.assert_compile(i, "INSERT INTO foo (x, y) VALUES ((:param_1 + :x2), :y)", params={'x':1, 'y':2}) + self.assert_compile(i, "INSERT INTO foo (x, y) VALUES ((:param_1 + :x2), :y)", params={'x2':1, 'y':2}) + class InlineDefaultTest(TestBase, AssertsCompiledSQL): def test_insert(self): m = MetaData() |
