PEP 249 (database api) -- executemany() with iterable?

J. Gerlach gerlach_joerg at web.de
Tue Oct 12 15:21:26 EDT 2010


Am 12.10.2010 17:10, schrieb Roy Smith:

> [A]re there any plans to update the api to allow an iterable instead of
> a sequence?

sqlite3 (standard library, python 2.6.6., Windows 32Bit) does that already::

import sqlite3 as sql

connection = sql.connect(":memory:")

cursor = connection.execute("""
    CREATE TABLE test (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
    text TEXT)
    ;""")
connection.commit()
cursor.executemany("""
    INSERT INTO test (text) VALUES ( ? );
    """,
    # A generator expression - delivers one row at a time
    ( ("hello nr %03d!" % i,) for i in xrange(100)))
connection.commit()
cursor.execute("SELECT * FROM test")

for id_, text in cursor.fetchall():
    print text, id_



More information about the Python-list mailing list