From 8a4e12738248c075e0016f9220b4654981a14720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Mon, 29 Oct 2018 11:13:21 +0100 Subject: [PATCH] Version 18.9.1 --- swad_changelog.h | 3 +- swad_statistic.c | 8 +-- swad_survey.c | 153 +++++++++++++++++++----------------------- swad_test.c | 170 +++++++++++++++++++++-------------------------- swad_timetable.c | 54 +++++++-------- swad_user.c | 19 ++---- 6 files changed, 180 insertions(+), 227 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index 90681624a..f1116d0bb 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -355,10 +355,11 @@ En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 18.9 (2018-10-28)" +#define Log_PLATFORM_VERSION "SWAD 18.9.1 (2018-10-29)" #define CSS_FILE "swad18.4.css" #define JS_FILE "swad17.17.1.js" /* + Version 18.9.1: Oct 29, 2018 Some sprintf for database queries changed by internal function. (236049 lines) Version 18.9: Oct 28, 2018 Some sprintf for database queries changed by internal function. (236082 lines) Version 18.8.18: Oct 28, 2018 Some asprintf for database queries changed by internal function. (236105 lines) Version 18.8.17: Oct 28, 2018 Some asprintf for database queries changed by internal function. (236116 lines) diff --git a/swad_statistic.c b/swad_statistic.c index e208418cb..663183ea6 100644 --- a/swad_statistic.c +++ b/swad_statistic.c @@ -422,13 +422,11 @@ void Sta_LogAccess (const char *Comments) void Sta_RemoveOldEntriesRecentLog (void) { - char Query[512]; - /***** Remove all expired clipboards *****/ - sprintf (Query,"DELETE LOW_PRIORITY FROM log_recent" + DB_BuildQuery ("DELETE LOW_PRIORITY FROM log_recent" " WHERE ClickTime%u", - SvyCod,SvyQst.QstInd); - DB_QueryUPDATE (Query,"can not update indexes of questions"); + SvyCod,SvyQst.QstInd); + DB_QueryUPDATE_new ("can not update indexes of questions"); /***** Write message *****/ Ale_ShowAlert (Ale_SUCCESS,Txt_Question_removed); diff --git a/swad_test.c b/swad_test.c index 63ddd22d0..8a0fa48da 100644 --- a/swad_test.c +++ b/swad_test.c @@ -728,21 +728,19 @@ static bool Tst_CheckIfNextTstAllowed (void) static void Tst_SetTstStatus (unsigned NumTst,Tst_Status_t TstStatus) { - char Query[256 + Cns_BYTES_SESSION_ID]; - /***** Delete old status from expired sessions *****/ - sprintf (Query,"DELETE FROM tst_status" + DB_BuildQuery ("DELETE FROM tst_status" " WHERE SessionId NOT IN (SELECT SessionId FROM sessions)"); - DB_QueryDELETE (Query,"can not remove old status of tests"); + DB_QueryDELETE_new ("can not remove old status of tests"); /***** Update database *****/ - sprintf (Query,"REPLACE INTO tst_status" + DB_BuildQuery ("REPLACE INTO tst_status" " (SessionId,CrsCod,NumTst,Status)" " VALUES" " ('%s',%ld,%u,%u)", - Gbl.Session.Id,Gbl.CurrentCrs.Crs.CrsCod, - NumTst,(unsigned) TstStatus); - DB_QueryREPLACE (Query,"can not update status of test"); + Gbl.Session.Id,Gbl.CurrentCrs.Crs.CrsCod, + NumTst,(unsigned) TstStatus); + DB_QueryREPLACE_new ("can not update status of test"); } /*****************************************************************************/ @@ -1549,7 +1547,6 @@ void Tst_RenameTag (void) extern const char *Txt_The_tag_X_has_not_changed; char OldTagTxt[Tst_MAX_BYTES_TAG + 1]; char NewTagTxt[Tst_MAX_BYTES_TAG + 1]; - char Query[1024 + 2 * Tst_MAX_BYTES_TAG]; long ExistingTagCod; long OldTagCod; bool ComplexRenaming; @@ -1606,56 +1603,54 @@ void Tst_RenameTag (void) /* Create a temporary table with all the question codes that had the new tag as one of their tags */ - sprintf (Query,"DROP TEMPORARY TABLE IF EXISTS tst_question_tags_tmp"); - if (mysql_query (&Gbl.mysql,Query)) - DB_ExitOnMySQLError ("can not remove temporary table"); - sprintf (Query,"CREATE TEMPORARY TABLE tst_question_tags_tmp" + DB_BuildQuery ("DROP TEMPORARY TABLE IF EXISTS tst_question_tags_tmp"); + DB_Query_new ("can not remove temporary table"); + + DB_BuildQuery ("CREATE TEMPORARY TABLE tst_question_tags_tmp" " ENGINE=MEMORY" " SELECT QstCod FROM tst_question_tags" " WHERE TagCod=%ld", - ExistingTagCod); - if (mysql_query (&Gbl.mysql,Query)) - DB_ExitOnMySQLError ("can not create temporary table"); + ExistingTagCod); + DB_Query_new ("can not create temporary table"); /* Remove old tag in questions where it would be repeated */ // New tag existed for a question ==> delete old tag - sprintf (Query,"DELETE FROM tst_question_tags" + DB_BuildQuery ("DELETE FROM tst_question_tags" " WHERE TagCod=%ld" " AND QstCod IN" " (SELECT QstCod FROM tst_question_tags_tmp)", - OldTagCod); - DB_QueryDELETE (Query,"can not remove a tag from some questions"); + OldTagCod); + DB_QueryDELETE_new ("can not remove a tag from some questions"); /* Change old tag to new tag in questions where it would not be repeated */ // New tag did not exist for a question ==> change old tag to new tag - sprintf (Query,"UPDATE tst_question_tags" + DB_BuildQuery ("UPDATE tst_question_tags" " SET TagCod=%ld" " WHERE TagCod=%ld" " AND QstCod NOT IN" " (SELECT QstCod FROM tst_question_tags_tmp)", - ExistingTagCod, - OldTagCod); - DB_QueryUPDATE (Query,"can not update a tag in some questions"); + ExistingTagCod, + OldTagCod); + DB_QueryUPDATE_new ("can not update a tag in some questions"); /* Drop temporary table, no longer necessary */ - sprintf (Query,"DROP TEMPORARY TABLE IF EXISTS tst_question_tags_tmp"); - if (mysql_query (&Gbl.mysql,Query)) - DB_ExitOnMySQLError ("can not remove temporary table"); + DB_BuildQuery ("DROP TEMPORARY TABLE IF EXISTS tst_question_tags_tmp"); + DB_Query_new ("can not remove temporary table"); /***** Delete old tag from tst_tags because it is not longer used *****/ - sprintf (Query,"DELETE FROM tst_tags WHERE TagCod=%ld", - OldTagCod); - DB_QueryDELETE (Query,"can not remove old tag"); + DB_BuildQuery ("DELETE FROM tst_tags WHERE TagCod=%ld", + OldTagCod); + DB_QueryDELETE_new ("can not remove old tag"); } else // Renaming is easy { /***** Simple update replacing each instance of the old tag by the new tag *****/ - sprintf (Query,"UPDATE tst_tags SET TagTxt='%s',ChangeTime=NOW()" + DB_BuildQuery ("UPDATE tst_tags SET TagTxt='%s',ChangeTime=NOW()" " WHERE tst_tags.CrsCod=%ld" " AND tst_tags.TagTxt='%s'", - NewTagTxt,Gbl.CurrentCrs.Crs.CrsCod,OldTagTxt); - DB_QueryUPDATE (Query,"can not update tag"); + NewTagTxt,Gbl.CurrentCrs.Crs.CrsCod,OldTagTxt); + DB_QueryUPDATE_new ("can not update tag"); } /***** Write message to show the change made *****/ @@ -6421,7 +6416,6 @@ static void Tst_PutParamsRemoveQst (void) void Tst_RemoveQst (void) { extern const char *Txt_Question_removed; - char Query[256]; bool EditingOnlyThisQst; /***** Get the question code *****/ @@ -6444,10 +6438,10 @@ void Tst_RemoveQst (void) Tst_RemoveUnusedTagsFromCurrentCrs (); /* Remove the question itself */ - sprintf (Query,"DELETE FROM tst_questions" + DB_BuildQuery ("DELETE FROM tst_questions" " WHERE QstCod=%ld AND CrsCod=%ld", - Gbl.Test.QstCod,Gbl.CurrentCrs.Crs.CrsCod); - DB_QueryDELETE (Query,"can not remove a question"); + Gbl.Test.QstCod,Gbl.CurrentCrs.Crs.CrsCod); + DB_QueryDELETE_new ("can not remove a question"); if (!mysql_affected_rows (&Gbl.mysql)) Lay_ShowErrorAndExit ("The question to be removed does not exist or belongs to another course."); @@ -6754,12 +6748,10 @@ static void Tst_InsertAnswersIntoDB (void) static void Tst_RemAnsFromQst (void) { - char Query[128]; - /***** Remove answers *****/ - sprintf (Query,"DELETE FROM tst_answers WHERE QstCod=%ld", - Gbl.Test.QstCod); - DB_QueryDELETE (Query,"can not remove the answers of a question"); + DB_BuildQuery ("DELETE FROM tst_answers WHERE QstCod=%ld", + Gbl.Test.QstCod); + DB_QueryDELETE_new ("can not remove the answers of a question"); } /*****************************************************************************/ @@ -6768,12 +6760,10 @@ static void Tst_RemAnsFromQst (void) static void Tst_RemTagsFromQst (void) { - char Query[128]; - /***** Remove tags *****/ - sprintf (Query,"DELETE FROM tst_question_tags WHERE QstCod=%ld", - Gbl.Test.QstCod); - DB_QueryDELETE (Query,"can not remove the tags of a question"); + DB_BuildQuery ("DELETE FROM tst_question_tags WHERE QstCod=%ld", + Gbl.Test.QstCod); + DB_QueryDELETE_new ("can not remove the tags of a question"); } /*****************************************************************************/ @@ -6782,18 +6772,16 @@ static void Tst_RemTagsFromQst (void) static void Tst_RemoveUnusedTagsFromCurrentCrs (void) { - char Query[512]; - /***** Remove unused tags from tst_tags *****/ - sprintf (Query,"DELETE FROM tst_tags" + DB_BuildQuery ("DELETE FROM tst_tags" " WHERE CrsCod=%ld AND TagCod NOT IN" " (SELECT DISTINCT tst_question_tags.TagCod" " FROM tst_questions,tst_question_tags" " WHERE tst_questions.CrsCod=%ld" " AND tst_questions.QstCod=tst_question_tags.QstCod)", - Gbl.CurrentCrs.Crs.CrsCod, - Gbl.CurrentCrs.Crs.CrsCod); - DB_QueryDELETE (Query,"can not remove unused tags"); + Gbl.CurrentCrs.Crs.CrsCod, + Gbl.CurrentCrs.Crs.CrsCod); + DB_QueryDELETE_new ("can not remove unused tags"); } /*****************************************************************************/ @@ -8556,20 +8544,18 @@ static void Tst_GetTestResultQuestionsFromDB (long TstCod) void Tst_RemoveTestResultsMadeByUsrInAllCrss (long UsrCod) { - char Query[512]; - /***** Remove test results made by the specified user *****/ - sprintf (Query,"DELETE FROM tst_exam_questions" + DB_BuildQuery ("DELETE FROM tst_exam_questions" " USING tst_exams,tst_exam_questions" " WHERE tst_exams.UsrCod=%ld" " AND tst_exams.TstCod=tst_exam_questions.TstCod", - UsrCod); - DB_QueryDELETE (Query,"can not remove test results made by a user"); + UsrCod); + DB_QueryDELETE_new ("can not remove test results made by a user"); - sprintf (Query,"DELETE FROM tst_exams" + DB_BuildQuery ("DELETE FROM tst_exams" " WHERE UsrCod=%ld", - UsrCod); - DB_QueryDELETE (Query,"can not remove test results made by a user"); + UsrCod); + DB_QueryDELETE_new ("can not remove test results made by a user"); } /*****************************************************************************/ @@ -8578,20 +8564,18 @@ void Tst_RemoveTestResultsMadeByUsrInAllCrss (long UsrCod) void Tst_RemoveTestResultsMadeByUsrInCrs (long UsrCod,long CrsCod) { - char Query[512]; - /***** Remove test results made by the specified user *****/ - sprintf (Query,"DELETE FROM tst_exam_questions" + DB_BuildQuery ("DELETE FROM tst_exam_questions" " USING tst_exams,tst_exam_questions" " WHERE tst_exams.CrsCod=%ld AND tst_exams.UsrCod=%ld" " AND tst_exams.TstCod=tst_exam_questions.TstCod", - CrsCod,UsrCod); - DB_QueryDELETE (Query,"can not remove test results made by a user in a course"); + CrsCod,UsrCod); + DB_QueryDELETE_new ("can not remove test results made by a user in a course"); - sprintf (Query,"DELETE FROM tst_exams" + DB_BuildQuery ("DELETE FROM tst_exams" " WHERE CrsCod=%ld AND UsrCod=%ld", - CrsCod,UsrCod); - DB_QueryDELETE (Query,"can not remove test results made by a user in a course"); + CrsCod,UsrCod); + DB_QueryDELETE_new ("can not remove test results made by a user in a course"); } /*****************************************************************************/ @@ -8600,20 +8584,18 @@ void Tst_RemoveTestResultsMadeByUsrInCrs (long UsrCod,long CrsCod) void Tst_RemoveCrsTestResults (long CrsCod) { - char Query[512]; - /***** Remove questions of test results made in the course *****/ - sprintf (Query,"DELETE FROM tst_exam_questions" + DB_BuildQuery ("DELETE FROM tst_exam_questions" " USING tst_exams,tst_exam_questions" " WHERE tst_exams.CrsCod=%ld" " AND tst_exams.TstCod=tst_exam_questions.TstCod", - CrsCod); - DB_QueryDELETE (Query,"can not remove test results made in a course"); + CrsCod); + DB_QueryDELETE_new ("can not remove test results made in a course"); /***** Remove test results made in the course *****/ - sprintf (Query,"DELETE FROM tst_exams WHERE CrsCod=%ld", - CrsCod); - DB_QueryDELETE (Query,"can not remove test results made in a course"); + DB_BuildQuery ("DELETE FROM tst_exams WHERE CrsCod=%ld", + CrsCod); + DB_QueryDELETE_new ("can not remove test results made in a course"); } /*****************************************************************************/ @@ -8622,37 +8604,35 @@ void Tst_RemoveCrsTestResults (long CrsCod) void Tst_RemoveCrsTests (long CrsCod) { - char Query[512]; - /***** Remove tests status in the course *****/ - sprintf (Query,"DELETE FROM tst_status WHERE CrsCod=%ld",CrsCod); - DB_QueryDELETE (Query,"can not remove status of tests of a course"); + DB_BuildQuery ("DELETE FROM tst_status WHERE CrsCod=%ld",CrsCod); + DB_QueryDELETE_new ("can not remove status of tests of a course"); /***** Remove test configuration of the course *****/ - sprintf (Query,"DELETE FROM tst_config WHERE CrsCod=%ld", - CrsCod); - DB_QueryDELETE (Query,"can not remove configuration of tests of a course"); + DB_BuildQuery ("DELETE FROM tst_config WHERE CrsCod=%ld", + CrsCod); + DB_QueryDELETE_new ("can not remove configuration of tests of a course"); /***** Remove associations between test questions and test tags in the course *****/ - sprintf (Query,"DELETE FROM tst_question_tags" + DB_BuildQuery ("DELETE FROM tst_question_tags" " USING tst_questions,tst_question_tags" " WHERE tst_questions.CrsCod=%ld" " AND tst_questions.QstCod=tst_question_tags.QstCod", - CrsCod); - DB_QueryDELETE (Query,"can not remove tags associated to questions of tests of a course"); + CrsCod); + DB_QueryDELETE_new ("can not remove tags associated to questions of tests of a course"); /***** Remove test tags in the course *****/ - sprintf (Query,"DELETE FROM tst_tags WHERE CrsCod=%ld", - CrsCod); - DB_QueryDELETE (Query,"can not remove tags of test of a course"); + DB_BuildQuery ("DELETE FROM tst_tags WHERE CrsCod=%ld", + CrsCod); + DB_QueryDELETE_new ("can not remove tags of test of a course"); /***** Remove test answers in the course *****/ - sprintf (Query,"DELETE FROM tst_answers USING tst_questions,tst_answers" + DB_BuildQuery ("DELETE FROM tst_answers USING tst_questions,tst_answers" " WHERE tst_questions.CrsCod=%ld" " AND tst_questions.QstCod=tst_answers.QstCod", - CrsCod); - DB_QueryDELETE (Query,"can not remove answers of tests of a course"); + CrsCod); + DB_QueryDELETE_new ("can not remove answers of tests of a course"); /***** Remove files with images associated to test questions in the course *****/ @@ -8660,7 +8640,7 @@ void Tst_RemoveCrsTests (long CrsCod) Tst_RemoveAllImgFilesFromStemOfAllQstsInCrs (CrsCod); /***** Remove test questions in the course *****/ - sprintf (Query,"DELETE FROM tst_questions WHERE CrsCod=%ld", - CrsCod); - DB_QueryDELETE (Query,"can not remove test questions of a course"); + DB_BuildQuery ("DELETE FROM tst_questions WHERE CrsCod=%ld", + CrsCod); + DB_QueryDELETE_new ("can not remove test questions of a course"); } diff --git a/swad_timetable.c b/swad_timetable.c index c09733dd0..ee46f19c6 100644 --- a/swad_timetable.c +++ b/swad_timetable.c @@ -558,9 +558,6 @@ void TT_ShowTimeTable (long UsrCod) static void TT_WriteCrsTimeTableIntoDB (long CrsCod) { - char Query[512 + - TT_MAX_BYTES_PLACE + - Grp_MAX_BYTES_GROUP_NAME]; unsigned Weekday; unsigned Interval; unsigned Hour; @@ -568,9 +565,9 @@ static void TT_WriteCrsTimeTableIntoDB (long CrsCod) unsigned Column; /***** Remove former timetable *****/ - sprintf (Query,"DELETE FROM timetable_crs WHERE CrsCod=%ld", - CrsCod); - DB_QueryDELETE (Query,"can not remove former timetable"); + DB_BuildQuery ("DELETE FROM timetable_crs WHERE CrsCod=%ld", + CrsCod); + DB_QueryDELETE_new ("can not remove former timetable"); /***** Go across the timetable inserting classes into database *****/ for (Weekday = 0; @@ -587,22 +584,22 @@ static void TT_WriteCrsTimeTableIntoDB (long CrsCod) if (TT_TimeTable[Weekday][Interval].Columns[Column].IntervalType == TT_FIRST_INTERVAL && TT_TimeTable[Weekday][Interval].Columns[Column].DurationIntervals) { - sprintf (Query,"INSERT INTO timetable_crs" + DB_BuildQuery ("INSERT INTO timetable_crs" " (CrsCod,GrpCod,Weekday,StartTime,Duration," "ClassType,Place,GroupName)" " VALUES" " (%ld,%ld,%u,'%02u:%02u:00',SEC_TO_TIME(%u)," "'%s','%s','%s')", - CrsCod, - TT_TimeTable[Weekday][Interval].Columns[Column].GrpCod, - Weekday, - Hour,Min, - TT_TimeTable[Weekday][Interval].Columns[Column].DurationIntervals * - Gbl.TimeTable.Config.SecondsPerInterval, - TT_ClassTypeDB[TT_TimeTable[Weekday][Interval].Columns[Column].ClassType], - TT_TimeTable[Weekday][Interval].Columns[Column].Place, - TT_TimeTable[Weekday][Interval].Columns[Column].Group); - DB_QueryINSERT (Query,"can not create course timetable"); + CrsCod, + TT_TimeTable[Weekday][Interval].Columns[Column].GrpCod, + Weekday, + Hour,Min, + TT_TimeTable[Weekday][Interval].Columns[Column].DurationIntervals * + Gbl.TimeTable.Config.SecondsPerInterval, + TT_ClassTypeDB[TT_TimeTable[Weekday][Interval].Columns[Column].ClassType], + TT_TimeTable[Weekday][Interval].Columns[Column].Place, + TT_TimeTable[Weekday][Interval].Columns[Column].Group); + DB_QueryINSERT_new ("can not create course timetable"); } } @@ -612,8 +609,6 @@ static void TT_WriteCrsTimeTableIntoDB (long CrsCod) static void TT_WriteTutTimeTableIntoDB (long UsrCod) { - char Query[512 + - TT_MAX_BYTES_PLACE]; unsigned Weekday; unsigned Interval; unsigned Hour; @@ -621,9 +616,8 @@ static void TT_WriteTutTimeTableIntoDB (long UsrCod) unsigned Column; /***** Remove former timetable *****/ - sprintf (Query,"DELETE FROM timetable_tut WHERE UsrCod=%ld", - UsrCod); - DB_QueryDELETE (Query,"can not remove former timetable"); + DB_BuildQuery ("DELETE FROM timetable_tut WHERE UsrCod=%ld",UsrCod); + DB_QueryDELETE_new ("can not remove former timetable"); /***** Loop over timetable *****/ for (Weekday = 0; @@ -640,17 +634,17 @@ static void TT_WriteTutTimeTableIntoDB (long UsrCod) if (TT_TimeTable[Weekday][Interval].Columns[Column].IntervalType == TT_FIRST_INTERVAL && TT_TimeTable[Weekday][Interval].Columns[Column].DurationIntervals) { - sprintf (Query,"INSERT INTO timetable_tut" + DB_BuildQuery ("INSERT INTO timetable_tut" " (UsrCod,Weekday,StartTime,Duration,Place)" " VALUES" " (%ld,%u,'%02u:%02u:00',SEC_TO_TIME(%u),'%s')", - UsrCod, - Weekday, - Hour,Min, - TT_TimeTable[Weekday][Interval].Columns[Column].DurationIntervals * - Gbl.TimeTable.Config.SecondsPerInterval, - TT_TimeTable[Weekday][Interval].Columns[Column].Place); - DB_QueryINSERT (Query,"can not create office timetable"); + UsrCod, + Weekday, + Hour,Min, + TT_TimeTable[Weekday][Interval].Columns[Column].DurationIntervals * + Gbl.TimeTable.Config.SecondsPerInterval, + TT_TimeTable[Weekday][Interval].Columns[Column].Place); + DB_QueryINSERT_new ("can not create office timetable"); } } diff --git a/swad_user.c b/swad_user.c index 8861fad02..996f4bfe0 100644 --- a/swad_user.c +++ b/swad_user.c @@ -2548,19 +2548,17 @@ static bool Usr_CheckIfMyBirthdayHasNotBeenCongratulated (void) static void Usr_InsertMyBirthday (void) { - char Query[256]; - /***** Delete old birthdays *****/ - sprintf (Query,"DELETE FROM birthdays_today WHERE Today<>CURDATE()"); - DB_QueryDELETE (Query,"can not delete old birthdays"); + DB_BuildQuery ("DELETE FROM birthdays_today WHERE Today<>CURDATE()"); + DB_QueryDELETE_new ("can not delete old birthdays"); /***** Insert new birthday *****/ - sprintf (Query,"INSERT INTO birthdays_today" + DB_BuildQuery ("INSERT INTO birthdays_today" " (UsrCod,Today)" " VALUES" " (%ld,CURDATE())", - Gbl.Usrs.Me.UsrDat.UsrCod); - DB_QueryINSERT (Query,"can not insert birthday"); + Gbl.Usrs.Me.UsrDat.UsrCod); + DB_QueryINSERT_new ("can not insert birthday"); } /*****************************************************************************/ @@ -8960,11 +8958,8 @@ bool Usr_CheckIfUsrBanned (long UsrCod) void Usr_RemoveUsrFromUsrBanned (long UsrCod) { - char Query[128]; - - sprintf (Query,"DELETE FROM usr_banned WHERE UsrCod=%ld", - UsrCod); - DB_QueryDELETE (Query,"can not remove user from users banned"); + DB_BuildQuery ("DELETE FROM usr_banned WHERE UsrCod=%ld",UsrCod); + DB_QueryDELETE_new ("can not remove user from users banned"); } /*****************************************************************************/