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 project.py 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.
All of the code you write for this project must be in "project.py".
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 project.py will be considered academic dishonesty for these projects.
You may (and should) write additional functions and classes in "project.py" to perform the needed actions.
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):
CREATE TABLE INSERT INTO VALUES SELECT FROM ORDER BY UPDATE SET DELETE WHERE DISTINCT LEFT OUTER JOIN ON
'My dog''s name'->
"My dog's name".
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);
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:
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 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;
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';
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.
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.