开发者

How to insert a large number of list entries into sqlite statements

开发者 https://www.devze.com 2023-01-22 23:09 出处:网络
Ok, I am using apsw with sqlite, and have a large list of ent开发者_开发知识库ries.Each entry contains a new row to be inserted. The number of entries is sometimes 20, sometimes 21. Since apsw support

Ok, I am using apsw with sqlite, and have a large list of ent开发者_开发知识库ries.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?


apsw cursors have an executemany method:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号