CSCI 305: Introduction to Database Systems

Homework 2: Work with SQLite3 Database Using Python

1. Objectives

After complete this assignment, students are expected to be able to use Python to

2. Overview

In this assignment, you will learn how to manipulate SQLite3 database through the use of Python programming language. The actual database task is relatively simple. You will create a database with a single table; insert a few records into the database; alter information in the database; and query information from the database. All are done from within a Python program.

You are given a working Python program that works with a SQLite3 database, including creating the database, inserting records into the database, altering database information, and querying database. Your task is to study the program and re-write this program to re-create the database you did in Homework 1, except that you only need to have the Books table. You do not need to import the information from a spreadsheet any more. You can directly store the book information in a Python list, and create the Books table from the Python list.

Use the web as your source of information if you are not sure how to do certain things. Please don't hesitate to talk to your instructor if you have questions.

3. Setup

Create a directory named "hw02" in your "csci305" directory under your git repo. Download the sample Python program and the database created by the program to your "hw02" directory.

Alternatively you may copy all relevant files from the Linux directory.

~csci305/2018-spring/student/hw/hw02/*

4. Your Work

As discussed in the Overview section, your work is to revise the Python program sqlite3_db.py to create a database containing the table of Books that is similar to what you did in Homework 1. The Books table should contain the following attributes.

Note that in Homework 1, some of us used variable names with double quotes. If you are comfortable with this notion, it is fine. If you prefer to use a more conventional variable name, you can use either the CamelCase notation or the more popular PEP 8 naming convention that uses lower case letters along with underscores. This link gives a more concise guideline from Google.

For your reference (or convenience), here is the books.csv file I generated when doing Homework 1.

You are given an example program csv2list.py that can read a CSV file and convert its content into a Python list. You may want to use this example in your program to read from the CSV file(s) and store the contents in Python list(s).

Note:

To make the grading a bit easier, please do the following.

5. Submission

You are to submit the following four files through your git repo.

  1. Revised and completed sqlite3_db.py;
  2. The database file created by your program. (See the notes immediately before the Submission section);
  3. A plain text file named README.txt briefly explain your experience in doing this work, any challenges, and any suggestions. A couple paragraphs should suffice.

6. References


Last modified: Tue Jan 30 20:20:55 EST 2018