views:

39

answers:

1

Ok, I am using apsw with sqlite, and have a large list of entries.Each entry contains a new row to be inserted. The number of entries is sometimes 20, sometimes 21. Since apsw supports multiple sql statements in curser.execute(), I was wondering if there would be a less confusing way of inserting all my list entries into the database than just doing something like

for entry in foo:
    cursor.execute(INSERT OR UPDATE INTO database.main ("{0}".format(entry))

I want to do it in all one thread because sqlite auto-commits to the database each time the execute finishes. Is there an easier, more efficient, and less confusing way?

+1  A: 

apsw cursors have an executemany method:

cursor.executemany('INSERT OR UPDATE INTO database.main values (?)',foo)
unutbu