0

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

1 Answer 1

3

You need to commit the changes.

sqlite_cur.execute(sql_statement)
sqlite_conn.commit()
answered Sep 14, 2018 at 8:16
Sign up to request clarification or add additional context in comments.

1 Comment

or can add isolation_level=None like this sqlite3.connect('sqlitedb.db', isolation_level=None). Which does auto commit

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.