summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-11-25 19:39:17 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2015-11-25 19:39:17 -0500
commitab0874e893af4331b43055776aa5a44e4d6a995e (patch)
treed67aa52482a67935c0677b7bd119d16d01f823c1 /test/sql
parent1106bd3ff2705014c6884661336b271d17df1c38 (diff)
downloadsqlalchemy-ab0874e893af4331b43055776aa5a44e4d6a995e.tar.gz
- work from an "explicit is better than implicit" perspective
here and require a flag on update() to use parameter ordering rather than table ordering. more docs/changelog notes are needed
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_update.py46
1 files changed, 32 insertions, 14 deletions
diff --git a/test/sql/test_update.py b/test/sql/test_update.py
index 059c3ad6d..0b01071a8 100644
--- a/test/sql/test_update.py
+++ b/test/sql/test_update.py
@@ -183,13 +183,15 @@ class UpdateTest(_UpdateFromTestBase, fixtures.TablesTest, AssertsCompiledSQL):
'mytable.myid = hoho(:hoho_1) AND '
'mytable.name = :param_2 || mytable.name || :param_3')
- def test_update_12(self):
+ def test_update_ordered_parameters_1(self):
table1 = self.tables.mytable
- # Confirm that we can pass values as tuple value pairs
- values = (
+ # Confirm that we can pass values as list value pairs
+ # note these are ordered *differently* from table.c
+ values = [
+ (table1.c.name, table1.c.name + 'lala'),
(table1.c.myid, func.do_stuff(table1.c.myid, literal('hoho'))),
- (table1.c.name, table1.c.name + 'lala'))
+ ]
self.assert_compile(
update(
table1,
@@ -197,22 +199,26 @@ class UpdateTest(_UpdateFromTestBase, fixtures.TablesTest, AssertsCompiledSQL):
table1.c.name == literal('foo') +
table1.c.name +
literal('lala')),
+ preserve_parameter_order=True,
values=values),
'UPDATE mytable '
'SET '
- 'myid=do_stuff(mytable.myid, :param_1), '
- 'name=(mytable.name || :name_1) '
+ 'name=(mytable.name || :name_1), '
+ 'myid=do_stuff(mytable.myid, :param_1) '
'WHERE '
'mytable.myid = hoho(:hoho_1) AND '
'mytable.name = :param_2 || mytable.name || :param_3')
- def test_update_13(self):
+ def test_update_ordered_parameters_2(self):
table1 = self.tables.mytable
# Confirm that we can pass values as list value pairs
+ # note these are ordered *differently* from table.c
values = [
- (table1.c.myid, func.do_stuff(table1.c.myid, literal('hoho'))),
- (table1.c.name, table1.c.name + 'lala')]
+ (table1.c.name, table1.c.name + 'lala'),
+ ('description', 'some desc'),
+ (table1.c.myid, func.do_stuff(table1.c.myid, literal('hoho')))
+ ]
self.assert_compile(
update(
table1,
@@ -220,19 +226,31 @@ class UpdateTest(_UpdateFromTestBase, fixtures.TablesTest, AssertsCompiledSQL):
table1.c.name == literal('foo') +
table1.c.name +
literal('lala')),
- values=values),
+ preserve_parameter_order=True).values(values),
'UPDATE mytable '
'SET '
- 'myid=do_stuff(mytable.myid, :param_1), '
- 'name=(mytable.name || :name_1) '
+ 'name=(mytable.name || :name_1), '
+ 'description=:description, '
+ 'myid=do_stuff(mytable.myid, :param_1) '
'WHERE '
'mytable.myid = hoho(:hoho_1) AND '
'mytable.name = :param_2 || mytable.name || :param_3')
- def test_update_14(self):
+ def test_update_preserve_order_reqs_listtups(self):
+ table1 = self.tables.mytable
+ testing.assert_raises_message(
+ ValueError,
+ "When preserve_parameter_order is True, values\(\) "
+ "only accepts a list of 2-tuples",
+ table1.update(preserve_parameter_order=True).values,
+ {"description": "foo", "name": "bar"}
+ )
+
+ def test_update_ordereddict(self):
table1 = self.tables.mytable
- # Confirm that ordered dicts are treated as normal dicts
+ # Confirm that ordered dicts are treated as normal dicts,
+ # columns sorted in table order
values = util.OrderedDict((
(table1.c.name, table1.c.name + 'lala'),
(table1.c.myid, func.do_stuff(table1.c.myid, literal('hoho')))))