From 8214a7e6660d4db94384176b8ed3650633cf4d25 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 11 Jun 2012 20:12:47 -0400 Subject: [PATCH] - [bug] Fixed bug affecting Py3K whereby string positional parameters passed to engine/connection execute() would fail to be interpreted correctly, due to __iter__ being present on Py3K string. [ticket:2503]. --- CHANGES | 7 +++++++ lib/sqlalchemy/engine/base.py | 4 ++-- test/aaa_profiling/test_zoomark.py | 3 +-- test/engine/test_execute.py | 33 ++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index dd21697f7e..0c17b2d30c 100644 --- a/CHANGES +++ b/CHANGES @@ -40,6 +40,13 @@ CHANGES The most prominently affected DBAPI is pyodbc. [ticket:2489] + - [bug] Fixed bug affecting Py3K whereby + string positional parameters passed to + engine/connection execute() would fail to be + interpreted correctly, due to __iter__ + being present on Py3K string. + [ticket:2503]. + - oracle - [bug] Added ROWID to oracle.*, [ticket:2483] diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index 11bd1f4b40..5254b9ba5f 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -1473,7 +1473,7 @@ class Connection(Connectable): elif len(multiparams) == 1: zero = multiparams[0] if isinstance(zero, (list, tuple)): - if not zero or hasattr(zero[0], '__iter__'): + if not zero or isinstance(zero[0], (list, tuple, dict)): return zero else: return [zero] @@ -1482,7 +1482,7 @@ class Connection(Connectable): else: return [[zero]] else: - if hasattr(multiparams[0], '__iter__'): + if isinstance(multiparams[0], (list, tuple, dict)): return multiparams else: return [multiparams] diff --git a/test/aaa_profiling/test_zoomark.py b/test/aaa_profiling/test_zoomark.py index a0336662d7..86baae22ec 100644 --- a/test/aaa_profiling/test_zoomark.py +++ b/test/aaa_profiling/test_zoomark.py @@ -377,8 +377,7 @@ class ZooMarkTest(fixtures.TestBase): def test_profile_2_insert(self): self.test_baseline_2_insert() - @profiling.function_call_count(3340, {'2.4': 2158, '2.7':3541, - '2.7+cextension':3317, '2.6':3564}) + @profiling.function_call_count(3333, {'2.4': 2358}) def test_profile_3_properties(self): self.test_baseline_3_properties() diff --git a/test/engine/test_execute.py b/test/engine/test_execute.py index 610f5e42b0..7ccd42b73f 100644 --- a/test/engine/test_execute.py +++ b/test/engine/test_execute.py @@ -79,6 +79,22 @@ class ExecuteTest(fixtures.TestBase): (6, 'donkey'), (7, 'sally'), ] + for multiparam, param in [ + (("jack", "fred"), {}), + ((["jack", "fred"],), {}) + ]: + res = conn.execute( + "select * from users where user_name=? or " + "user_name=? order by user_id", + *multiparam, **param) + assert res.fetchall() == [ + (1, 'jack'), + (2, 'fred') + ] + res = conn.execute("select * from users where user_name=?", + "jack" + ) + assert res.fetchall() == [(1, 'jack')] conn.execute('delete from users') go(testing.db) @@ -104,6 +120,23 @@ class ExecuteTest(fixtures.TestBase): res = conn.execute('select * from users order by user_id') assert res.fetchall() == [(1, 'jack'), (2, 'ed'), (3, 'horse'), (4, 'sally'), (5, None)] + for multiparam, param in [ + (("jack", "ed"), {}), + ((["jack", "ed"],), {}) + ]: + res = conn.execute( + "select * from users where user_name=%s or " + "user_name=%s order by user_id", + *multiparam, **param) + assert res.fetchall() == [ + (1, 'jack'), + (2, 'ed') + ] + res = conn.execute("select * from users where user_name=%s", + "jack" + ) + assert res.fetchall() == [(1, 'jack')] + conn.execute('delete from users') go(testing.db) conn = testing.db.connect() -- 2.47.2