External Exam Download Resources Web Applications Games Recycle Bin

Connect to Bookshop Database

books.py

import sqlite3
db = sqlite3.connect('bookshop.db')
db.close()

    Core Activities:

  1. Run above code and make sure you get no error message.
  2. 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".
  3. Try adding a line of code to print a message to the console window after this program closes the database file, saying "connection closed".
  4. Extension Activities:

  5. 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.