PEP 249 (database api) -- executemany() with iterable?
Jon Clements
joncle at googlemail.com
Wed Oct 13 08:26:30 EDT 2010
On 12 Oct, 20:21, "J. Gerlach" <gerlach_jo... at web.de> wrote:
> 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_
What happens if you do itertools.repeat(0) instead of xrange(100) ?
More information about the Python-list
mailing list