I have this simple python sqlite code to execute a simple SQL statement.
import sqlite3
db_pathname = "./data/db.sqlite3"
sqlite_conn = sqlite3.connect(db_pathname)
sqlite_cur = sqlite_conn.cursor()
sql_statement = """INSERT OR REPLACE INTO table_infos (code, name) VALUES('XL2.SO', 'AGOS Pte')"""
sqlite_cur.execute(sql_statement)
I do not see a new record being added to the sqlite database after running the code. However, if I run the SQL statement manually using a sqlite tool called DB Browser, a new record is added.
I am using python 3.6 and sqlite3.
asked Sep 14, 2018 at 8:13
guagay_wk
28.3k64 gold badges202 silver badges311 bronze badges
1 Answer 1
You need to commit the changes.
sqlite_cur.execute(sql_statement)
sqlite_conn.commit()
answered Sep 14, 2018 at 8:16
Daniel Roseman
602k68 gold badges911 silver badges924 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
sjd
or can add
isolation_level=None like this sqlite3.connect('sqlitedb.db', isolation_level=None). Which does auto commitdefault