diff --git a/db/StoredFunctions.sql b/db/StoredFunctions.sql index fb737913550b43a60f4a25ac7dfe7a3ffaef8991..374e08fb0f43c10b982dc4863ae1723af821a4fc 100644 --- a/db/StoredFunctions.sql +++ b/db/StoredFunctions.sql @@ -36,6 +36,8 @@ DROP FUNCTION IF EXISTS GetMaxRateForDisc// DROP FUNCTION IF EXISTS BindTeacher// +DROP FUNCTION IF EXISTS GetDisciplineSemesterID// + # ------------------------------------------------------------------------------------------- @@ -250,22 +252,31 @@ END // # Label: semesters # ------------------------------------------------------------------------------------------- -DROP FUNCTION IF EXISTS GetDisciplineSemesterID// -CREATE FUNCTION `GetDisciplineSemesterID` ( - `pDisciplineID` INT +DROP FUNCTION IF EXISTS GetDisciplineProperty// +CREATE FUNCTION `GetDisciplineProperty` ( + `pDisciplineID` INT, + `pType` enum('grade', 'subject', 'author', 'semester', 'milestone') ) RETURNS int(11) NO SQL BEGIN - DECLARE vSemesterID INT DEFAULT -1; + DECLARE vRes INT DEFAULT -1; - SELECT disciplines.SemesterID INTO vSemesterID - FROM `disciplines` - WHERE disciplines.ID = pDisciplineID - LIMIT 1; + SELECT CASE pType + WHEN 'grade' THEN disciplines.GradeID + WHEN 'subject' THEN disciplines.SubjectID + WHEN 'author' THEN disciplines.AuthorID + WHEN 'semester' THEN disciplines.SemesterID + WHEN 'milestone' THEN disciplines.Milestone + END INTO vRes + FROM `disciplines` + WHERE disciplines.ID = pDisciplineID + LIMIT 1; - RETURN vSemesterID; + RETURN vRes; END // + + # ------------------------------------------------------------------------------------------- # Label: faculties # ------------------------------------------------------------------------------------------- @@ -835,13 +846,13 @@ CREATE FUNCTION `Discipline_Create` ( `pTeacherID` INT, `pGradeID` INT, `pSubjectID` INT, - `pExamType` VARCHAR(30) CHARSET utf8, + `pExamType` enum('exam', 'credit', 'grading_credit'), `pLectureCount` INT, `pPracticeCount` INT, `pLabCount` INT, `pFacultyID` INT, `pSemesterID` INT, - `pSubtype` VARCHAR(30) CHARSET utf8 # scientific_coursework discipline_coursework + `pSubtype` enum('scientific_coursework', 'disciplinary_course') ) RETURNS int(11) NO SQL BEGIN @@ -940,11 +951,7 @@ BEGIN RETURN -1; END IF; - # get current grade - SELECT disciplines.GradeID INTO vCurGradeID - FROM `disciplines` - WHERE disciplines.ID = pDisciplineID - LIMIT 1; + SET vCurGradeID = GetDisciplineProperty(pDisciplineID, 'grade'); IF vCurGradeID = pGradeID THEN RETURN 0; END IF; @@ -1100,7 +1107,7 @@ BEGIN disciplines_groups.ID = ( @isAttached := LAST_INSERT_ID(disciplines_groups.ID) ); IF @isAttached < 0 THEN # group was attached - SET vSemesterID = GetDisciplineSemesterID(pDisciplineID); + SET vSemesterID = GetDisciplineProperty(pDisciplineID, 'semester'); # 3. delete students of this group which were bound to discipline before DELETE FROM `disciplines_students` @@ -1135,7 +1142,7 @@ BEGIN RETURN -1; END IF; - SET vSemesterID = GetDisciplineSemesterID(pDisciplineID); + SET vSemesterID = GetDisciplineProperty(pDisciplineID, 'semester'); SET vStudentGroupID = GetStudentGroup(pStudentID, vSemesterID); # 2. check if student's group is bound yet @@ -1185,7 +1192,7 @@ BEGIN disciplines_groups.GroupID = pGroupID LIMIT 1; - SET vSemesterID = GetDisciplineSemesterID(pDisciplineID); + SET vSemesterID = GetDisciplineProperty(pDisciplineID, 'semester'); # delete attached, and detached (doesn't take disc in any case) DELETE FROM `disciplines_students` @@ -1216,7 +1223,7 @@ BEGIN RETURN -1; END IF; - SET vSemesterID = GetDisciplineSemesterID(pDisciplineID); + SET vSemesterID = GetDisciplineProperty(pDisciplineID, 'semester'); SET vStudentGroupID = GetStudentGroup(pStudentID, vSemesterID); # 2. check if student's group is bound yet @@ -1420,7 +1427,7 @@ BEGIN UPDATE `disciplines` SET disciplines.MilestoneDate = CURDATE(), disciplines.Milestone = pMilestone - WHERE disciplines.FacultyID= pFacultyID AND + WHERE disciplines.FacultyID= pFacultyID AND disciplines.SemesterID = pSemesterID AND ( disciplines.ExamType = 'credit' OR disciplines.ExamType = 'grading_credit'); RETURN 0; diff --git a/db/StoredProcedures.sql b/db/StoredProcedures.sql index 53f5cfa7a0345531a87384ac773b1e06af72b30b..fb35d4580f8b5587811bb790e571261622180dbe 100644 --- a/db/StoredProcedures.sql +++ b/db/StoredProcedures.sql @@ -500,7 +500,7 @@ CREATE PROCEDURE `GetStudentsForDiscipline` ( NO SQL BEGIN DECLARE vSemesterID INT DEFAULT -1; - SET vSemesterID = GetDisciplineSemesterID(pDisciplineID); + SET vSemesterID = GetDisciplineProperty(pDisciplineID, 'semester'); SELECT view_disciplines_students.StudentID AS 'ID', view_disciplines_students.LastName, @@ -744,7 +744,7 @@ BEGIN disciplines_groups.GroupID = pGroupID LIMIT 1; - SET vSemesterID = GetDisciplineSemesterID(pDisciplineID); + SET vSemesterID = GetDisciplineProperty(pDisciplineID, 'semester'); IF !vChecker THEN SELECT students.ID,