This question is a continuation of the Lab 3 and 4 questions. You will be able to continue working with the script you submitted before, or with the solution posted on the course website. You can find the necessary background, as well as the requirements of the Lab 3 and 4 questions on the previous page. The following assumes you are familiar with Labs 3 and 4.
For this test, you can assume that all database files your script will be tested with will have correct format.
For your convenience, you can download the sample database used in Labs 3 and 4 here.
lt1m.sh
in your favourite editor
so that it implements the functionality described in the Requirements
section below.
submit 2031 LT1M lt1m.sh
submit
command can be viewed by
typing man submit
. In addition to the commands introduced in Labs 3 and 4, your script must implement the following command:
delrel rel output.txt threshold
The expected behaviour is the following:
If the database has not been set by a successful setdb
command, then your script must respond with
Database has not been set.
followed by a new prompt.
If there are less than two arguments, your script must respond with
Missing arguments.
followed by a new prompt.
If the first argument does not correspond to a relation in the database file, your script must respond with
Relation rel does not exist.
followed by a new prompt.
If a file whose name matches the second argument exists already, your script must respond with something like
File output.txt exists. No output created.
followed by a new prompt.
If there are only two arguments, your script must create a new file whose name is the second argument and it contains all lines in the database except for the ones that refer to the relation specified by the first argument. You can assume that your script always has permissions to create the output file. Your script must also output to the standard output a message such as the following
Added 5 lines to file output.txt
If there is a third argument, you can assume that it will always be an integer number. If such an argument exists, your script should create the output file as described above only if the cardinality of the relation is larger than the threshold indicated by the third argument. If the file is not created, your script must output to the standard output a message such as the following
Cardinality of relation rel too small.
Your script must ignore any further arguments to
delrel
without warning the user.
Following is a sample run that shows the expected behaviour of the script.
% lt1f.sh Grock- hello Unrecognized command. Grock- setdb Missing Argument. Grock- setdbb example.txt Unrecognized command. Grock- delrel inherit inheritance.txt Database has not been set. Grock- setdb example.txt Database set to example.txt Grock- delrel Missing Arguments. Grock- delrel inherit Missing Arguments. Grock- delrel rel output.txt Relation rel does not exist. Grock- delrel inherit output_sample_run.fout Added 2 lines to file output_sample_run.fout Grock- delrel inherit output_sample_run.fout File output_sample_run.fout exists. No output created. Grock- delrel inherit output.txt 3 Cardinality of relation inherit too small. Grock- quit % cat output_sample_run.fout implement class3 interface1 aggregate class3 class5 %