[pypy-commit] pypy default: test and fix for sqlite param container check

bdkearns noreply at buildbot.pypy.org
Thu Mar 7 10:02:24 CET 2013


Author: Brian Kearns <bdkearns at gmail.com>
Branch: 
Changeset: r62165:5103722a91c0
Date: 2013-03-07 04:00 -0500
http://bitbucket.org/pypy/pypy/changeset/5103722a91c0/

Log:	test and fix for sqlite param container check

diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -1110,8 +1110,11 @@
         num_params_needed = sqlite.sqlite3_bind_parameter_count(self._statement)
         if isinstance(params, (tuple, list)) or \
                 not isinstance(params, dict) and \
-                hasattr(params, '__len__') and hasattr(params, '__getitem__'):
-            num_params = len(params)
+                hasattr(params, '__getitem__'):
+            try:
+                num_params = len(params)
+            except TypeError:
+                num_params = -1
             if num_params != num_params_needed:
                 raise ProgrammingError("Incorrect number of bindings supplied. "
                                        "The current statement uses %d, and "
diff --git a/pypy/module/test_lib_pypy/test_sqlite3.py b/pypy/module/test_lib_pypy/test_sqlite3.py
--- a/pypy/module/test_lib_pypy/test_sqlite3.py
+++ b/pypy/module/test_lib_pypy/test_sqlite3.py
@@ -138,6 +138,9 @@
         def __getitem__(self, key):
             return 2
     con.execute('insert into foo(x) values (?)', seq())
+    del seq.__len__
+    with pytest.raises(_sqlite3.ProgrammingError):
+        con.execute('insert into foo(x) values (?)', seq())
     with pytest.raises(_sqlite3.ProgrammingError):
         con.execute('insert into foo(x) values (?)', {2:2})
     with pytest.raises(ValueError) as e:


More information about the pypy-commit mailing list