[issue18691] sqlite3.Cursor.execute expects sequence as second argument.

Andrew Myers report at bugs.python.org
Fri Aug 9 00:22:52 CEST 2013


New submission from Andrew Myers:

Sorry if this isn't the place for this, it is my first python bug report.

In PEP 249 Python database API specifiction 2.0 the Cursor execute method[1] is described as taking a variable number of arguments for substitution of '?' in the SQL string.  In the documentation of the sqlite3 module the Cursor execute method is also described this way[2].

However, the actual method requires a sequence, in the same way that the executemany method does.  This does not match the execute method in (for instance) pyodbc and means one cannot write code that is (fully) agnostic to the connection type.

[1]: http://www.python.org/dev/peps/pep-0249/#id15
[2]: http://docs.python.org/2/library/sqlite3.html#sqlite3.Cursor.execute

Pasted below is an example of this from python 3.3

In [1]: import sqlite3
In [2]: con = sqlite3.connect(":memory:")
In [4]: con.execute('create table foo (bar int, baz int)')
Out[4]: <sqlite3.Cursor at 0x7fe622286730>

In [5]: con.execute('insert into foo values (?, ?)', 4, 5)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-a0ea5e3e7a03> in <module>()
----> 1 con.execute('insert into foo values (?, ?)', 4, 5)

TypeError: function takes at most 2 arguments (3 given)

In [6]: con.execute('insert into foo values (?, ?)', (4, 5))
Out[6]: <sqlite3.Cursor at 0x7fe622201880>

In [7]:

----------
components: Library (Lib)
messages: 194710
nosy: Andrew.Myers
priority: normal
severity: normal
status: open
title: sqlite3.Cursor.execute expects sequence as second argument.
versions: Python 2.7, Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18691>
_______________________________________


More information about the Python-bugs-list mailing list