2

I am attempting to use sqlite3 through python commands in Visual Code Studio. After importing sqlite3, here is my code:

connection = sqlite3.connect("test.db")
crsr = connection.cursor()
crsr.execute("CREATE TABLE list (id INTEGER PRIMARY KEY, name TEXT);")
crsr.execute("INSERT INTO list VALUES(1, 'value1');")

The program runs fine with no errors. When I open the database in DB browser, I see that the table list has been successfully created with the columns I specified. But when I actually view the SQL data, no values are in the table.

Clearly, I am successfully connecting to DB Browser since I'm able to make a table- but why is my data not inserting into it?

1
  • 2
    Also do connection.commit() after your INSERT statement. Commented Dec 31, 2019 at 18:26

1 Answer 1

1

Creating the table is a DDL action, which doesn't need committing. Inserting data, on the other hand, is a DML operation, and you need to explicitly commit it after it completes:

connection.commit()
Sign up to request clarification or add additional context in comments.

Comments

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.