Programming Assignment 5 (Data Dictionary)

Sample figure

In this programming assignment, you will develop a Python program to keep track of data that is typically kept in a data dictionary of a database. In particular, we will keep track of relation names and attributes associated with relations.

A relational database consists of one or more relations. Each relation has a name and a list of attributes. Each attribute has a name, a type, and a boolean indicating if it is a "key" attribute or not.

A sample data dictionary is shown below:

	student(sno:INTEGER:KEY,sname:STRING,phone:STRING)
	course(cno:INTEGER:KEY,ctitle:STRING)
	enroll(sno:INTEGER:KEY,cno:INTEGER:KEY,grade:STRING)

We will use four Python Classes:

  1. Attribute.py: encapsulates information about a single attribute. The constructor method is shown below:
    	def __init__(self, an, at, ky):
    		self.aname = an
    		self.atype = at
    		self.key = ky
    
  2. Attributes.py: encapsulates information about ALL attributes. The individual attribute objects are stored in a Python list. The constructor method is shown below:
    	def __init__(self):
    		self.attributes = []
    
  3. Relation.py: encapsulates information about a single relation including its name and its list of attributes (the Attributes object). The constructor method is shown below:
    	def __init__(self, rname, attrs):
    		self.rname = rname
    		self.attributes = attrs
    
  4. Relations.py: encapsulates information about ALL relations in the data dictionary. This is stored inside a Python dictionary with relation name serving as the key.. The constructor method is shown below:
    	def __init__(self):
    		self.relations = {}
    

The program takes the name of an input file as command line argument. A sample input file is shown below:

$ more schema.dat
student,sno:i:y,sname:s:n,phone:s:n
course,cno:i:y,ctitle:s:n
enroll,sno:i:y,cno:i:y,grade:s:n

Each line in the file contains the name of a relation and a list of attributes, all separated by commas. Information about each attribute are separated by colons.

The following are skeleton files for you to use in the assignment:

Attribute.py
Attributes.py
Relation.py
Relations.py
DD.py

Sample run of the program is shown below:

$ python3 DD.py schema.dat

i. DEFINE RELATION SCHEME
m. MODIFY RELATION SCHEME
d. DELETE RELATION SCHEME
p. PRINT DATABASE SCHEME
q. QUIT

Enter your option (i rname, d rname, m rname, p, q): p

student(sno:INTEGER:KEY,sname:STRING,phone:STRING)
course(cno:INTEGER:KEY,ctitle:STRING)
enroll(sno:INTEGER:KEY,cno:INTEGER:KEY,grade:STRING)

i. DEFINE RELATION SCHEME
m. MODIFY RELATION SCHEME
d. DELETE RELATION SCHEME
p. PRINT DATABASE SCHEME
q. QUIT

Enter your option (i rname, d rname, m rname, p, q): i movie
Attributes: aname1:atype1:key1,aname2:atype2:key2:etc:
mid:i:y,mtitle:s:n,year:i:n

i. DEFINE RELATION SCHEME
m. MODIFY RELATION SCHEME
d. DELETE RELATION SCHEME
p. PRINT DATABASE SCHEME
q. QUIT

Enter your option (i rname, d rname, m rname, p, q): p

student(sno:INTEGER:KEY,sname:STRING,phone:STRING)
course(cno:INTEGER:KEY,ctitle:STRING)
enroll(sno:INTEGER:KEY,cno:INTEGER:KEY,grade:STRING)
movie(mid:INTEGER:KEY,mtitle:STRING,year:INTEGER)

i. DEFINE RELATION SCHEME
m. MODIFY RELATION SCHEME
d. DELETE RELATION SCHEME
p. PRINT DATABASE SCHEME
q. QUIT

Enter your option (i rname, d rname, m rname, p, q): m student
a aname:atype:key:pos, d aname: a age:i:n:4
Attribute age:i inserted!

i. DEFINE RELATION SCHEME
m. MODIFY RELATION SCHEME
d. DELETE RELATION SCHEME
p. PRINT DATABASE SCHEME
q. QUIT

Enter your option (i rname, d rname, m rname, p, q): p

student(sno:INTEGER:KEY,sname:STRING,phone:STRING,age:i)
course(cno:INTEGER:KEY,ctitle:STRING)
enroll(sno:INTEGER:KEY,cno:INTEGER:KEY,grade:STRING)
movie(mid:INTEGER:KEY,mtitle:STRING,year:INTEGER)

i. DEFINE RELATION SCHEME
m. MODIFY RELATION SCHEME
d. DELETE RELATION SCHEME
p. PRINT DATABASE SCHEME
q. QUIT

Enter your option (i rname, d rname, m rname, p, q): m student
a aname:atype:key:pos, d aname: d phone
Attribute phone deleted!

i. DEFINE RELATION SCHEME
m. MODIFY RELATION SCHEME
d. DELETE RELATION SCHEME
p. PRINT DATABASE SCHEME
q. QUIT

Enter your option (i rname, d rname, m rname, p, q): p

student(sno:INTEGER:KEY,sname:STRING,age:i)
course(cno:INTEGER:KEY,ctitle:STRING)
enroll(sno:INTEGER:KEY,cno:INTEGER:KEY,grade:STRING)
movie(mid:INTEGER:KEY,mtitle:STRING,year:INTEGER)

i. DEFINE RELATION SCHEME
m. MODIFY RELATION SCHEME
d. DELETE RELATION SCHEME
p. PRINT DATABASE SCHEME
q. QUIT

Enter your option (i rname, d rname, m rname, p, q): d course
Relation course has been deleted

i. DEFINE RELATION SCHEME
m. MODIFY RELATION SCHEME
d. DELETE RELATION SCHEME
p. PRINT DATABASE SCHEME
q. QUIT

Enter your option (i rname, d rname, m rname, p, q): p

student(sno:INTEGER:KEY,sname:STRING,age:i)
enroll(sno:INTEGER:KEY,cno:INTEGER:KEY,grade:STRING)
movie(mid:INTEGER:KEY,mtitle:STRING,year:INTEGER)

i. DEFINE RELATION SCHEME
m. MODIFY RELATION SCHEME
d. DELETE RELATION SCHEME
p. PRINT DATABASE SCHEME
q. QUIT

Enter your option (i rname, d rname, m rname, p, q): q


ASCSC1PP629W1:05-dd raj$ python3 DD.py schema.dat

i. DEFINE RELATION SCHEME
m. MODIFY RELATION SCHEME
d. DELETE RELATION SCHEME
p. PRINT DATABASE SCHEME
q. QUIT

Enter your option (i rname, d rname, m rname, p, q): p

student(sno:INTEGER:KEY,sname:STRING,age:STRING)
enroll(sno:INTEGER:KEY,cno:INTEGER:KEY,grade:STRING)
movie(mid:STRING:KEY,mtitle:STRING,year:STRING)

i. DEFINE RELATION SCHEME
m. MODIFY RELATION SCHEME
d. DELETE RELATION SCHEME
p. PRINT DATABASE SCHEME
q. QUIT

Enter your option (i rname, d rname, m rname, p, q): q

Bye!

$
TO SUBMIT: Attribute.py, Attributes.py, Relation.py, Relations.py, and DD.py.