6

I have the following code:

import sqlite3

con = sqlite3.connect("testDB")
cur = con.cursor()

#cur.execute('CREATE TABLE test_table (id integer primary key, data text)')
cur.execute('INSERT INTO test_table VALUES (?, ?)', (76, 'MyData'))

when I run this script it does not update table. But when I do the same insertion using sqlite3 commandline in Linux, it updates. Why is it so or there anything I am making wrong?

2 Answers 2

12
# Save (commit) the changes
con.commit()
Sign up to request clarification or add additional context in comments.

2 Comments

con.commit() this should be done after everything is finished, or can I commit after each con.execute() statement???
If another program want to see the data immediately, you should commit immediately. Otherwise you can commit at the end.
1

Did you try commiting after the insert clause?

2 Comments

con.commit() work but con.commit() this should be done after everything is finished, or can I commit after each con.execute() statement??? what is the main purpos of commit?
the 'commit' is to finish all the alteration in your table...but if you want back at the last status you use the 'rollback clause'

Your Answer

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.