-
Notifications
You must be signed in to change notification settings - Fork 0
/
projectProcedures.sql
173 lines (141 loc) · 4.89 KB
/
projectProcedures.sql
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
use vr2m;
/* 4. View available Projects */
DROP PROCEDURE IF EXISTS showAvailCourseWork;
DELIMITER $$
CREATE PROCEDURE showAvailCourseWork(stuUsername varchar(20), type char(2))
BEGIN
SELECT eCourseNum, eCRN, Name, Assign_date, Due_date, eDescription
FROM COURSE_WORK JOIN COURSES_ENROLLED JOIN COURSES_THIS_SEM as cc ON eCRN=sCRN AND eSectionNum=sSectionNum AND sCRN = cc.CRN
WHERE sUserName = stuUsername AND Work_type = type;
END $$
DELIMITER ;
DROP PROCEDURE IF EXISTS showAllAvailCourseWork;
DELIMITER $$
CREATE PROCEDURE showAllAvailCourseWork(stuUsername varchar(20))
BEGIN
SELECT eCourseNum, eCRN, Name, Assign_date, Due_date, eDescription
FROM COURSE_WORK JOIN COURSES_ENROLLED JOIN COURSES_THIS_SEM as cc ON eCRN=sCRN AND eSectionNum=sSectionNum AND sCRN = cc.CRN
WHERE sUserName = stuUsername;
END $$
DELIMITER ;
/* 5. View active Projects */
DROP PROCEDURE IF EXISTS showActiveCourseWork;
DELIMITER $$
CREATE PROCEDURE showActiveCourseWork(stuUsername varchar(20), type char(2))
BEGIN
SELECT eCourseNum, eCRN, Name, Assign_date, Due_date, eDescription
FROM COURSE_WORK JOIN COURSES_ENROLLED JOIN COURSES_THIS_SEM as cc ON eCRN=sCRN AND eSectionNum=sSectionNum AND sCRN = cc.CRN
WHERE sUserName = stuUsername AND Work_type = type AND Assign_date <= CURDATE() AND Due_date >= CURDATE();
END $$
DELIMITER ;
DROP PROCEDURE IF EXISTS showAllActiveCourseWork;
DELIMITER $$
CREATE PROCEDURE showAllActiveCourseWork(stuUsername varchar(20))
BEGIN
SELECT eCourseNum, eCRN, Name, Assign_date, Due_date, eDescription
FROM COURSE_WORK JOIN COURSES_ENROLLED JOIN COURSES_THIS_SEM as cc ON eCRN=sCRN AND eSectionNum=sSectionNum AND sCRN = cc.CRN
WHERE sUserName = stuUsername AND Assign_date <= CURDATE() AND Due_date >= CURDATE();
END $$
DELIMITER ;
/* 8. Add coursework */
/* Example :
call addCourseWork('CSCI 4560', 'Survey1', '001', 'Survey.txt', '2015-11-17', '2015-12-10', 'SV');
call addCourseWork( '4560','Survey1','001','Survey.txt','2015-11-17','2015-12-10','SV')
*/
DROP PROCEDURE IF EXISTS addCourseWork;
DELIMITER $$
CREATE PROCEDURE addCourseWork( cNum varchar(20), cName varchar(20), sNum varchar(3), eDes varchar(50), aDate date, dDate date, wtype varchar(2))
BEGIN
INSERT INTO COURSE_WORK VALUES (cName, (
SELECT CRN
FROM COURSES_THIS_SEM
WHERE eCourseNum=cNum AND SectionNum=sNum
),
sNum, eDes, aDate, dDate, wtype);
END $$
DELIMITER ;
/* 9. Edit assign and due date */
/* Example :
call editAssignDueDate('ResearchPaper1', '81159', '2015-9-1', '2015-12-10');
*/
DROP PROCEDURE IF EXISTS editAssignDueDate;
DELIMITER $$
CREATE PROCEDURE editAssignDueDate(cName varchar(20), c_crn varchar(5), aDate date, dDate date)
BEGIN
UPDATE COURSE_WORK
SET Assign_date = aDate, Due_date = dDate
WHERE Name = cName AND eCRN = c_crn;
END $$
DELIMITER ;
/* 11. View Coursework of all courses taught by the instructor */
/* Example :
call courseWorkOfInstructor('zhi_ins');
*/
DROP PROCEDURE IF EXISTS courseWorkOfInstructor;
DELIMITER $$
CREATE PROCEDURE courseWorkOfInstructor(IN InsUserName varchar(20))
BEGIN
SELECT cc.eCourseNum as CourseNum, Name, eCRN, eSectionNum, eDescription, Assign_date, Due_date, Work_type
FROM COURSE_WORK JOIN (
SELECT tCRN FROM COURSES_TEACHING
WHERE tUsername = InsUserName
) as dT
JOIN COURSES_THIS_SEM as cc
ON eCRN = dT.tCRN AND tCRN=cc.CRN
ORDER BY Due_date;
END $$
DELIMITER ;
/* 12. & 13. Delete coursework*/
/* Example :
call deleteCourseWork('ResearchPaper1', '81159');
*/
DROP PROCEDURE IF EXISTS deleteCourseWork;
DELIMITER $$
CREATE PROCEDURE deleteCourseWork( CourseWorkName varchar(20), crnNum varchar(5))
BEGIN
DELETE from COURSE_WORK
WHERE Name = CourseWorkName AND eCRN = crnNum;
END $$
DELIMITER ;
/* 16. Add email alert */
/* Example :
call courseWorkOfInstructor('zhi_ins');
*/
DROP PROCEDURE IF EXISTS AddEmailAlert;
DELIMITER $$
CREATE PROCEDURE AddEmailAlert(IN UserName varchar(32), Name varchar(20), CRN varchar(5))
BEGIN
INSERT INTO EMAIL_ALERT VALUES (UserName, Name, CRN);
END $$
DELIMITER ;
DROP PROCEDURE IF EXISTS DeleteEmailAlert;
DELIMITER $$
CREATE PROCEDURE DeleteEmailAlert(IN User_Name varchar(32), _Name varchar(20), _CRN varchar(5))
BEGIN
DELETE FROM EMAIL_ALERT WHERE Username=User_Name AND Name=_Name AND CRN=_CRN;
END $$
DELIMITER ;
/* 17. Show email alerts */
/* Example :
call courseWorkOfInstructor('zhi_ins');
*/
DROP PROCEDURE IF EXISTS ShowEmailAlert;
DELIMITER $$
CREATE PROCEDURE ShowEmailAlert(IN User_Name varchar(32))
BEGIN
SELECT c.eCourseNum as CourseNum, e.CRN as CRN, e.Name as Name
FROM EMAIL_ALERT as e JOIN COURSES_THIS_SEM as c
WHERE e.Username = User_Name and e.CRN = c.CRN ;
END $$
DELIMITER ;
DROP TRIGGER IF EXISTS HashPass;
DELIMITER $$
create trigger HashPass before insert on LOGIN_USER
for each row
begin
IF EXISTS (SELECT NEW.Password)
THEN
SET NEW.Password = md5(NEW.Password);
END IF;
end$$
DELIMITER ;