From f976c4c944e6799d7c9dcab4c23070ed622230c7 Mon Sep 17 00:00:00 2001 From: acanas Date: Thu, 9 Sep 2021 11:11:08 +0200 Subject: [PATCH] Version 20.96.5: Sep 09, 2021 Queries moved to module swad_exam_database. --- swad_account.c | 2 +- swad_changelog.h | 3 +- swad_enrolment.c | 2 +- swad_exam.c | 26 ++++---- swad_exam_database.c | 145 +++++++++++++++++++++++++++++++++++-------- swad_exam_database.h | 47 +++++++------- swad_exam_session.c | 4 +- swad_exam_set.c | 79 +++++------------------ swad_game.c | 2 - swad_group.c | 2 +- swad_survey.c | 2 - swad_test.c | 3 - 12 files changed, 181 insertions(+), 136 deletions(-) diff --git a/swad_account.c b/swad_account.c index d99767a1..9c18668f 100644 --- a/swad_account.c +++ b/swad_account.c @@ -1018,7 +1018,7 @@ void Acc_CompletelyEliminateAccount (struct UsrData *UsrDat, /***** Remove test, exams and matches made by user in all courses *****/ TstPrn_RemovePrintsMadeByUsrInAllCrss (UsrDat->UsrCod); Exa_DB_RemovePrintQstsMadeByUsrInAllCrss (UsrDat->UsrCod); - Exa_DB_RemovePrintsMadeByUsrInAllCrss (UsrDat->UsrCod); + Exa_DB_RemoveAllPrintsMadeByUsrInAllCrss (UsrDat->UsrCod); Mch_RemoveMatchesMadeByUsrInAllCrss (UsrDat->UsrCod); /***** Remove user's notifications *****/ diff --git a/swad_changelog.h b/swad_changelog.h index 13cb2aeb..cea38e8d 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo. */ -#define Log_PLATFORM_VERSION "SWAD 20.96.4 (2021-09-08)" +#define Log_PLATFORM_VERSION "SWAD 20.96.5 (2021-09-09)" #define CSS_FILE "swad20.45.css" #define JS_FILE "swad20.69.1.js" /* TODO: Rename CENTRE to CENTER in help wiki. TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams + Version 20.96.5: Sep 09, 2021 Queries moved to module swad_exam_database. (314448 lines) Version 20.96.4: Sep 08, 2021 Queries moved to module swad_exam_database. (314414 lines) Version 20.96.3: Sep 08, 2021 Queries moved to module swad_exam_database. (314384 lines) Version 20.96.2: Sep 08, 2021 Queries moved to module swad_exam_database. (314362 lines) diff --git a/swad_enrolment.c b/swad_enrolment.c index d7622892..8cd7b08c 100644 --- a/swad_enrolment.c +++ b/swad_enrolment.c @@ -3213,7 +3213,7 @@ static void Enr_EffectivelyRemUsrFromCrs (struct UsrData *UsrDat, /* Remove tests, exams and matches results made by user in course */ TstPrn_RemovePrintsMadeByUsrInCrs (UsrDat->UsrCod,Crs->CrsCod); Exa_DB_RemovePrintQstsMadeByUsrInCrs (UsrDat->UsrCod,Crs->CrsCod); - Exa_DB_RemovePrintsMadeByUsrInCrs (UsrDat->UsrCod,Crs->CrsCod); + Exa_DB_RemoveAllPrintsMadeByUsrInCrs (UsrDat->UsrCod,Crs->CrsCod); Mch_RemoveMatchesMadeByUsrInCrs (UsrDat->UsrCod,Crs->CrsCod); } diff --git a/swad_exam.c b/swad_exam.c index c3edc131..911cab11 100644 --- a/swad_exam.c +++ b/swad_exam.c @@ -1081,22 +1081,22 @@ static void Exa_RemoveExamFromAllTables (long ExaCod) /***** Remove questions of exams prints, and exam prints, in this exam *****/ // TODO: DO NOT REMOVE EXAMS PRINTS. Instead move them to tables of deleted prints Exa_DB_RemovePrintQstsFromExa (ExaCod); - Exa_DB_RemovePrintsFromExa (ExaCod); + Exa_DB_RemoveAllPrintsFromExa (ExaCod); /***** Remove groups associated to sessions, and sessions, in this exam *****/ - Exa_DB_RemoveGrpsFromExa (ExaCod); - Exa_DB_RemoveSessionsFromExam (ExaCod); + Exa_DB_RemoveAllGrpsFromExa (ExaCod); + Exa_DB_RemoveAllSessionsFromExam (ExaCod); /***** Remove media associated to exam questions in the exam *****/ Exa_RemoveAllMedFilesFromStemOfAllQstsFromExam (ExaCod); Exa_RemoveAllMedFilesFromAnsOfAllQstsFromExam (ExaCod); /***** Remove the answers and the questions in sets of questions *****/ - Exa_DB_RemoveSetAnswersFromExam (ExaCod); - Exa_DB_RemoveSetQuestionsFromExam (ExaCod); + Exa_DB_RemoveAllSetAnswersFromExam (ExaCod); + Exa_DB_RemoveAllSetQuestionsFromExam (ExaCod); /***** Remove exam sets *****/ - Exa_DB_RemoveSetsFromExam (ExaCod); + Exa_DB_RemoveAllSetsFromExam (ExaCod); /***** Remove exam *****/ Exa_DB_RemoveExam (ExaCod); @@ -1112,25 +1112,25 @@ void Exa_RemoveCrsExams (long CrsCod) made in the given course *****/ // TODO: DO NOT REMOVE EXAMS PRINTS. Instead move them to tables of deleted prints Exa_DB_RemovePrintQstsFromCrs (CrsCod); - Exa_DB_RemovePrintsFromCrs (CrsCod); + Exa_DB_RemoveAllPrintsFromCrs (CrsCod); /***** Remove groups associated to sessions, and sessions, in this course *****/ - Exa_DB_RemoveGrpsFromCrs (CrsCod); - Exa_DB_RemoveSessionsFromCrs (CrsCod); + Exa_DB_RemoveAllGrpsFromCrs (CrsCod); + Exa_DB_RemoveAllSessionsFromCrs (CrsCod); /***** Remove media associated to test questions in the course *****/ Exa_RemoveAllMedFilesFromStemOfAllQstsFromCrs (CrsCod); Exa_RemoveAllMedFilesFromAnsOfAllQstsFromCrs (CrsCod); /***** Remove the answers and the questions in sets of questions *****/ - Exa_DB_RemoveSetAnswersFromCrs (CrsCod); - Exa_DB_RemoveSetQuestionsFromCrs (CrsCod); + Exa_DB_RemoveAllSetAnswersFromCrs (CrsCod); + Exa_DB_RemoveAllSetQuestionsFromCrs (CrsCod); /***** Remove the sets of questions in exams *****/ - Exa_DB_RemoveSetsFromCrs (CrsCod); + Exa_DB_RemoveAllSetsFromCrs (CrsCod); /***** Remove the exams *****/ - Exa_DB_RemoveExamsFromCrs (CrsCod); + Exa_DB_RemoveAllExamsFromCrs (CrsCod); } /*****************************************************************************/ diff --git a/swad_exam_database.c b/swad_exam_database.c index 51c9ddc0..ea1eafaa 100644 --- a/swad_exam_database.c +++ b/swad_exam_database.c @@ -184,7 +184,7 @@ void Exa_DB_RemoveExam (long ExaCod) /********************** Remove all exams from a course ***********************/ /*****************************************************************************/ -void Exa_DB_RemoveExamsFromCrs (long CrsCod) +void Exa_DB_RemoveAllExamsFromCrs (long CrsCod) { DB_QueryDELETE ("can not remove course exams", "DELETE FROM exa_exams" @@ -234,7 +234,7 @@ void Exa_DB_UpdateSet (const struct ExaSet_Set *Set) /************************ Update set title in database ***********************/ /*****************************************************************************/ -void Exa_DB_UpdateSetTitle (const struct ExaSet_Set *Set, +void Exa_DB_UpdateSetTitle (long SetCod,long ExaCod, const char NewTitle[ExaSet_MAX_BYTES_TITLE + 1]) { /***** Update set of questions changing old title by new title *****/ @@ -244,16 +244,15 @@ void Exa_DB_UpdateSetTitle (const struct ExaSet_Set *Set, " WHERE SetCod=%ld" " AND ExaCod=%ld", // Extra check NewTitle, - Set->SetCod, - Set->ExaCod); + SetCod, + ExaCod); } /*****************************************************************************/ /****** Update number of questions to appear in exam print in database *******/ /*****************************************************************************/ -void Exa_DB_UpdateNumQstsToExam (const struct ExaSet_Set *Set, - unsigned NumQstsToPrint) +void Exa_DB_UpdateNumQstsToExam (long SetCod,long ExaCod,unsigned NumQstsToPrint) { /***** Update set of questions changing old number by new number *****/ DB_QueryUPDATE ("can not update the number of questions to appear in exam print", @@ -262,8 +261,23 @@ void Exa_DB_UpdateNumQstsToExam (const struct ExaSet_Set *Set, " WHERE SetCod=%ld" " AND ExaCod=%ld", // Extra check NumQstsToPrint, - Set->SetCod, - Set->ExaCod); + SetCod, + ExaCod); + } + +/*****************************************************************************/ +/************ Change indexes of sets greater than a given index **************/ +/*****************************************************************************/ + +void Exa_DB_UpdateSetIndexesInExamGreaterThan (long ExaCod,long SetInd) + { + DB_QueryUPDATE ("can not update indexes of sets", + "UPDATE exa_sets" + " SET SetInd=SetInd-1" + " WHERE ExaCod=%ld" + " AND SetInd>%u", + ExaCod, + SetInd); } /*****************************************************************************/ @@ -443,11 +457,25 @@ unsigned Exa_DB_GetNextSetIndexInExam (long ExaCod,unsigned SetInd) SetInd); } +/*****************************************************************************/ +/******************* Remove a set of questions from an exam ******************/ +/*****************************************************************************/ + +void Exa_DB_RemoveSetFromExam (long SetCod,long ExaCod) + { + DB_QueryDELETE ("can not remove set", + "DELETE FROM exa_sets" + " WHERE SetCod=%ld" + " AND ExaCod=%ld", // Extra check + SetCod, + ExaCod); + } + /*****************************************************************************/ /***************** Remove the sets of questions from an course ***************/ /*****************************************************************************/ -void Exa_DB_RemoveSetsFromExam (long ExaCod) +void Exa_DB_RemoveAllSetsFromExam (long ExaCod) { DB_QueryDELETE ("can not remove exam sets", "DELETE FROM exa_sets" @@ -459,7 +487,7 @@ void Exa_DB_RemoveSetsFromExam (long ExaCod) /************ Remove the sets of questions from exams in a course ************/ /*****************************************************************************/ -void Exa_DB_RemoveSetsFromCrs (long CrsCod) +void Exa_DB_RemoveAllSetsFromCrs (long CrsCod) { DB_QueryDELETE ("can not remove sets in course exams", "DELETE FROM exa_sets" @@ -593,17 +621,64 @@ unsigned Exa_DB_GetAnswerType (MYSQL_RES **mysql_res,long QstCod) { return (unsigned) DB_QuerySELECT (mysql_res,"can not get a question", - "SELECT AnsType" // row[0] + "SELECT AnsType" // row[0] " FROM exa_set_questions" " WHERE QstCod=%ld", QstCod); } +/*****************************************************************************/ +/************* Get media code associated to stem of set question *************/ +/*****************************************************************************/ + +unsigned Exa_DB_GetMediaFromStemOfQst (MYSQL_RES **mysql_res,long QstCod,long SetCod) + { + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get media", + "SELECT MedCod" // row[0] + " FROM exa_set_questions" + " WHERE QstCod=%ld" + " AND SetCod=%ld", // Extra check + QstCod, + SetCod); + } + +/*****************************************************************************/ +/**************** Remove a question from a set of questions ******************/ +/*****************************************************************************/ + +void Exa_DB_RemoveSetQuestion (long QstCod,long SetCod) + { + DB_QueryDELETE ("can not remove a question from a set", + "DELETE FROM exa_set_questions" + " WHERE QstCod=%ld" + " AND SetCod=%ld", // Extra check + QstCod, + SetCod); + } + +/*****************************************************************************/ +/*************** Remove the questions in a set of questions ******************/ +/*****************************************************************************/ + +void Exa_DB_RemoveAllSetQuestionsFromSet (long SetCod,long ExaCod) + { + DB_QueryDELETE ("can not remove questions associated to set", + "DELETE FROM exa_set_questions" + " USING exa_set_questions," + "exa_sets" + " WHERE exa_set_questions.SetCod=%ld" + " AND exa_set_questions.SetCod=exa_sets.SetCod" + " AND exa_sets.ExaCod=%ld", // Extra check + SetCod, + ExaCod); + } + /*****************************************************************************/ /********* Remove the questions in sets of questions from an exam ************/ /*****************************************************************************/ -void Exa_DB_RemoveSetQuestionsFromExam (long ExaCod) +void Exa_DB_RemoveAllSetQuestionsFromExam (long ExaCod) { DB_QueryDELETE ("can not remove exam questions", "DELETE FROM exa_set_questions" @@ -618,7 +693,7 @@ void Exa_DB_RemoveSetQuestionsFromExam (long ExaCod) /********* Remove the questions in sets of questions from a course ***********/ /*****************************************************************************/ -void Exa_DB_RemoveSetQuestionsFromCrs (long CrsCod) +void Exa_DB_RemoveAllSetQuestionsFromCrs (long CrsCod) { DB_QueryDELETE ("can not remove questions in course exams", "DELETE FROM exa_set_questions" @@ -711,11 +786,29 @@ unsigned Exa_DB_GetQstAnswersCorrFromSet (MYSQL_RES **mysql_res,long QstCod) QstCod); } +/*****************************************************************************/ +/*********** Get media codes associated to answers of set question ***********/ +/*****************************************************************************/ + +unsigned Exa_DB_GetMediaFromAllAnsOfQst (MYSQL_RES **mysql_res,long QstCod,long SetCod) + { + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get media", + "SELECT exa_set_answers.MedCod" // row[0] + " FROM exa_set_answers," + "exa_set_questions" + " WHERE exa_set_answers.QstCod=%ld" + " AND exa_set_answers.QstCod=exa_set_questions.QstCod" + " AND exa_set_questions.SetCod=%ld", // Extra check + QstCod, + SetCod); + } + /*****************************************************************************/ /********** Remove the answers in sets of questions from an exam *************/ /*****************************************************************************/ -void Exa_DB_RemoveSetAnswersFromExam (long ExaCod) +void Exa_DB_RemoveAllSetAnswersFromExam (long ExaCod) { DB_QueryDELETE ("can not remove exam answers", "DELETE FROM exa_set_answers" @@ -732,7 +825,7 @@ void Exa_DB_RemoveSetAnswersFromExam (long ExaCod) /********** Remove the answers in sets of questions from a course ************/ /*****************************************************************************/ -void Exa_DB_RemoveSetAnswersFromCrs (long CrsCod) +void Exa_DB_RemoveAllSetAnswersFromCrs (long CrsCod) { DB_QueryDELETE ("can not remove answers in course exams", "DELETE FROM exa_set_answers" @@ -1020,7 +1113,7 @@ void Exa_DB_RemoveSessionFromAllTables (long SesCod) /*********************** Remove exam sessions from exam **********************/ /*****************************************************************************/ -void Exa_DB_RemoveSessionsFromExam (long ExaCod) +void Exa_DB_RemoveAllSessionsFromExam (long ExaCod) { DB_QueryDELETE ("can not remove sessions of an exam", "DELETE FROM exa_sessions" @@ -1032,7 +1125,7 @@ void Exa_DB_RemoveSessionsFromExam (long ExaCod) /********************** Remove exam sessions from course *********************/ /*****************************************************************************/ -void Exa_DB_RemoveSessionsFromCrs (long CrsCod) +void Exa_DB_RemoveAllSessionsFromCrs (long CrsCod) { DB_QueryDELETE ("can not remove sessions of a course", "DELETE FROM exa_sessions" @@ -1136,7 +1229,7 @@ bool Exa_DB_CheckIfICanListThisSessionBasedOnGrps (long SesCod) /******************** Remove all groups from one session *********************/ /*****************************************************************************/ -void Exa_DB_RemoveGrpsFromSes (long SesCod) +void Exa_DB_RemoveAllGrpsFromSes (long SesCod) { DB_QueryDELETE ("can not remove groups associated to a session", "DELETE FROM exa_groups" @@ -1148,7 +1241,7 @@ void Exa_DB_RemoveGrpsFromSes (long SesCod) /********* Remove groups associated to exam sessions of a given exam *********/ /*****************************************************************************/ -void Exa_DB_RemoveGrpsFromExa (long ExaCod) +void Exa_DB_RemoveAllGrpsFromExa (long ExaCod) { DB_QueryDELETE ("can not remove groups associated to sessions of an exam", "DELETE FROM exa_groups" @@ -1163,7 +1256,7 @@ void Exa_DB_RemoveGrpsFromExa (long ExaCod) /******** Remove groups associated to exam sessions of a given course ********/ /*****************************************************************************/ -void Exa_DB_RemoveGrpsFromCrs (long CrsCod) +void Exa_DB_RemoveAllGrpsFromCrs (long CrsCod) { DB_QueryDELETE ("can not remove sessions of a course", "DELETE FROM exa_groups" @@ -1180,7 +1273,7 @@ void Exa_DB_RemoveGrpsFromCrs (long CrsCod) /**************** Remove groups of one type from all sessions ****************/ /*****************************************************************************/ -void Exa_DB_RemoveGrpsOfType (long GrpTypCod) +void Exa_DB_RemoveAllGrpsOfType (long GrpTypCod) { DB_QueryDELETE ("can not remove groups of a type" " from the associations between sessions and groups", @@ -1303,7 +1396,7 @@ unsigned Exa_DB_GetDataOfPrintBySesCodAndUsrCod (MYSQL_RES **mysql_res, /******************* Remove exam prints for a given user *********************/ /*****************************************************************************/ -void Exa_DB_RemovePrintsMadeByUsrInAllCrss (long UsrCod) +void Exa_DB_RemoveAllPrintsMadeByUsrInAllCrss (long UsrCod) { DB_QueryDELETE ("can not remove exam prints made by a user", "DELETE FROM exa_prints" @@ -1315,7 +1408,7 @@ void Exa_DB_RemovePrintsMadeByUsrInAllCrss (long UsrCod) /*************** Remove exam prints made by a user in a course ***************/ /*****************************************************************************/ -void Exa_DB_RemovePrintsMadeByUsrInCrs (long UsrCod,long CrsCod) +void Exa_DB_RemoveAllPrintsMadeByUsrInCrs (long UsrCod,long CrsCod) { DB_QueryDELETE ("can not remove exams prints made by a user in a course", "DELETE FROM exa_prints" @@ -1334,7 +1427,7 @@ void Exa_DB_RemovePrintsMadeByUsrInCrs (long UsrCod,long CrsCod) /************ Remove exams prints made in the given exam session *************/ /*****************************************************************************/ -void Exa_DB_RemovePrintsFromSes (long SesCod) +void Exa_DB_RemoveAllPrintsFromSes (long SesCod) { DB_QueryDELETE ("can not remove exam prints in exam session", "DELETE FROM exa_prints" @@ -1346,7 +1439,7 @@ void Exa_DB_RemovePrintsFromSes (long SesCod) /**************** Remove exams prints made in the given exam *****************/ /*****************************************************************************/ -void Exa_DB_RemovePrintsFromExa (long ExaCod) +void Exa_DB_RemoveAllPrintsFromExa (long ExaCod) { DB_QueryDELETE ("can not remove exams prints in a course", "DELETE FROM exa_prints" @@ -1361,7 +1454,7 @@ void Exa_DB_RemovePrintsFromExa (long ExaCod) /*************** Remove exams prints made in the given course ****************/ /*****************************************************************************/ -void Exa_DB_RemovePrintsFromCrs (long CrsCod) +void Exa_DB_RemoveAllPrintsFromCrs (long CrsCod) { DB_QueryDELETE ("can not remove exams prints in a course", "DELETE FROM exa_prints" diff --git a/swad_exam_database.h b/swad_exam_database.h index 9dcf47af..f1ae92ca 100644 --- a/swad_exam_database.h +++ b/swad_exam_database.h @@ -46,14 +46,14 @@ unsigned Exa_DB_GetDataOfExamByCod (MYSQL_RES **mysql_res,long ExaCod); unsigned Exa_DB_GetExamStartEnd (MYSQL_RES **mysql_res,long ExaCod); void Exa_DB_GetExamTxt (long ExaCod,char Txt[Cns_MAX_BYTES_TEXT + 1]); void Exa_DB_RemoveExam (long ExaCod); -void Exa_DB_RemoveExamsFromCrs (long CrsCod); +void Exa_DB_RemoveAllExamsFromCrs (long CrsCod); long Exa_DB_CreateSet (const struct ExaSet_Set *Set,unsigned SetInd); void Exa_DB_UpdateSet (const struct ExaSet_Set *Set); -void Exa_DB_UpdateSetTitle (const struct ExaSet_Set *Set, +void Exa_DB_UpdateSetTitle (long SetCod,long ExaCod, const char NewTitle[ExaSet_MAX_BYTES_TITLE + 1]); -void Exa_DB_UpdateNumQstsToExam (const struct ExaSet_Set *Set, - unsigned NumQstsToPrint); +void Exa_DB_UpdateNumQstsToExam (long SetCod,long ExaCod,unsigned NumQstsToPrint); +void Exa_DB_UpdateSetIndexesInExamGreaterThan (long ExaCod,long SetInd); unsigned Exa_DB_GetNumSetsExam (long ExaCod); unsigned Exa_DB_GetNumQstsExam (long ExaCod); unsigned Exa_DB_GetExamSets (MYSQL_RES **mysql_res,long ExaCod); @@ -65,8 +65,9 @@ long Exa_DB_GetSetCodFromSetInd (long ExaCod,unsigned SetInd); unsigned Exa_DB_GetMaxSetIndexInExam (long ExaCod); unsigned Exa_DB_GetPrevSetIndexInExam (long ExaCod,unsigned SetInd); unsigned Exa_DB_GetNextSetIndexInExam (long ExaCod,unsigned SetInd); -void Exa_DB_RemoveSetsFromExam (long ExaCod); -void Exa_DB_RemoveSetsFromCrs (long CrsCod); +void Exa_DB_RemoveSetFromExam (long SetCod,long ExaCod); +void Exa_DB_RemoveAllSetsFromExam (long ExaCod); +void Exa_DB_RemoveAllSetsFromCrs (long CrsCod); long Exa_DB_AddQuestionToSet (long SetCod,const struct Tst_Question *Question,long MedCod); unsigned Exa_DB_GetNumQstsInSet (long SetCod); @@ -76,8 +77,11 @@ unsigned Exa_DB_GetSomeQstsFromSetToPrint (MYSQL_RES **mysql_res, unsigned Exa_DB_GetQstDataByCod (MYSQL_RES **mysql_res,long QstCod); unsigned Exa_DB_GetValidityAndAnswerType (MYSQL_RES **mysql_res,long QstCod); unsigned Exa_DB_GetAnswerType (MYSQL_RES **mysql_res,long QstCod); -void Exa_DB_RemoveSetQuestionsFromExam (long ExaCod); -void Exa_DB_RemoveSetQuestionsFromCrs (long CrsCod); +unsigned Exa_DB_GetMediaFromStemOfQst (MYSQL_RES **mysql_res,long QstCod,long SetCod); +void Exa_DB_RemoveSetQuestion (long QstCod,long SetCod); +void Exa_DB_RemoveAllSetQuestionsFromSet (long SetCod,long ExaCod); +void Exa_DB_RemoveAllSetQuestionsFromExam (long ExaCod); +void Exa_DB_RemoveAllSetQuestionsFromCrs (long CrsCod); void Exa_DB_AddAnsToQstInSet (long QstCod,unsigned AnsInd, const char *Answer,const char *Feedback, @@ -85,8 +89,9 @@ void Exa_DB_AddAnsToQstInSet (long QstCod,unsigned AnsInd, unsigned Exa_DB_GetQstAnswersFromSet (MYSQL_RES **mysql_res,long QstCod,bool Shuffle); unsigned Exa_DB_GetQstAnswersTextFromSet (MYSQL_RES **mysql_res,long QstCod); unsigned Exa_DB_GetQstAnswersCorrFromSet (MYSQL_RES **mysql_res,long QstCod); -void Exa_DB_RemoveSetAnswersFromExam (long ExaCod); -void Exa_DB_RemoveSetAnswersFromCrs (long CrsCod); +unsigned Exa_DB_GetMediaFromAllAnsOfQst (MYSQL_RES **mysql_res,long QstCod,long SetCod); +void Exa_DB_RemoveAllSetAnswersFromExam (long ExaCod); +void Exa_DB_RemoveAllSetAnswersFromCrs (long CrsCod); long Exa_DB_CreateSession (const struct ExaSes_Session *Session); void Exa_DB_UpdateSession (const struct ExaSes_Session *Session); @@ -97,17 +102,17 @@ unsigned Exa_DB_GetDataOfSessionByCod (MYSQL_RES **mysql_res,long SesCod); void Exa_DB_ToggleVisResultsSesUsr (const struct ExaSes_Session *Session); void Exa_DB_HideUnhideSession (const struct ExaSes_Session *Session,bool Hide); void Exa_DB_RemoveSessionFromAllTables (long SesCod); -void Exa_DB_RemoveSessionsFromExam (long ExaCod); -void Exa_DB_RemoveSessionsFromCrs (long CrsCod); +void Exa_DB_RemoveAllSessionsFromExam (long ExaCod); +void Exa_DB_RemoveAllSessionsFromCrs (long CrsCod); void Exa_DB_RemoveUsrFromSessionTablesInCrs (long UsrCod,long CrsCod); void Exa_DB_CreateGrpAssociatedToSes (long SesCod,long GrpCod); unsigned Exa_DB_GetGrpsAssociatedToSes (MYSQL_RES **mysql_res,long SesCod); bool Exa_DB_CheckIfICanListThisSessionBasedOnGrps (long SesCod); -void Exa_DB_RemoveGrpsFromExa (long ExaCod); -void Exa_DB_RemoveGrpsFromCrs (long CrsCod); -void Exa_DB_RemoveGrpsFromSes (long SesCod); -void Exa_DB_RemoveGrpsOfType (long GrpTypCod); +void Exa_DB_RemoveAllGrpsFromExa (long ExaCod); +void Exa_DB_RemoveAllGrpsFromCrs (long CrsCod); +void Exa_DB_RemoveAllGrpsFromSes (long SesCod); +void Exa_DB_RemoveAllGrpsOfType (long GrpTypCod); void Exa_DB_RemoveGrpAssociatedToExamSess (long GrpCod); long Exa_DB_CreatePrint (const struct ExaPrn_Print *Print); @@ -115,11 +120,11 @@ void Exa_DB_UpdatePrint (const struct ExaPrn_Print *Print); unsigned Exa_DB_GetDataOfPrintByPrnCod (MYSQL_RES **mysql_res,long PrnCod); unsigned Exa_DB_GetDataOfPrintBySesCodAndUsrCod (MYSQL_RES **mysql_res, long SesCod,long UsrCod); -void Exa_DB_RemovePrintsMadeByUsrInAllCrss (long UsrCod); -void Exa_DB_RemovePrintsMadeByUsrInCrs (long UsrCod,long CrsCod); -void Exa_DB_RemovePrintsFromSes (long SesCod); -void Exa_DB_RemovePrintsFromExa (long ExaCod); -void Exa_DB_RemovePrintsFromCrs (long CrsCod); +void Exa_DB_RemoveAllPrintsMadeByUsrInAllCrss (long UsrCod); +void Exa_DB_RemoveAllPrintsMadeByUsrInCrs (long UsrCod,long CrsCod); +void Exa_DB_RemoveAllPrintsFromSes (long SesCod); +void Exa_DB_RemoveAllPrintsFromExa (long ExaCod); +void Exa_DB_RemoveAllPrintsFromCrs (long CrsCod); void Exa_DB_StoreOneQstOfPrint (const struct ExaPrn_Print *Print, unsigned QstInd); diff --git a/swad_exam_session.c b/swad_exam_session.c index b0c0c060..0a5aeb6e 100644 --- a/swad_exam_session.c +++ b/swad_exam_session.c @@ -860,7 +860,7 @@ void ExaSes_RemoveSession (void) // DELETE FROM exa_prints WHERE SesCod NOT IN (SELECT SesCod FROM exa_sessions); */ Exa_DB_RemovePrintQstsFromSes (Session.SesCod); - Exa_DB_RemovePrintsFromSes (Session.SesCod); + Exa_DB_RemoveAllPrintsFromSes (Session.SesCod); /***** Remove the exam session from all database tables *****/ Exa_DB_RemoveSessionFromAllTables (Session.SesCod); @@ -1307,7 +1307,7 @@ static void ExaSes_UpdateSession (struct ExaSes_Session *Session) Exa_DB_UpdateSession (Session); /***** Update groups associated to the exam session *****/ - Exa_DB_RemoveGrpsFromSes (Session->SesCod); // Remove all groups associated to this session + Exa_DB_RemoveAllGrpsFromSes (Session->SesCod); // Remove all groups associated to this session if (Gbl.Crs.Grps.LstGrpsSel.NumGrps) ExaSes_CreateGrpsAssociatedToExamSession (Session->SesCod,&Gbl.Crs.Grps.LstGrpsSel); // Associate new groups } diff --git a/swad_exam_set.c b/swad_exam_set.c index 9b612fc2..2816db37 100644 --- a/swad_exam_set.c +++ b/swad_exam_set.c @@ -116,8 +116,8 @@ static void ExaSet_FreeListsSelectedQuestions (struct Exa_Exams *Exams); static void ExaSet_CopyQstFromBankToExamSet (const struct ExaSet_Set *Set,long QstCod); -static void ExaSet_RemoveMediaFromStemOfQst (long SetCod,long QstCod); -static void ExaSet_RemoveMediaFromAllAnsOfQst (long SetCod,long QstCod); +static void ExaSet_RemoveMediaFromStemOfQst (long QstCod,long SetCod); +static void ExaSet_RemoveMediaFromAllAnsOfQst (long QstCod,long SetCod); static void ExaSet_ChangeValidityQst (Tst_Validity_t Valid); @@ -415,7 +415,7 @@ void ExaSet_ChangeSetTitle (void) if (ExaSet_CheckSetTitleReceivedFromForm (&Set,NewTitle)) { /* Update the table changing old title by new title */ - Exa_DB_UpdateSetTitle (&Set,NewTitle); + Exa_DB_UpdateSetTitle (Set.SetCod,Set.ExaCod,NewTitle); /* Update title */ Str_Copy (Set.Title,NewTitle,sizeof (Set.Title) - 1); @@ -462,7 +462,7 @@ void ExaSet_ChangeNumQstsToExam (void) if (NumQstsToPrint != Set.NumQstsToPrint) { /* Update the table changing old number by new number */ - Exa_DB_UpdateNumQstsToExam (&Set,NumQstsToPrint); + Exa_DB_UpdateNumQstsToExam (Set.SetCod,Set.ExaCod,NumQstsToPrint); /* Update title */ Set.NumQstsToPrint = NumQstsToPrint; @@ -1456,34 +1456,13 @@ void ExaSet_RemoveSet (void) /***** Remove the set from all the tables *****/ /* Remove questions associated to set */ - DB_QueryDELETE ("can not remove questions associated to set", - "DELETE FROM exa_set_questions" - " USING exa_set_questions," - "exa_sets" - " WHERE exa_set_questions.SetCod=%ld" - " AND exa_set_questions.SetCod=exa_sets.SetCod" - " AND exa_sets.ExaCod=%ld", // Extra check - Set.SetCod, - Set.ExaCod); + Exa_DB_RemoveAllSetQuestionsFromSet (Set.SetCod,Set.ExaCod); /* Remove the set itself */ - DB_QueryDELETE ("can not remove set", - "DELETE FROM exa_sets" - " WHERE SetCod=%ld" - " AND ExaCod=%ld", // Extra check - Set.SetCod, - Set.ExaCod); - if (!mysql_affected_rows (&Gbl.mysql)) - Err_ShowErrorAndExit ("The set to be removed does not exist."); + Exa_DB_RemoveSetFromExam (Set.SetCod,Set.ExaCod); - /* Change index of sets greater than this */ - DB_QueryUPDATE ("can not update indexes of sets", - "UPDATE exa_sets" - " SET SetInd=SetInd-1" - " WHERE ExaCod=%ld" - " AND SetInd>%u", - Set.ExaCod, - Set.SetInd); + /* Change indexes of sets greater than this */ + Exa_DB_UpdateSetIndexesInExamGreaterThan (Set.ExaCod,Set.SetInd); /***** Write message *****/ Ale_ShowAlert (Ale_SUCCESS,Txt_Set_of_questions_removed); @@ -1657,19 +1636,11 @@ void ExaSet_RemoveQstFromSet (void) QstCod = ExaSet_GetParamQstCod (); /***** Remove media associated to question *****/ - ExaSet_RemoveMediaFromStemOfQst (Set.SetCod,QstCod); - ExaSet_RemoveMediaFromAllAnsOfQst (Set.SetCod,QstCod); + ExaSet_RemoveMediaFromStemOfQst (QstCod,Set.SetCod); + ExaSet_RemoveMediaFromAllAnsOfQst (QstCod,Set.SetCod); /***** Remove the question from set *****/ - /* Remove the question itself */ - DB_QueryDELETE ("can not remove a question from a set", - "DELETE FROM exa_set_questions" - " WHERE QstCod=%ld" - " AND SetCod=%ld", // Extra check - QstCod, - Set.SetCod); - if (!mysql_affected_rows (&Gbl.mysql)) - Err_WrongQuestionExit (); + Exa_DB_RemoveSetQuestion (QstCod,Set.SetCod); /***** Write message *****/ Ale_ShowAlert (Ale_SUCCESS,Txt_Question_removed); @@ -1683,20 +1654,13 @@ void ExaSet_RemoveQstFromSet (void) /************ Remove media associated to stem of a test question *************/ /*****************************************************************************/ -static void ExaSet_RemoveMediaFromStemOfQst (long SetCod,long QstCod) +static void ExaSet_RemoveMediaFromStemOfQst (long QstCod,long SetCod) { MYSQL_RES *mysql_res; unsigned NumMedia; - /***** Get media code associated to stem of test question from database *****/ - NumMedia = (unsigned) - DB_QuerySELECT (&mysql_res,"can not get media", - "SELECT MedCod" // row[0] - " FROM exa_set_questions" - " WHERE QstCod=%ld" - " AND SetCod=%ld", // Extra check - QstCod, - SetCod); + /***** Get media code associated to stem of set question from database *****/ + NumMedia = Exa_DB_GetMediaFromStemOfQst (&mysql_res,QstCod,SetCod); /***** Go over result removing media *****/ Med_RemoveMediaFromAllRows (NumMedia,mysql_res); @@ -1706,24 +1670,13 @@ static void ExaSet_RemoveMediaFromStemOfQst (long SetCod,long QstCod) /****** Remove all media associated to all answers of an exam question *******/ /*****************************************************************************/ -static void ExaSet_RemoveMediaFromAllAnsOfQst (long SetCod,long QstCod) +static void ExaSet_RemoveMediaFromAllAnsOfQst (long QstCod,long SetCod) { MYSQL_RES *mysql_res; unsigned NumMedia; /***** Get media codes associated to answers of test question from database *****/ - NumMedia = (unsigned) - DB_QuerySELECT (&mysql_res,"can not get media", - "SELECT exa_set_answers.MedCod" // row[0] - " FROM exa_set_answers," - "exa_set_questions" - " WHERE exa_set_answers.QstCod=%ld" - " AND exa_set_answers.QstCod=exa_set_questions.QstCod" - " AND exa_set_questions.SetCod=%ld" // Extra check - " AND exa_set_questions.QstCod=%ld", // Extra check - QstCod, - SetCod, - QstCod); + NumMedia = Exa_DB_GetMediaFromAllAnsOfQst (&mysql_res,QstCod,SetCod); /***** Go over result removing media *****/ Med_RemoveMediaFromAllRows (NumMedia,mysql_res); diff --git a/swad_game.c b/swad_game.c index e90e55cd..325cbe4b 100644 --- a/swad_game.c +++ b/swad_game.c @@ -2354,8 +2354,6 @@ void Gam_RemoveQstFromGame (void) " AND QstInd=%u", Game.GamCod, QstInd); - if (!mysql_affected_rows (&Gbl.mysql)) - Err_WrongQuestionExit (); /* Change index of questions greater than this */ DB_QueryUPDATE ("can not update indexes of questions in table of answers", diff --git a/swad_group.c b/swad_group.c index 8f3415b6..608cf2e8 100644 --- a/swad_group.c +++ b/swad_group.c @@ -3507,7 +3507,7 @@ static void Grp_RemoveGroupTypeCompletely (void) Att_DB_RemoveGroupsOfType (Gbl.Crs.Grps.GrpTyp.GrpTypCod); /***** Remove the associations of exam sessions to groups of this type *****/ - Exa_DB_RemoveGrpsOfType (Gbl.Crs.Grps.GrpTyp.GrpTypCod); + Exa_DB_RemoveAllGrpsOfType (Gbl.Crs.Grps.GrpTyp.GrpTypCod); /***** Remove the associations of matches to groups of this type *****/ Mch_DB_RemoveGroupsOfType (Gbl.Crs.Grps.GrpTyp.GrpTypCod); diff --git a/swad_survey.c b/swad_survey.c index d0f64b24..b314af9d 100644 --- a/swad_survey.c +++ b/swad_survey.c @@ -3756,8 +3756,6 @@ void Svy_RemoveQst (void) "DELETE FROM svy_questions" " WHERE QstCod=%ld", SvyQst.QstCod); - if (!mysql_affected_rows (&Gbl.mysql)) - Err_WrongQuestionExit (); /* Change index of questions greater than this */ DB_QueryUPDATE ("can not update indexes of questions", diff --git a/swad_test.c b/swad_test.c index 3cd2a3bb..54ea62f8 100644 --- a/swad_test.c +++ b/swad_test.c @@ -4862,9 +4862,6 @@ static void Tst_RemoveOneQstFromDB (long CrsCod,long QstCod) " AND CrsCod=%ld", QstCod, CrsCod); - - if (!mysql_affected_rows (&Gbl.mysql)) - Err_WrongQuestionExit (); } /*****************************************************************************/