0

i have problem with SQLite3 in Python (using PyCharm + Python 3.5 on W10). The insert doesn't work

import sqlite3
conn = sqlite3.connect("test.db")
c = conn.cursor()
c.execute("DROP TABLE Normal;") # to clean data
c.execute("CREATE TABLE Normal (Invoice INTEGER);")
c.execute("INSERT INTO Normal (Invoice) VALUES (24);")

If I run sqlite3.exe in the directory afterwards, open the db and write commands in cmd.exe console:

sqlite> .open test.db;
sqlite> select * from Normal;
sqlite> INSERT INTO Normal (Invoice) VALUES (24);
sqlite> select * from Normal;
24

The very same insert works. I am confused...

asked Nov 8, 2017 at 20:32
4
  • 1
    Are there any error messages? Commented Nov 8, 2017 at 20:34
  • Have you tried to do a COMMIT? Commented Nov 8, 2017 at 20:35
  • "Doesn't work" is not specific enough. Add details. Commented Nov 8, 2017 at 20:35
  • See about using the connection as a context manager Commented Nov 8, 2017 at 20:40

1 Answer 1

3

The python library of SQLITE3 is transactional, meaning that it doesn't commit to the database until you commit the changes.

after the INSERT INTO statement put the line:

conn.commit()
answered Nov 8, 2017 at 20:34
Sign up to request clarification or add additional context in comments.

Comments

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.