-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
94 lines (80 loc) · 4.72 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import psycopg2
from psycopg2 import Error
try:
# Connect to an existing database
connection = psycopg2.connect(user="postgres",
password="4874651",
host="127.0.0.1",
port="5432",
database="IKU-OBE-alfa")
# Create a cursor to perform database operations
cursor = connection.cursor()
# Print PostgreSQL details
print("PostgreSQL server information")
print(connection.get_dsn_parameters(), "\n")
# Executing a SQL query
cursor.execute("SELECT version();")
# Fetch result
record = cursor.fetchone()
print("You are connected to - ", record, "\n")
except (Exception, Error) as error:
print("Error while connecting to PostgreSQL", error)
finally:
cursor.execute("CREATE TABLE Course\
(CourseID SERIAL PRIMARY KEY NOT NULL,\
CourseTag TEXT NOT NULL,\
CourseName TEXT NOT NULL,\
Year1 INT NOT NULL,\
Year2 INT NOT NULL,\
Semester TEXT NOT NULL);")
cursor.execute("CREATE TABLE Student\
(StuID SERIAL PRIMARY KEY NOT NULL,\
StuNo INT NOT NULL,\
Name TEXT NOT NULL,\
CourseID INT REFERENCES Course(CourseID) NOT NULL,\
CourseTag TEXT NOT NULL,\
Year1 INT NOT NULL,\
Year2 INT NOT NULL,\
Semester TEXT NOT NULL);")
cursor.execute("CREATE TABLE AssesWeight\
(AssesWeightID SERIAL PRIMARY KEY NOT NULL,\
CourseID INT REFERENCES Course(CourseID) NOT NULL,\
CourseTag TEXT NOT NULL,\
Year1 INT NOT NULL,\
Year2 INT NOT NULL,\
Semester TEXT NOT NULL,\
AssesType TEXT NOT NULL,\
AssesWeight INT NOT NULL);")
cursor.execute("CREATE TABLE QuestWeight\
(QuestWeightID SERIAL PRIMARY KEY NOT NULL,\
CourseID INT REFERENCES Course(CourseID) NOT NULL,\
CourseTag TEXT NOT NULL,\
Year1 INT NOT NULL,\
Year2 INT NOT NULL,\
Semester TEXT NOT NULL,\
AssesType TEXT NOT NULL,\
QuestNo INT NOT NULL,\
QuestWeight INT NOT NULL);")
cursor.execute("CREATE TABLE COPO\
(CourseID INT REFERENCES Course(CourseID) NOT NULL,\
CourseTag TEXT NOT NULL,\
Year1 INT NOT NULL,\
Year2 INT NOT NULL,\
Semester TEXT NOT NULL,\
CO INT NOT NULL,\
PO INT NOT NULL,\
Support INT NOT NULL);")
cursor.execute("CREATE TABLE Grade\
(GradeID SERIAL PRIMARY KEY NOT NULL,\
CourseID INT REFERENCES Course(CourseID) NOT NULL,\
StuNo INT NOT NULL,\
QuestWeightID INT REFERENCES QuestWeight(QuestWeightID) NOT NULL,\
Grade INT NOT NULL);")
connection.commit()
cursor.close()
connection.close()