CS145 - Spring 2004
Introduction to Databases
Project Part 2: Oracle Features
Due Thursday May 13th
Warning: This is the first project part in which significant numbers of students will be putting significant load onto the Oracle system at the same time. Unfortunately it is possible the system will become much slower as the deadline approaches. We strongly suggest that you start early for your own benefit and convenience, and please be aware that we will not extend the on-time deadline because the system is slow.


Overview

This part of the project will introduce you to the PL/SQL database programming language, and to the constraints and triggers features in Oracle. You will also add a "current time" feature to your AuctionBase database.

Part A: Current Time

The original auction data that we provided for you in XML, which you translated into relations and loaded into your AuctionBase database in Project Part 1, represents a single point in time, specifically one second after midnight on December 20th, 2001 ("Dec-20-01 00:00:01").

To fully test your functionality, and to simulate the true operation of an online auction system in which auctions close as time passes, we suggest that you maintain a fictitious "current time" in your database. Add a new one-attribute table to your AuctionBase schema. This table should at all times contain a single row (i.e., a single value) representing the "current time," which can be updated to represent time passing. (It's up to you whether you also want to permit backward time-travel.) Initialize the table by inserting the current time for the initial state of your database: Dec-20-01 00:00:01.

Note: If you want to input and output dates in Oracle using the same format as in the original XML auction data files, issue the command:

  alter session set NLS_DATE_FORMAT='MON-DD-YY HH24:MI:SS';
For more information see the Oracle Dates and Times help document.

Create a file named time.sql that contains your commands for creating and initializing your current time table.

Part B: PL/SQL

Before getting started, please read the help document Using Oracle PL/SQL. Take particular note of the section on how to turn on debug messages when compiling PL/SQL procedures.

For this part, you will be writing a procedure that computes the "bidding closure" for a specified seller. More precisely, given a particular seller as a parameter, we wish to construct the set of all bidders who placed a bid on one of the seller's items, or (recursively) on an item being sold by any of the bidders in this set. For example, if we wish to compute the recursive bidding closure of seller Jennifer, and Beverly placed a bid on one of Jennifer's items, and Qi placed a bid on one of Beverly's items, then Beverly and Qi would be in the recursive bidding closure of Jennifer. Note that Jennifer is not part of this closure.

Your procedure, called compute_closure, should take as an argument the user id of a seller, and it should insert into a relation called my_closure the user id's of the individuals in the seller's bidding closure.

Please create a command file named closure.sql containing the command to create your closure relation, your PL/SQL procedure, and a command for invoking your procedure with some parameter. To facilitate the grading process, your closure.sql file must have the following format:

    drop procedure compute_closure;
    drop table my_closure;

    create table my_closure  ( ... );

    create procedure compute_closure ( ... )
    ...
    end;
    .
    run;

    begin
        compute_closure( ... );
    end;
    .
    run;

    select count(*) from my_closure;

    drop procedure compute_closure;
    drop table my_closure;

    quit;
The DROP commands are for cleaning up before and after you run your procedure. You should fill in the details of creating your closure relation, the actual procedure, and calling your procedure. Be sure to test your procedure thoroughly.

Correctness check: When you run your procedure for seller 'westbur' using the large data set, your bidding closure should contain 87 rows.

Part C: Constraints and Triggers

Constraints and triggers are covered in your textbook readings and are the topic of lecture on May 5th. Before getting started with Part C, please also read the Oracle help document Constraints and Triggers.

Please be very careful to note that constraints and triggers as supported in Oracle do not conform to the SQL-99 standard, the lecture notes, or the textbook. You will need to read the help document carefully.

If the data in your AuctionBase system at a given point in time represents a correct state of the real world, a number of constraints are expected to hold. To get you started, here are a few possible examples, some of which depend on a particular schema:

Here is what you need to do:

A note about transactions

This is the first time you will be doing significant updating to a large Oracle database. Assuming you want your database updates to persist, you may need to think just a little bit about transactions. Transactions are covered in your textbook readings and are the topic of lecture on May 10th. Please read the section on Transactions in the Oracle 9i SQL help document.


Having trouble?

If you run into difficulties, before contacting the course staff please consult the Project Part 2 FAQ Page. We will keep it up-to-date with answers to common questions.

What to submit

Your submission directory should contain only the following files :

time.sql Command file for creating and initializing the time table as specified in Part A
closure.sql Command file for PL/SQL as specified in Part B
constraints.txt Constraints file as specified in Part C
referential.sql Command file for a referential integrity constraint
check.sql Command file for a check constraint
trigger1.sql Command file for a first trigger-based constraint
trigger2.sql Command file for a second trigger-based constraint

One exception is that you may submit additional referential, check, and trigger command files as described earlier.

Important: If you decided to change your database schema while doing this part of the project, you must also resubmit ALL of the relevant files from Project Part 1: parser, Makefile, runParser script, control files, etc.. Refer back to the Project Part 1 Specification for details on the files to submit.

As usual, from your submission directory execute the script:

  /afs/ir/class/cs145/bin/submit-project
You may resubmit as many times as you like, however only the latest submission and timestamp are saved, and those are what we will use for grading your work and determining late penalties. Submissions via email will not be accepted.

Note: Points will be deducted if you do not follow the submission procedures exactly as specified, including which files to include (and which not to include), file naming, and file contents. Remember to allow sufficient time to prepare your submission once your work is complete.