From 17ed9d593547b8233703b41af11eb7597d1d602e Mon Sep 17 00:00:00 2001 From: c22063583 <WHITEf6@cardiff.ac.uk> Date: Sun, 23 Apr 2023 16:32:15 +0100 Subject: [PATCH] ssql ready --- createdb.sql | 130 ++++++++++++++++++++++++++++++++++++++++++----- databaseTest.sql | 84 ++++++++++++++++++++++-------- 2 files changed, 180 insertions(+), 34 deletions(-) diff --git a/createdb.sql b/createdb.sql index 14a54db..1d8bd48 100644 --- a/createdb.sql +++ b/createdb.sql @@ -1,3 +1,7 @@ +-- this script is made out of 2 parts building the db +-- and testing it I would reccomend looking at the comments of the testing +-- section as it runs for an explanation of whats happpening + DROP SCHEMA IF EXISTS `SuperGeeks`; CREATE SCHEMA `SuperGeeks`; USE `SuperGeeks`; @@ -79,7 +83,7 @@ CREATE TABLE `Badge`( studentID varchar(40) unique, groupID varchar(40), - dateJoined date, + dateJoined datetime default now(), dateRemoved date, ageGroup int(2), FOREIGN KEY (studentID) REFERENCES Students(studentID)); @@ -305,7 +309,7 @@ BEGIN END; INSERT INTO WaitList(StudentID,groupID,dateJoined,ageGroup) values - (StudentID,groupID,CURDATE(),ageGroup); + (StudentID,groupID,now(),ageGroup); END$$ DELIMITER ; @@ -339,7 +343,7 @@ CREATE PROCEDURE viewStudent( BEGIN If LENGTH(studentvID) = 0 then - SELECT s0.StudentID , s0.studentCode, s0.fname ,s0.lname,s0.bday,(select email from parents where parentID = s0.parentsID),(select phonenum from parents where parentID = s0.parentsID) from students as s0; + SELECT s0.StudentID , s0.studentCode, s0.fname ,s0.lname,s0.bday,(select email from parents where parentID = s0.parentsID) as `emergency email`,(select phonenum from parents where parentID = s0.parentsID) as `emergency phone contact` from students as s0 ; else SELECT s0.StudentID , s0.studentCode, s0.fname ,s0.lname,s0.bday,(select email from parents where parentID = s0.parentsID),(select phonenum from parents where parentID = s0.parentsID) from students as s0 where studentvID=s0.studentID; end if; @@ -441,16 +445,14 @@ BEGIN SELECT "CANNOT APPLY FOR THAT GROUP" as ERROR ; END; select * from WaitList; -DO sleep(5); -select count(distinct volunteerID) *(SELECT ageGroup from Sessions where groupID=grapeID limit 1) into @maxstu from volunteerattendance as v0 +-- DO sleep(5); +select count(distinct volunteerID) *(SELECT ageGroup from sessiongroup where groupID=grapeID) into @maxstu from volunteerattendance as v0 where grapeID in (select groupID from Sessions as s0 - where v0.sessionID = s0.sessionID And - date_add(s0.OccuredOn, interval 7 day) > CURDATE() = 1) ; + where date_add(s0.OccuredOn, interval 31 day) > CURDATE() = 1) ; - select count(*) into @currentStu - from students as stu0 where grapeID in - (select groupID from sessions as s2 where stu0.studentID in - (select studentID from StudentAttendance as att0 where stu0.studentID=att0.StudentID)); + select count(distinct studentID) into @currentStu + from StudentAttendance as stu0 where grapeID in + (select groupID from students as ts0 where stu0.studentID=ts0.studentID); set toad = @maxstu - @currentStu; -- toad reprisents how many students the program should add off the WaitList -- the next loop adds a student to the group from the waitlist equal @@ -461,15 +463,18 @@ select count(distinct volunteerID) *(SELECT ageGroup from Sessions where groupID select studentID from waitlist where (dateRemoved is null) - order by dateJoined asc limit 1 into @theChosenOnes; + order by dateJoined asc limit 1 into @theChosenOnes; UPDATE WaitList as wl0,students as stu2 SET stu2.groupID=grapeID,wl0.dateRemoved=CURDATE() where wl0.studentID = @theChosenOnes and stu2.StudentID=@thechosenOnes; - -- test + -- test IF x=toad THEN LEAVE adding_loop; END IF; END LOOP adding_loop; + else + select @maxstu, @currentStu; + do sleep(2); end if; select * from WaitList; -- you should see that a number of students application should be successful @@ -608,7 +613,104 @@ CREATE PROCEDURE badgeApprove( BEGIN - update BadgeAwarded set awardedby=volunteerID,dateAwarded=curdate(),isAwarded=result; + update BadgeAwarded as ba set ba.awardedby=volunteerID,dateAwarded=curdate(),isAwarded=result where awardedID=ba.awardedid; END$$ DELIMITER ; + +-- THIS IS THE TESTING SECTION +SELECT * FROM parents; +do sleep(2); +call addParent("jeff","Jones","email@realemail.com","veryStrongPassw0rd",02358254); +call addParent("tim","buckley","loss@realemail.com","veryStrongPassw0rd",118254); +select * from parents; +do sleep(2); +-- this is how we add parents to the db notice how it automatically hashes +-- to create an ID based on the information +call addBadge("real badge","respond with placeholder evidence in <>"); +call addBadge("test badge","do not respond with hello world"); +select * from badge; +select * from students; +do sleep(3); +insert into students (studentID,fname,lname,bday,dayjoined,parentsID,groupID)values ((md5(concat('bobby','jones','EXTRaSTRONGPASSWORD'))),"bobby","jones",'2012-2-11',curdate(),'8e301d6e513165a9c0b6b9a2b10c8305','41'); + +insert into students (studentID,fname,lname,bday,dayjoined,parentsID,groupID) values(md5(concat('timothy','jones','EXTREMELYSTRONGPASSWORD')),"timothy","jones",'2002-2-11',curdate(),'8e301d6e513165a9c0b6b9a2b10c8305','41'); +call addStudent("samantha","jones",'2019-2-11','8e301d6e513165a9c0b6b9a2b10c8305','superSTRONGPASSWORD'); +call addStudent("tom","jones",'2012-2-11','8e301d6e513165a9c0b6b9a2b10c8305','superSTRONGPASSWORD'); +CALL addstudent('ethan','buckley','2013-03-02','4a85f9d4254038c83c3fc4f9b02b9619','weakpassword'); +CALL addstudent('tibalt','buckley','2014-03-02','4a85f9d4254038c83c3fc4f9b02b9619','password'); +call viewstudent(''); + +insert into sessiongroup values('41',5); + + +call viewstudent(''); +do sleep(5); +-- this adds some dummy data in for the db to use +-- some students have been inserted straight into the db without a SP +-- so it seems they have been part of this organisation for a while +-- this will be relevent when I add the students to a group and need students already +-- part of a group + +call applytogroup('4208a177bd0e3e81b682640e2c8078dd','41',5); +call addVolunteer("timothy","jones",'bob@bbc.co.uk','8e301d6e513165a9c0b6b9a2b10c8305',"0777008913"); +call applytogroup('b6e14bcdd6a79c8f8cd9fcef3be5f00b', '41',5); + +call applytogroup('7bd99d2efd6611161736f780a042f978','41',5); +do sleep(1); +-- 2 people were already in the group and 4 students have applied +-- tom jones was added last so he will be the one who will have to miss out +-- (tom's hashed id starts with 031f) +call applytogroup('031f0ba110c9683bf4cf5d2836b32a95',41,5); + +call updateSG('419fd9859978a9bf79df4ff16c99c5f9',"2010-04-09"); +call updateDBS('419fd9859978a9bf79df4ff16c99c5f9',"2021-09-09"); +call viewCheckExpiries(); +-- hmmm it appears volunteer tim doesn't have a valid sg check +-- +call updateSG('419fd9859978a9bf79df4ff16c99c5f9',"2023-04-04"); +-- now its valid + +do sleep(2); +call addSession("computer lab",4,'419fd9859978a9bf79df4ff16c99c5f9','2023-02-03',5,'41'); +call ReviewSession(md5('2023-02-03'),"it was ok","idk"); + +-- this is creating sessions and adding students and volunteers to the session +call addSession("computer lab",3,'419fd9859978a9bf79df4ff16c99c5f9','2023-01-03',5,'41'); +call ReviewSession(md5('2023-01-03'),"it was ok","idk"); +call addSession("computer lab",3,'419fd9859978a9bf79df4ff16c99c5f9','2022-11-03',5,'41'); +call addSession("computer lab",13,'419fd9859978a9bf79df4ff16c99c5f9','2023-04-16',5,'41'); +CALL STUDENTATTENDS('0ad073b3372ad0c243e6d465a2318568','94b21f931d888fefd4da7a07c01dff4a'); +call studentattends('313b6d9a06c3a0618f72ec75c082b6a4','94b21f931d888fefd4da7a07c01dff4a'); + +call viewVolunteer(''); +-- time volunteer has spent has been calculated from +do sleep(3); +select * from students; +do sleep(3); +call viewCheckExpiries(); +call addToGroup('41'); +do sleep(3); +-- you can see that tom jones is the only one not added as he joined the list last +select * from waitlist; + +select * from students; +call StudentBadgeApply( '0ad073b3372ad0c243e6d465a2318568','fb635b87d668b2bbcc6a0b0a2f6adc32','<placeholder evidence that is what is needed>'); +call StudentBadgeApply( '0ad073b3372ad0c243e6d465a2318568','fc1c7ce79f0265dd918c07588166cd03','hello world (incorrect)'); +-- bobby jones with hash id of 0ad is applying for a badge +-- with the correct evidence to sign them off +call viewbadges('0ad073b3372ad0c243e6d465a2318568'); +-- hmm it seems its pending +do sleep(3); +call volunteerviewbadges(); +do sleep(3); +call badgeapprove('1ab31562f157f8489ae45bb767cbad43','419fd9859978a9bf79df4ff16c99c5f9',1); +call badgeapprove( 'a360ea99016380d8ee67bdb4d9048004','419fd9859978a9bf79df4ff16c99c5f9',0); + +-- the volunteer timothy jones is validating the student booby's application it is correct so he is approving ity +-- the second application is incorrect so it is being rejected + +call viewbadges('0ad073b3372ad0c243e6d465a2318568'); +-- as you can see the correct badge has been approved and incorrect one has been rejected +do sleep(3); +-- it is correctly approved diff --git a/databaseTest.sql b/databaseTest.sql index 1f0fd74..7332af3 100644 --- a/databaseTest.sql +++ b/databaseTest.sql @@ -1,52 +1,96 @@ --- please run the createdb file before This - +-- please run the createdb file before every time you run this +SELECT * FROM parents; +do sleep(2); call addParent("jeff","Jones","email@realemail.com","veryStrongPassw0rd",02358254); call addParent("tim","buckley","loss@realemail.com","veryStrongPassw0rd",118254); -call addBadge("real badge","this is a totally real badge"); - +select * from parents; +do sleep(2); +-- this is how we add parents to the db notice how it automatically hashes +-- to create an ID based on the information +call addBadge("real badge","respond with placeholder evidence in <>"); +call addBadge("test badge","do not respond with hello world"); +select * from badge; +select * from students; +do sleep(3); insert into students (studentID,fname,lname,bday,dayjoined,parentsID,groupID)values ((md5(concat('bobby','jones','EXTRaSTRONGPASSWORD'))),"bobby","jones",'2012-2-11',curdate(),'8e301d6e513165a9c0b6b9a2b10c8305','41'); insert into students (studentID,fname,lname,bday,dayjoined,parentsID,groupID) values(md5(concat('timothy','jones','EXTREMELYSTRONGPASSWORD')),"timothy","jones",'2002-2-11',curdate(),'8e301d6e513165a9c0b6b9a2b10c8305','41'); call addStudent("samantha","jones",'2019-2-11','8e301d6e513165a9c0b6b9a2b10c8305','superSTRONGPASSWORD'); call addStudent("tom","jones",'2012-2-11','8e301d6e513165a9c0b6b9a2b10c8305','superSTRONGPASSWORD'); CALL addstudent('ethan','buckley','2013-03-02','4a85f9d4254038c83c3fc4f9b02b9619','weakpassword'); -insert into sessiongroup values('41',4); +CALL addstudent('tibalt','buckley','2014-03-02','4a85f9d4254038c83c3fc4f9b02b9619','password'); +call viewstudent(''); + +insert into sessiongroup values('41',5); + call viewstudent(''); +do sleep(5); -- this adds some dummy data in for the db to use -- some students have been inserted straight into the db without a SP -- so it seems they have been part of this organisation for a while -- this will be relevent when I add the students to a group and need students already -- part of a group -select * from students; -call applytogroup('4208a177bd0e3e81b682640e2c8078dd','41',4); +call applytogroup('4208a177bd0e3e81b682640e2c8078dd','41',5); call addVolunteer("timothy","jones",'bob@bbc.co.uk','8e301d6e513165a9c0b6b9a2b10c8305',"0777008913"); -call applytogroup('b6e14bcdd6a79c8f8cd9fcef3be5f00b', '41',4); +call applytogroup('b6e14bcdd6a79c8f8cd9fcef3be5f00b', '41',5); -call applytogroup('031f0ba110c9683bf4cf5d2836b32a95',41,4); -call updateSG('419fd9859978a9bf79df4ff16c99c5f9',"2020-04-09"); +call applytogroup('7bd99d2efd6611161736f780a042f978','41',5); +do sleep(1); +-- 2 people were already in the group and 4 students have applied +-- tom jones was added last so he will be the one who will have to miss out +-- (tom's hashed id starts with 031f) +call applytogroup('031f0ba110c9683bf4cf5d2836b32a95',41,5); + +call updateSG('419fd9859978a9bf79df4ff16c99c5f9',"2010-04-09"); call updateDBS('419fd9859978a9bf79df4ff16c99c5f9',"2021-09-09"); -call addSession("computer lab",4,'419fd9859978a9bf79df4ff16c99c5f9','2023-02-03',4,'41'); -call ReviewSession(md5('2023-02-03'),"it was ok","idk"); +call viewCheckExpiries(); +-- hmmm it appears volunteer tim doesn't have a valid sg check +-- +call updateSG('419fd9859978a9bf79df4ff16c99c5f9',"2023-04-04"); +-- now its valid +do sleep(2); +call addSession("computer lab",4,'419fd9859978a9bf79df4ff16c99c5f9','2023-02-03',5,'41'); +call ReviewSession(md5('2023-02-03'),"it was ok","idk"); -call addSession("computer lab",3,'419fd9859978a9bf79df4ff16c99c5f9','2023-01-03',4,'41'); +-- this is creating sessions and adding students and volunteers to the session +call addSession("computer lab",3,'419fd9859978a9bf79df4ff16c99c5f9','2023-01-03',5,'41'); call ReviewSession(md5('2023-01-03'),"it was ok","idk"); -call addSession("computer lab",3,'419fd9859978a9bf79df4ff16c99c5f9','2022-11-03',4,'41'); -call addSession("computer lab",3,'419fd9859978a9bf79df4ff16c99c5f9','2023-04-16',4,'41'); +call addSession("computer lab",3,'419fd9859978a9bf79df4ff16c99c5f9','2022-11-03',5,'41'); +call addSession("computer lab",13,'419fd9859978a9bf79df4ff16c99c5f9','2023-04-16',5,'41'); CALL STUDENTATTENDS('0ad073b3372ad0c243e6d465a2318568','94b21f931d888fefd4da7a07c01dff4a'); call studentattends('313b6d9a06c3a0618f72ec75c082b6a4','94b21f931d888fefd4da7a07c01dff4a'); + call viewVolunteer(''); +-- time volunteer has spent has been calculated from +do sleep(3); select * from students; - +do sleep(3); call viewCheckExpiries(); call addToGroup('41'); --- select * from waitlist; +do sleep(3); +-- you can see that tom jones is the only one not added as he joined the list last +select * from waitlist; + select * from students; -call StudentBadgeApply( '0ad073b3372ad0c243e6d465a2318568','fb635b87d668b2bbcc6a0b0a2f6adc32','I did it'); -call volunteerviewBadges(); +call StudentBadgeApply( '0ad073b3372ad0c243e6d465a2318568','fb635b87d668b2bbcc6a0b0a2f6adc32','<placeholder evidence that is what is needed>'); +call StudentBadgeApply( '0ad073b3372ad0c243e6d465a2318568','fc1c7ce79f0265dd918c07588166cd03','hello world (incorrect)'); +-- bobby jones with hash id of 0ad is applying for a badge +-- with the correct evidence to sign them off +call viewbadges('0ad073b3372ad0c243e6d465a2318568'); +-- hmm it seems its pending +do sleep(3); call volunteerviewbadges(); -select * from volunteers; +do sleep(3); call badgeapprove('1ab31562f157f8489ae45bb767cbad43','419fd9859978a9bf79df4ff16c99c5f9',1); +call badgeapprove( 'a360ea99016380d8ee67bdb4d9048004','419fd9859978a9bf79df4ff16c99c5f9',0); + +-- the volunteer timothy jones is validating the student booby's application it is correct so he is approving ity +-- the second application is incorrect so it is being rejected + call viewbadges('0ad073b3372ad0c243e6d465a2318568'); +-- as you can see the correct badge has been approved and incorrect one has been rejected +do sleep(3); +-- it is correctly approved -- GitLab