Search code examples
python-3.xsqlitesql-insertexecutemany

Python3 | sqlite3: executemany() inserts nothing


I am trying to use sqlite3's executemany() to insert multiple values with Python3.

Code:

import sqlite3
conn = sqlite3.connect('rssnewsdata.db')
c = conn.cursor()

entries = [
    ('url1', 1234, 'title1', 'summary1', 'feedurl1'),
    ('url2', 1235, 'title2', 'summary2', 'feedurl2'),
    ('url3', 1236, 'title3', 'summary3', 'feedurl3'),
    ('url4', 1237, 'title4', 'summary4', 'feedurl4')
]

c.executemany('INSERT INTO entries VALUES (?, ?, ?, ?, ?)', entries)

The db file exists, the table exists, I can use Python3 to SELECT from it, so connecting to it is not a problem. The columns are of TEXT, INTEGER, TEXT, TEXT, TEXT type.

Python reports no errors. What is missing?


Solution

  • you need to

    conn.commit()
    

    after the insert.