homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: sqlite3.Cursor.execute expects sequence as second argument.
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.3, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Rename & explain sqlite3.Cursor.execute 'parameters' param
View: 20364
Assigned To: Nosy List: Andrew.Myers, BreamoreBoy, berker.peksag, ghaering, r.david.murray
Priority: normal Keywords:

Created on 2013年08月08日 22:22 by Andrew.Myers, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Messages (3)
msg194710 - (view) Author: Andrew Myers (Andrew.Myers) Date: 2013年08月08日 22:22
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]:
msg224599 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014年08月03日 00:32
@Andrew your words describe the Cursor execute method but your examples show the Connection execute method, can you clarify please.
msg262530 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016年03月27日 18:26
I think the name "parameters" causes a confusion here. It basically means
 def execute(sql, parameters):
not 
 def execute(sql, *parameters):
So ``con.execute('insert into foo values (?, ?)', (4, 5))`` is the correct usage of the API.
Also, this looks like a duplicate of issue 20364.
History
Date User Action Args
2022年04月11日 14:57:49adminsetgithub: 62891
2016年03月27日 18:26:25berker.peksagsetstatus: open -> closed

superseder: Rename & explain sqlite3.Cursor.execute 'parameters' param

nosy: + berker.peksag
messages: + msg262530
resolution: duplicate
stage: resolved
2014年08月03日 00:32:26BreamoreBoysetnosy: + ghaering, BreamoreBoy
messages: + msg224599
2013年08月08日 22:28:32r.david.murraysetnosy: + r.david.murray
2013年08月08日 22:22:52Andrew.Myerscreate

AltStyle によって変換されたページ (->オリジナル) /