diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-10-09 17:18:00 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-10-09 17:18:00 -0400 |
commit | 58ad3b5ed78249f1faf48774bf6dedd424a1f435 (patch) | |
tree | 46f10805d70064abfc405f49035d7c1e4e6648d8 /test/sql/test_update.py | |
parent | 78a7bbdb3b0906a35528bdc829a08f0644d6fd7b (diff) | |
parent | 44e5a31ccee5335962602327132a4196fb1c7911 (diff) | |
download | sqlalchemy-pr200.tar.gz |
Merge remote-tracking branch 'origin/pr/200' into pr200pr200
Diffstat (limited to 'test/sql/test_update.py')
-rw-r--r-- | test/sql/test_update.py | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/test/sql/test_update.py b/test/sql/test_update.py index 58c86613b..059c3ad6d 100644 --- a/test/sql/test_update.py +++ b/test/sql/test_update.py @@ -4,6 +4,7 @@ from sqlalchemy.dialects import mysql from sqlalchemy.engine import default from sqlalchemy.testing import AssertsCompiledSQL, eq_, fixtures from sqlalchemy.testing.schema import Table, Column +from sqlalchemy import util class _UpdateFromTestBase(object): @@ -165,6 +166,77 @@ class UpdateTest(_UpdateFromTestBase, fixtures.TablesTest, AssertsCompiledSQL): table1.c.name: table1.c.name + 'lala', table1.c.myid: func.do_stuff(table1.c.myid, literal('hoho')) } + + self.assert_compile( + update( + table1, + (table1.c.myid == func.hoho(4)) & ( + table1.c.name == literal('foo') + + table1.c.name + + literal('lala')), + values=values), + 'UPDATE mytable ' + 'SET ' + 'myid=do_stuff(mytable.myid, :param_1), ' + 'name=(mytable.name || :name_1) ' + 'WHERE ' + 'mytable.myid = hoho(:hoho_1) AND ' + 'mytable.name = :param_2 || mytable.name || :param_3') + + def test_update_12(self): + table1 = self.tables.mytable + + # Confirm that we can pass values as tuple value pairs + values = ( + (table1.c.myid, func.do_stuff(table1.c.myid, literal('hoho'))), + (table1.c.name, table1.c.name + 'lala')) + self.assert_compile( + update( + table1, + (table1.c.myid == func.hoho(4)) & ( + table1.c.name == literal('foo') + + table1.c.name + + literal('lala')), + values=values), + 'UPDATE mytable ' + 'SET ' + 'myid=do_stuff(mytable.myid, :param_1), ' + 'name=(mytable.name || :name_1) ' + 'WHERE ' + 'mytable.myid = hoho(:hoho_1) AND ' + 'mytable.name = :param_2 || mytable.name || :param_3') + + def test_update_13(self): + table1 = self.tables.mytable + + # Confirm that we can pass values as list value pairs + values = [ + (table1.c.myid, func.do_stuff(table1.c.myid, literal('hoho'))), + (table1.c.name, table1.c.name + 'lala')] + self.assert_compile( + update( + table1, + (table1.c.myid == func.hoho(4)) & ( + table1.c.name == literal('foo') + + table1.c.name + + literal('lala')), + values=values), + 'UPDATE mytable ' + 'SET ' + 'myid=do_stuff(mytable.myid, :param_1), ' + 'name=(mytable.name || :name_1) ' + 'WHERE ' + 'mytable.myid = hoho(:hoho_1) AND ' + 'mytable.name = :param_2 || mytable.name || :param_3') + + def test_update_14(self): + table1 = self.tables.mytable + + # Confirm that ordered dicts are treated as normal dicts + values = util.OrderedDict(( + (table1.c.name, table1.c.name + 'lala'), + (table1.c.myid, func.do_stuff(table1.c.myid, literal('hoho'))))) + self.assert_compile( update( table1, |