简体   繁体   中英

Simple python sqlite code cannot work. What is wrong?

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.

You need to commit the changes .

sqlite_cur.execute(sql_statement)
sqlite_conn.commit()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM