From ab5f548d49512307a78202b69b5f1984149916b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Mon, 22 Oct 2018 10:12:41 +0200 Subject: [PATCH] Version 18.7.28 --- swad_changelog.h | 3 ++- swad_forum.c | 4 +-- swad_game.c | 10 ++++--- swad_group.c | 69 ++++++++++++++++++++++++++++++------------------ 4 files changed, 53 insertions(+), 33 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index 90e0aa38b..af610e55d 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.7.27 (2018-10-22)" +#define Log_PLATFORM_VERSION "SWAD 18.7.28 (2018-10-22)" #define CSS_FILE "swad18.4.css" #define JS_FILE "swad17.17.1.js" /* + Version 18.7.28: Oct 22, 2018 Some sprintf for database queries changed by asprintf. (237674 lines) Version 18.7.27: Oct 22, 2018 Some sprintf for database queries changed by asprintf. (237661 lines) Version 18.7.26: Oct 22, 2018 Some sprintf for database queries changed by asprintf. (237600 lines) Version 18.7.25: Oct 22, 2018 Some sprintf for database queries changed by asprintf. (237538 lines) diff --git a/swad_forum.c b/swad_forum.c index 336bcf60f..98a0d585e 100644 --- a/swad_forum.c +++ b/swad_forum.c @@ -904,8 +904,8 @@ static unsigned For_GetNumMyPstInThr (long ThrCod) " WHERE ThrCod=%ld AND UsrCod=%ld", ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod) < 0) Lay_NotEnoughMemoryExit (); - return (unsigned) DB_QueryCOUNT (Query,"can not check if you have written" - " posts in a thead of a forum"); + return (unsigned) DB_QueryCOUNT_free (Query,"can not check if you have written" + " posts in a thead of a forum"); } /*****************************************************************************/ diff --git a/swad_game.c b/swad_game.c index b4660d1cd..ddbd5bdb6 100644 --- a/swad_game.c +++ b/swad_game.c @@ -3500,8 +3500,9 @@ static void Gam_ExchangeQuestions (long GamCod, long QstCodBottom; /***** Lock table to make the inscription atomic *****/ - DB_Query ("LOCK TABLES gam_questions WRITE", - "Can not lock tables to move game question"); + if (asprintf (&Query,"LOCK TABLES gam_questions WRITE") < 0) + Lay_NotEnoughMemoryExit (); + DB_Query_free (Query,"can not lock tables to move game question"); Gbl.DB.LockedTables = true; /***** Get question code of the questions to be moved *****/ @@ -3537,8 +3538,9 @@ static void Gam_ExchangeQuestions (long GamCod, /***** Unlock table *****/ Gbl.DB.LockedTables = false; // Set to false before the following unlock... // ...to not retry the unlock if error in unlocking - DB_Query ("UNLOCK TABLES", - "Can not unlock tables after moving game questions"); + if (asprintf (&Query,"UNLOCK TABLES") < 0) + Lay_NotEnoughMemoryExit (); + DB_Query_free (Query,"can not unlock tables after moving game questions"); } /*****************************************************************************/ diff --git a/swad_group.c b/swad_group.c index 25470d9bd..a751212e3 100644 --- a/swad_group.c +++ b/swad_group.c @@ -96,6 +96,9 @@ static void Grp_PutIconToCreateNewGroup (void); static void Grp_PutCheckboxAllGrps (Grp_WhichGroups_t GroupsSelectableByStdsOrNETs); +static void Grp_LockTables (void); +static void Grp_UnlockTables (void); + static void Grp_ConstructorListGrpAlreadySelec (struct ListGrpsAlreadySelec **AlreadyExistsGroupOfType); static void Grp_DestructorListGrpAlreadySelec (struct ListGrpsAlreadySelec **AlreadyExistsGroupOfType); static void Grp_RemoveUsrFromGroup (long UsrCod,long GrpCod); @@ -760,10 +763,7 @@ bool Grp_ChangeMyGrpsAtomically (struct ListCodGrps *LstGrpsIWant) bool ChangesMade = false; /***** Lock tables to make the inscription atomic *****/ - DB_Query ("LOCK TABLES crs_grp_types WRITE,crs_grp WRITE," - "crs_grp_usr WRITE,crs_usr READ", - "Can not lock tables to change user's groups"); - Gbl.DB.LockedTables = true; + Grp_LockTables (); /***** Get list of groups types and groups in this course *****/ Grp_GetListGrpTypesAndGrpsInThisCrs (Grp_ONLY_GROUP_TYPES_WITH_GROUPS); @@ -881,10 +881,7 @@ bool Grp_ChangeMyGrpsAtomically (struct ListCodGrps *LstGrpsIWant) Grp_FreeListCodGrp (&LstGrpsIBelong); /***** Unlock tables after changes in my groups *****/ - Gbl.DB.LockedTables = false; // Set to false before the following unlock... - // ...to not retry the unlock if error in unlocking - DB_Query ("UNLOCK TABLES", - "Can not unlock tables after changes in user's groups"); + Grp_UnlockTables (); /***** Free list of groups types and groups in this course *****/ Grp_FreeListGrpTypesAndGrps (); @@ -904,14 +901,9 @@ void Grp_ChangeGrpsOtherUsrAtomically (struct ListCodGrps *LstGrpsUsrWants) bool RemoveUsrFromThisGrp; bool RegisterUsrInThisGrp; + /***** Lock tables to make the inscription atomic *****/ if (Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs.Role == Rol_STD) - { - /***** Lock tables to make the inscription atomic *****/ - DB_Query ("LOCK TABLES crs_grp_types WRITE,crs_grp WRITE," - "crs_grp_usr WRITE,crs_usr READ", - "Can not lock tables to change user's groups"); - Gbl.DB.LockedTables = true; - } + Grp_LockTables (); /***** Get list of groups types and groups in this course *****/ Grp_GetListGrpTypesAndGrpsInThisCrs (Grp_ONLY_GROUP_TYPES_WITH_GROUPS); @@ -948,22 +940,47 @@ void Grp_ChangeGrpsOtherUsrAtomically (struct ListCodGrps *LstGrpsUsrWants) Grp_AddUsrToGroup (&Gbl.Usrs.Other.UsrDat,LstGrpsUsrWants->GrpCods[NumGrpUsrWants]); } - /***** Free memory with the list of groups which I belonged to *****/ + /***** Free memory with the list of groups which user belonged to *****/ Grp_FreeListCodGrp (&LstGrpsUsrBelongs); - /***** Unlock tables after changes in my groups *****/ + /***** Unlock tables after changes in groups *****/ if (Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs.Role == Rol_STD) - { - Gbl.DB.LockedTables = false; // Set to false before the following unlock... - // ...to not retry the unlock if error in unlocking - DB_Query ("UNLOCK TABLES", - "Can not unlock tables after changes in user's groups"); - } + Grp_UnlockTables (); /***** Free list of groups types and groups in this course *****/ Grp_FreeListGrpTypesAndGrps (); } +/*****************************************************************************/ +/*********** Lock tables to make the registration in groups atomic ***********/ +/*****************************************************************************/ + +static void Grp_LockTables (void) + { + char *Query; + + if (asprintf (&Query,"LOCK TABLES crs_grp_types WRITE,crs_grp WRITE," + "crs_grp_usr WRITE,crs_usr READ") < 0) + Lay_NotEnoughMemoryExit (); + DB_Query_free (Query,"can not lock tables to change user's groups"); + Gbl.DB.LockedTables = true; + } + +/*****************************************************************************/ +/*********** Unlock tables after changes in registration in groups ***********/ +/*****************************************************************************/ + +static void Grp_UnlockTables (void) + { + char *Query; + + Gbl.DB.LockedTables = false; // Set to false before the following unlock... + // ...to not retry the unlock if error in unlocking + if (asprintf (&Query,"UNLOCK TABLES") < 0) + Lay_NotEnoughMemoryExit (); + DB_Query_free (Query,"can not unlock tables after changing user's groups"); + } + /*****************************************************************************/ /******* Check if not selected more than a group of single enrolment *********/ /*****************************************************************************/ @@ -3326,8 +3343,8 @@ bool Grp_GetIfIBelongToGrp (long GrpCod) GrpCod,Gbl.Usrs.Me.UsrDat.UsrCod) < 0) Lay_NotEnoughMemoryExit (); Gbl.Cache.IBelongToGrp.GrpCod = GrpCod; - Gbl.Cache.IBelongToGrp.IBelong = (DB_QueryCOUNT (Query,"can not check" - " if you belong to a group") != 0); + Gbl.Cache.IBelongToGrp.IBelong = (DB_QueryCOUNT_free (Query,"can not check" + " if you belong to a group") != 0); return Gbl.Cache.IBelongToGrp.IBelong; } @@ -4678,7 +4695,7 @@ void Grp_RenameGroupType (void) NewNameGrpTyp, Gbl.CurrentCrs.Grps.GrpTyp.GrpTypCod) < 0) Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE (Query,"can not update the type of a group"); + DB_QueryUPDATE_free (Query,"can not update the type of a group"); /***** Write message to show the change made *****/ AlertType = Ale_SUCCESS;