Connect to Bookshop Database
books.py
import sqlite3 db = sqlite3.connect('bookshop.db') db.close()
- Run above code and make sure you get no error message.
- Try adding a line of code to print a message to the console window after this program first connects to the database file, saying "connection successful".
- Try adding a line of code to print a message to the console window after this program closes the database file, saying "connection closed".
- According to SQLite:
"When SQLite connection is closed explicitly by code or implicitly by program exit then any outstanding transaction is rolled back. (The rollback is actually done by the next program to open the database.) If there is no outstanding transaction open then nothing happens."
Considering this, do you think you need the
db.close()
, or is it simply good practise to do so? Discuss.
Core Activities:
Extension Activities: