1. Pypy
  2. Untitled project
  3. pypy

Commits

Brian Kearns  committed 5103722

test and fix for sqlite param container check

  • Participants
  • Parent commits 96d7103
  • Branches default

Comments (0)

Files changed (2)

File lib_pypy/_sqlite3.py

View file
  • Ignore whitespace
         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 "

File pypy/module/test_lib_pypy/test_sqlite3.py

View file
  • Ignore whitespace
         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: