Kyle Anderson Kyle Anderson - 6 months ago 9
SQL Question

Sql Insert Statement not displaying anything

Im trying to insert a value in a python script, and im not getting any errors but it isnt displaying in the SQL file and I cant find any documentation that helps me understand why it isnt displaying.

Here is the code

#Connect the db to this python script
top10_connection = connect(database = 'top_ten.db')

#Get a cursor for the database which allows you to make
#and execute sql queries in this script
top_ten_db = top10_connection.cursor()

top_ten_db.execute("INSERT INTO Top_Ten (Rank) VALUES(1)")

top10_connection.close()

Answer

If you arent getting any traceback errors you are msot likely forgetting to commit changes to the db.

add top10_connection.commit() before you close the connection:

top10_connection = connect(database = 'top_ten.db')

#Get a cursor for the database which allows you to make
#and execute sql queries in this script

top_ten_db = top10_connection.cursor()

top_ten_db.execute("INSERT INTO Top_Ten (Rank) VALUES(1)")

top10_connection.commit()

top10_connection.close()
Comments