From eab0259d6158a1a88c5ec9406755e44793c41b5e Mon Sep 17 00:00:00 2001 From: c22063583 <WHITEf6@cardiff.ac.uk> Date: Thu, 20 Apr 2023 17:35:03 +0100 Subject: [PATCH] removal working --- createdb.sql | 71 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 22 deletions(-) diff --git a/createdb.sql b/createdb.sql index f033519..be136cf 100644 --- a/createdb.sql +++ b/createdb.sql @@ -21,7 +21,7 @@ fname varchar(35), lname varchar(35), -- The UK Government Data Standards Catalogue reccomends 35 characters for each the first name and last name bday date, -dayjoined date DEFAULT CURDATE() , +dayjoined date , parentsID varchar(40), groupID varchar(40), FOREIGN KEY (parentsID) REFERENCES Parents(parentID) @@ -72,12 +72,11 @@ CREATE TABLE `Badge`( CREATE TABLE `WaitList`( studentID varchar(40) unique, - SessionID varchar(40), + groupID varchar(40), dateJoined date, dateRemoved date, ageGroup int(1), - FOREIGN KEY (studentID) REFERENCES Students(studentID), - FOREIGN KEY (SessionID) REFERENCES Sessions(SessionID)); + FOREIGN KEY (studentID) REFERENCES Students(studentID)); @@ -226,16 +225,15 @@ drop procedure if exists `applyToGroup`; delimiter $$ CREATE PROCEDURE applyToGroup( IN studentID varchar(40), - IN SessionID varchar(255), - IN ageGroup int(1)) + IN groupID varchar(40)) BEGIN DECLARE EXIT HANDLER FOR 1062 BEGIN SELECT 'This student is already on a wait list' as ERROR ; END; - INSERT INTO WaitList(StudentID,SessionID,dateJoined,ageGroup) values - (StudentID,SessionID,CURDATE(),ageGroup); + INSERT INTO WaitList(StudentID,groupID,dateJoined) values + (StudentID,groupID,CURDATE()); END$$ DELIMITER ; @@ -357,19 +355,38 @@ CREATE PROCEDURE addToGroup( IN grapeID varchar(40)) BEGIN -select count(distinct volunteerID) into @noOfVols from volunteerattendance as v0 + DECLARE toad INT DEFAULT 0; + DECLARE a INT Default 0; + +select count(distinct volunteerID) *(SELECT ageGroup from Sessions where groupID=grapeID limit 1) 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 14 day) > CURDATE() = 1) ; - select count(*)*(SELECT ageGroup from Sessions where groupID=grapeID limit 1) - 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 @noOfStus; + date_add(s0.OccuredOn, interval 7 day) > CURDATE() = 1) ; - -- UPDATE WaitList as wl0,students as stu2 + 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)); + set toad = @maxstu - @currentStu; + if toad is not null and toad >0 then + simple_loop : LOOP + SET a=a+1; + select studentID + from waitlist + where (dateRemoved is null) + 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; + + IF a=toad THEN + LEAVE simple_loop; + END IF; + END LOOP simple_loop; + end if; + + -- UPDATE WaitList as wl0,students as stu2 + -- SET stu2.groupID=grapeID,wl0.dateRemoved=CURDATE() where stu2.studentID in (@theChosenOnes); - -- UPDATE student set groupID =groupID where true; END$$ DELIMITER ; @@ -438,20 +455,30 @@ call addParent("jeff","Jones","email@realemail.com","veryStrongPassw0rd",0235825 call addStudent("bobby","jones",'2012-2-11','8e301d6e513165a9c0b6b9a2b10c8305',"EXTRASTRONGPASSWORD"); call addBadge("real badge","this is a totally real badge"); call addStudent("timothy","jones",'2002-2-11','8e301d6e513165a9c0b6b9a2b10c8305',"EXTREMELYSTRONGPASSWORD"); +call addStudent("samantha","jones",'2012-2-11','8e301d6e513165a9c0b6b9a2b10c8305','superSTRONGPASSWORD'); +call addStudent("tom","jones",'2012-2-11','8e301d6e513165a9c0b6b9a2b10c8305','superSTRONGPASSWORD'); + + +call viewstudent(''); +select * from students; call addVolunteer("timothy","jones",'bob@bbc.co.uk','8e301d6e513165a9c0b6b9a2b10c8305',"0777008913"); +call applytogroup('b6e14bcdd6a79c8f8cd9fcef3be5f00b', '41'); +call applytogroup('031f0ba110c9683bf4cf5d2836b32a95',41); call updateSG('419fd9859978a9bf79df4ff16c99c5f9',"2020-04-09"); call updateDBS('419fd9859978a9bf79df4ff16c99c5f9',"2021-09-09"); -call addSession("computer lab",3,'419fd9859978a9bf79df4ff16c99c5f9','2023-02-03',8,'41'); +call addSession("computer lab",3,'419fd9859978a9bf79df4ff16c99c5f9','2023-02-03',3,'41'); call ReviewSession(md5('2023-02-03'),"it was ok","idk"); -call addSession("computer lab",3,'419fd9859978a9bf79df4ff16c99c5f9','2023-01-03',8,'41'); + +call addSession("computer lab",3,'419fd9859978a9bf79df4ff16c99c5f9','2023-01-03',3,'41'); call ReviewSession(md5('2023-01-03'),"it was ok","idk"); -call addSession("computer lab",3,'419fd9859978a9bf79df4ff16c99c5f9','2022-11-03',8,'41'); -call addSession("computer lab",3,'419fd9859978a9bf79df4ff16c99c5f9','2023-04-16',8,'41'); +call addSession("computer lab",3,'419fd9859978a9bf79df4ff16c99c5f9','2022-11-03',3,'41'); +call addSession("computer lab",3,'419fd9859978a9bf79df4ff16c99c5f9','2023-04-16',3,'41'); CALL STUDENTATTENDS('562fe5b6c65003a11148594678c42b90','94b21f931d888fefd4da7a07c01dff4a'); call studentattends('313b6d9a06c3a0618f72ec75c082b6a4','94b21f931d888fefd4da7a07c01dff4a'); call viewVolunteer(''); select * from sessions; -select * from students; +select * from waitlist; + call viewCheckExpiries(); call addToGroup('41'); -- GitLab