This project will be extending the "project" module, which solves Project 2, and emulates the behaviour of the built in module, "sqlite3". Your module will be able to execute SQL statements corresponding to: (from Project 2) creating tables, inserting rows, and selecting rows; (and adding) various syntax improvements, updating and deleting rows, joins and the distinct keyword.

You should probably copy the file you submitted to Project 2, or build off the instructor's Project 2 solution. Note: you are responsible for understanding every line of code in your submissions, even if that code was written by the instructor.

What you need to do

All of the code you write for this project must be in "".

There is no need to write any database output to any files. Persistence will be covered in a later project. Each test will be done on a clean, empty database.

Your program is allowed to use any built in modules of python, with the exception of sqlite3. sqlite3 is the reference implementation for this project, your output will be compared against it for correctness. Importing the sqlite3 module in will be considered academic dishonesty for these projects.

You may (and should) write additional functions and classes in "" to perform the needed actions.

SQL Keywords

All SQL keywords will be in ALL_CAPS. For this project, the SQL keywords you need to handle are as follows (red are new for this project):


New SQL Syntax

Extensions over Project 2

  • Single quoted strings may have single quotes in them (escaped with a preceding single quote), you need to store and return the python string after removing this escaping. Example: 'My dog''s name' -> "My dog's name".
  • Any time a column name is used it may be qualified with a table name ("id" is the same thing as "" if the table being SELECT'ed is "students").
  • The "*" column name may be qualified or included as one of multiple columns (SELECT *, name ..., SELECT student.*, name ...).


The INSERT INTO statement can specify the columns and order of the VALUES being inserted: INSERT INTO students (id, name) VALUES ... If not all the columns of a table are specified, the absent columns will have NULL inserted. Multiple rows can be inserted with a single INSERT INTO statement: INSERT INTO students (name, grade) VALUES ('Josh', 3.7), ('Tyler', 2.5), ('Hangchen', 3.9);

WHERE clause

SELECT (as well as, UPDATE and DELETE) statements can have a WHERE clause that specifies what rows should be processed. SELECT * WHERE id > 4; To make things easier, all WHERE clauses will be in this form: WHERE column_name operator value The column_name may be qualified. The operator will be one of: >, <, =, !=, IS NOT, IS. The value will be a constant (not a different column or expression). There won't be any parentheses, ANDs or ORs in the projects.

DELETE statement

DELETE works much like UPDATE, but instead removes all rows from a table, (unless a WHERE clause is added, in that case only removes the rows which pass the predicate). DELETE FROM students; DELETE FROM students WHERE id > 4;

UPDATE statement

You will need to add the UPDATE statement: UPDATE table_name SET col1 = value1, col2 = value2; An UPDATE statement changes the associated columns to the value. For simplicity, the value will always be a constant. If a WHERE clause is added, only those rows will be updated (see above). UPDATE student SET grades=4.0 WHERE name = 'Josh';

DISTINCT keyword

The DISTINCT keyword specifies you only want the unique values (no duplicates). For simplicity, we the tests will only use the DISTINCT keyword with a single output column. Example: SELECT DISTINCT column_name FROM ... ORDER BY column_name;


The LEFT OUTER JOIN is the only join you need to implement for this project. If will be of the form: SELECT "columns" FROM "table_a" LEFT OUTER JOIN "table_b" ON "column from table_a" = "column from table_b" ORDER BY "columns"; As shown above, the ON clause will always match on equality with a column from the left table then the right table. For simplicity, all column names will be qualified in queries involving joins.