pysqlite - simple problem

Fredrik Lundh fredrik at pythonware.com
Fri Sep 1 04:04:59 EDT 2006


John Machin wrote:
>> So this has to be something stupidly simple... but for the life of me I
>> can't see it.
>
> With the '?' paramstyle, the 2nd arg to cursor.execute() should be a
> *sequence* (typically a tuple) of the values that you are inserting.
>
> Tty this:
> cur.execute("INSERT INTO foo (id) VALUES (?)", (num, ))
>
> This is standard Python DBAPI stuff - you would probably get a similar
> response from other gadgets e.g. mySQLdb -- IOW it's not specific to
> pysqlite.

that mistake gives an entirely different error message, at least under 2.2.0
(which is the version shipped with 2.5):

>>> import sqlite3
>>> db = sqlite3.connect("foo.db")
>>> cur = db.cursor()
>>> cur.execute("CREATE TABLE foo (id INTEGER)")
<pysqlite2.dbapi2.Cursor object at 0x00B7CEF0>
>>> cur.execute("INSERT INTO foo (id) VALUES (?)", 200)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current
statement uses 1, and there are -1 supplied.
>>> cur.execute("INSERT INTO foo (id) VALUES (?)", [200])
<pysqlite2.dbapi2.Cursor object at 0x00B7CEF0>

(not sure "-1 arguments supplied" is any less confusing, though)

</F> 






More information about the Python-list mailing list