In this lab, you will demonstrate your ability to interact with SQL databases using Python's sqlite3 module. You will be acting as a Database Administrator (DBA).
Read SQLITE_DATABASE_TUTORIAL for Sqlite3 cheatsheet.
Total Points: 40
The lab is divided into two sections:
-
Mystery Database (20 pts): You are given a file
library.db(generated automatically when you run tests). You do not know the table names or columns. You must discover them and perform queries/updates. -
New System (20 pts): You must create a
finance.dbfrom scratch, design a schema, and handle complex Transactions (Commit/Rollback).
-
lab5_exercises.py: EDIT THIS FILE. This is where you write your code. -
test_lab5.py: Run this to check your score. DO NOT EDIT. -
SQLITE_DATABASE_TUTORIAL.md: Use this as a reference guide.
We use pytest to grade the lab. The testing script will automatically generate the database files required for the lab.
-
Open your terminal.
-
Run the following command:
pytest -v -s
(The
-vshows details,-sallows printed output to be seen) -
At the end of the test run, you will see a Score Summary calculated out of 40 points.
-
Easy (2 pts each): List items, Filter items, Count items, Get attribute.
-
Medium (3 pts each): Update stock, Add item, Delete item, Calculate Average.
-
Hard (5 pts each): * Create Schema (Create table/db).
-
Bulk Insert (Using
executemany). -
Transaction (Money Transfer with
commit). -
Undo (Simulate error and
rollback).
-
-
Complete the functions in
lab5_exercises.py. -
Ensure
pytestshows 40/40. -
Commit and Push to GitHub Classroom:
git add lab5_exercises.py git commit -m "Completed Lab 5" git push origin main