From ce1772f53ea78e2ed24c04b7cb0edf6cb86493bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Wed, 14 Nov 2018 23:40:56 +0100 Subject: [PATCH] Version 18.17 --- swad_alert.c | 2 +- swad_changelog.h | 3 ++- swad_database.c | 21 +++++++++++---------- swad_database.h | 3 --- swad_social.c | 35 +++++++++++++++++++---------------- swad_statistic.c | 5 +++-- swad_test.c | 10 ++++++---- swad_user.c | 23 ++++++++++++----------- swad_web_service.c | 5 +++-- 9 files changed, 57 insertions(+), 50 deletions(-) diff --git a/swad_alert.c b/swad_alert.c index bc0ae8c56..d71c39367 100644 --- a/swad_alert.c +++ b/swad_alert.c @@ -120,7 +120,7 @@ void Ale_ShowAlertAndButton1 (Ale_AlertType_t AlertType,const char *Txt) static const bool AlertClosable[Ale_NUM_ALERT_TYPES] = { false, // Ale_NONE - false, // Ale_CLIPBOARD + true, // Ale_CLIPBOARD true, // Ale_INFO true, // Ale_SUCCESS true, // Ale_QUESTION diff --git a/swad_changelog.h b/swad_changelog.h index 6023fc9c7..40ea12b1f 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -353,10 +353,11 @@ En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 18.16.3 (2018-11-14)" +#define Log_PLATFORM_VERSION "SWAD 18.17 (2018-11-14)" #define CSS_FILE "swad18.4.css" #define JS_FILE "swad17.17.1.js" /* + Version 18.17: Nov 14, 2018 Code refactoring related to database queries. (236899 lines) Version 18.16.3: Nov 14, 2018 Fixed bug when copying-pasting on assignments/works of another user, reported by Javier Fernández Baldomero. (236890 lines) Version 18.16.2: Nov 14, 2018 Fixed bug in account, discovered by Oresti Baños. (236848 lines) Version 18.16.1: Nov 12, 2018 MOOC advertisement. (236846 lines) diff --git a/swad_database.c b/swad_database.c index faeaac7cd..f7dae6cd0 100644 --- a/swad_database.c +++ b/swad_database.c @@ -53,8 +53,9 @@ extern struct Globals Gbl; /*****************************************************************************/ static void DB_CreateTable (const char *Query); - -// static void DB_QueryPrintf (char **strp,const char *fmt,...); +static unsigned long DB_QuerySELECTusingQueryStr (char *Query, + MYSQL_RES **mysql_res, + const char *MsgError); /*****************************************************************************/ /***************************** Database tables *******************************/ @@ -3105,23 +3106,23 @@ unsigned long DB_QuerySELECT (MYSQL_RES **mysql_res,const char *MsgError, // vasprintf will return -1 Lay_NotEnoughMemoryExit (); - return DB_QuerySELECTusingQueryStr (&Query,mysql_res,MsgError); + return DB_QuerySELECTusingQueryStr (Query,mysql_res,MsgError); } -unsigned long DB_QuerySELECTusingQueryStr (char **Query, - MYSQL_RES **mysql_res,const char *MsgError) +static unsigned long DB_QuerySELECTusingQueryStr (char *Query, + MYSQL_RES **mysql_res, + const char *MsgError) { int Result; /***** Check that query string pointer does point to an allocated string *****/ - if (*Query == NULL) + if (Query == NULL) Lay_ShowErrorAndExit ("Wrong query string."); /***** Query database and free query string pointer *****/ - Result = mysql_query (&Gbl.mysql,*Query); // Returns 0 on success - free ((void *) *Query); - *Query = NULL; + Result = mysql_query (&Gbl.mysql,Query); // Returns 0 on success + free ((void *) Query); if (Result) DB_ExitOnMySQLError (MsgError); @@ -3164,7 +3165,7 @@ unsigned long DB_QueryCOUNT (const char *MsgError,const char *fmt,...) Lay_NotEnoughMemoryExit (); /***** Make query "SELECT COUNT(*) FROM..." *****/ - DB_QuerySELECTusingQueryStr (&Query,&mysql_res,MsgError); + DB_QuerySELECTusingQueryStr (Query,&mysql_res,MsgError); /***** Get number of rows *****/ row = mysql_fetch_row (mysql_res); diff --git a/swad_database.h b/swad_database.h index 89dc58018..f99305dfe 100644 --- a/swad_database.h +++ b/swad_database.h @@ -41,9 +41,6 @@ void DB_BuildQuery_old (char **Query,const char *fmt,...); unsigned long DB_QuerySELECT (MYSQL_RES **mysql_res,const char *MsgError, const char *fmt,...); -unsigned long DB_QuerySELECTusingQueryStr (char **Query, - MYSQL_RES **mysql_res,const char *MsgError); - unsigned long DB_GetNumRowsTable (const char *Table); unsigned long DB_QueryCOUNT (const char *MsgError,const char *fmt,...); diff --git a/swad_social.c b/swad_social.c index 15aeb23dc..11437f931 100644 --- a/swad_social.c +++ b/swad_social.c @@ -145,7 +145,7 @@ static void Soc_UpdateLastPubCodIntoSession (void); static void Soc_UpdateFirstPubCodIntoSession (long FirstPubCod); static void Soc_DropTemporaryTablesUsedToQueryTimeline (void); -static void Soc_ShowTimeline (char **Query, +static void Soc_ShowTimeline (char *Query, const char *Title,long NotCodToHighlight); static void Soc_PutIconsTimeline (void); @@ -157,8 +157,8 @@ static void Soc_GetParamsWhichUsrs (void); static void Soc_ShowWarningYouDontFollowAnyUser (void); -static void Soc_InsertNewPubsInTimeline (char **Query); -static void Soc_ShowOldPubsInTimeline (char **Query); +static void Soc_InsertNewPubsInTimeline (char *Query); +static void Soc_ShowOldPubsInTimeline (char *Query); static void Soc_GetDataOfSocialPublishingFromRow (MYSQL_ROW row,struct SocialPublishing *SocPub); @@ -372,7 +372,7 @@ static void Soc_ShowTimelineGblHighlightingNot (long NotCod) Soc_GET_RECENT_TIMELINE); /***** Show timeline *****/ - Soc_ShowTimeline (&Query,Txt_Timeline,NotCod); + Soc_ShowTimeline (Query,Txt_Timeline,NotCod); /***** Drop temporary tables *****/ Soc_DropTemporaryTablesUsedToQueryTimeline (); @@ -401,7 +401,7 @@ static void Soc_ShowTimelineUsrHighlightingNot (long NotCod) snprintf (Gbl.Title,sizeof (Gbl.Title), Txt_Timeline_OF_A_USER, Gbl.Usrs.Other.UsrDat.FirstName); - Soc_ShowTimeline (&Query,Gbl.Title,NotCod); + Soc_ShowTimeline (Query,Gbl.Title,NotCod); /***** Drop temporary tables *****/ Soc_DropTemporaryTablesUsedToQueryTimeline (); @@ -430,7 +430,7 @@ void Soc_RefreshNewTimelineGbl (void) Soc_GET_ONLY_NEW_PUBS); /***** Show new timeline *****/ - Soc_InsertNewPubsInTimeline (&Query); + Soc_InsertNewPubsInTimeline (Query); /***** Drop temporary tables *****/ Soc_DropTemporaryTablesUsedToQueryTimeline (); @@ -475,7 +475,7 @@ static void Soc_GetAndShowOldTimeline (Soc_TimelineUsrOrGbl_t TimelineUsrOrGbl) Soc_GET_ONLY_OLD_PUBS); /***** Show old timeline *****/ - Soc_ShowOldPubsInTimeline (&Query); + Soc_ShowOldPubsInTimeline (Query); /***** Drop temporary tables *****/ Soc_DropTemporaryTablesUsedToQueryTimeline (); @@ -919,7 +919,7 @@ static void Soc_DropTemporaryTablesUsedToQueryTimeline (void) | |_____| \ |_____| */ -static void Soc_ShowTimeline (char **Query, +static void Soc_ShowTimeline (char *Query, const char *Title,long NotCodToHighlight) { extern const char *Hlp_SOCIAL_Timeline; @@ -933,8 +933,9 @@ static void Soc_ShowTimeline (char **Query, bool ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod); /***** Get publishings from database *****/ - NumPubsGot = DB_QuerySELECTusingQueryStr (Query,&mysql_res, - "can not get timeline"); + NumPubsGot = DB_QuerySELECT (&mysql_res,"can not get timeline", + "%s", + Query); /***** Start box *****/ Box_StartBox (Soc_WIDTH_TIMELINE,Title,Soc_PutIconsTimeline, @@ -1123,7 +1124,7 @@ static void Soc_ShowWarningYouDontFollowAnyUser (void) /*****************************************************************************/ // The publishings are inserted as list elements of a hidden list -static void Soc_InsertNewPubsInTimeline (char **Query) +static void Soc_InsertNewPubsInTimeline (char *Query) { MYSQL_RES *mysql_res; MYSQL_ROW row; @@ -1133,8 +1134,9 @@ static void Soc_InsertNewPubsInTimeline (char **Query) struct SocialNote SocNot; /***** Get new publishings timeline from database *****/ - NumPubsGot = DB_QuerySELECTusingQueryStr (Query,&mysql_res, - "can not get timeline"); + NumPubsGot = DB_QuerySELECT (&mysql_res,"can not get timeline", + "%s", + Query); /***** List new publishings timeline *****/ for (NumPub = 0; @@ -1164,7 +1166,7 @@ static void Soc_InsertNewPubsInTimeline (char **Query) /*****************************************************************************/ // The publishings are inserted as list elements of a hidden list -static void Soc_ShowOldPubsInTimeline (char **Query) +static void Soc_ShowOldPubsInTimeline (char *Query) { MYSQL_RES *mysql_res; MYSQL_ROW row; @@ -1174,8 +1176,9 @@ static void Soc_ShowOldPubsInTimeline (char **Query) struct SocialNote SocNot; /***** Get old publishings timeline from database *****/ - NumPubsGot = DB_QuerySELECTusingQueryStr (Query,&mysql_res, - "can not get timeline"); + NumPubsGot = DB_QuerySELECT (&mysql_res,"can not get timeline", + "%s", + Query); /***** List old publishings in timeline *****/ for (NumPub = 0, SocPub.PubCod = 0; diff --git a/swad_statistic.c b/swad_statistic.c index 9f736fce7..8f8535c87 100644 --- a/swad_statistic.c +++ b/swad_statistic.c @@ -1459,8 +1459,9 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse) Ale_ShowAlert (Ale_INFO,Query); */ /***** Make the query *****/ - NumRows = DB_QuerySELECTusingQueryStr (&Query,&mysql_res, - "can not get clicks"); + NumRows = DB_QuerySELECT (&mysql_res,"can not get clicks", + "%s", + Query); /***** Count the number of rows in result *****/ if (NumRows == 0) diff --git a/swad_test.c b/swad_test.c index f303ef17f..ab103f297 100644 --- a/swad_test.c +++ b/swad_test.c @@ -2652,8 +2652,9 @@ static unsigned long Tst_GetQuestions (MYSQL_RES **mysql_res) } /* Make the query */ - NumRows = DB_QuerySELECTusingQueryStr (&Query,mysql_res, - "can not get questions"); + NumRows = DB_QuerySELECT (mysql_res,"can not get questions", + "%s", + Query); if (NumRows == 0) Ale_ShowAlert (Ale_INFO,Txt_No_questions_found_matching_your_search_criteria); @@ -2789,8 +2790,9 @@ static unsigned long Tst_GetQuestionsForTest (MYSQL_RES **mysql_res) Lay_ShowAlert (Lay_INFO,Query); */ /* Make the query */ - return DB_QuerySELECTusingQueryStr (&Query,mysql_res, - "can not get questions"); + return DB_QuerySELECT (mysql_res,"can not get questions", + "%s", + Query); } /*****************************************************************************/ diff --git a/swad_user.c b/swad_user.c index 66850afd8..299936bd2 100644 --- a/swad_user.c +++ b/swad_user.c @@ -186,7 +186,7 @@ static void Usr_BuildQueryToGetUsrsLstCrs (char **Query,Rol_Role_t Role); static void Usr_GetAdmsLst (Sco_Scope_t Scope); static void Usr_GetGstsLst (Sco_Scope_t Scope); -static void Usr_GetListUsrsFromQuery (char **Query,Rol_Role_t Role,Sco_Scope_t Scope); +static void Usr_GetListUsrsFromQuery (char *Query,Rol_Role_t Role,Sco_Scope_t Scope); static void Usr_AllocateUsrsList (Rol_Role_t Role); static void Usr_PutButtonToConfirmIWantToSeeBigList (unsigned NumUsrs,const char *OnSubmit); @@ -4619,7 +4619,7 @@ void Usr_GetListUsrs (Sco_Scope_t Scope,Rol_Role_t Role) Lay_ShowAlert (Lay_INFO,Query); */ /***** Get list of users from database given a query *****/ - Usr_GetListUsrsFromQuery (&Query,Role,Scope); + Usr_GetListUsrsFromQuery (Query,Role,Scope); } /*****************************************************************************/ @@ -4897,7 +4897,7 @@ void Usr_SearchListUsrs (Rol_Role_t Role) // Lay_ShowAlert (Lay_INFO,Query); /***** Get list of users from database given a query *****/ - Usr_GetListUsrsFromQuery (&Query,Role,Gbl.Scope.Current); + Usr_GetListUsrsFromQuery (Query,Role,Gbl.Scope.Current); } /*****************************************************************************/ @@ -5101,7 +5101,7 @@ static void Usr_GetAdmsLst (Sco_Scope_t Scope) } /***** Get list of administrators from database *****/ - Usr_GetListUsrsFromQuery (&Query,Rol_DEG_ADM,Scope); + Usr_GetListUsrsFromQuery (Query,Rol_DEG_ADM,Scope); } /*****************************************************************************/ @@ -5180,7 +5180,7 @@ static void Usr_GetGstsLst (Sco_Scope_t Scope) } /***** Get list of students from database *****/ - Usr_GetListUsrsFromQuery (&Query,Rol_GST,Scope); + Usr_GetListUsrsFromQuery (Query,Rol_GST,Scope); } /*****************************************************************************/ @@ -5231,7 +5231,7 @@ void Usr_GetUnorderedStdsCodesInDeg (long DegCod) DegCod,(unsigned) Rol_STD); /***** Get list of students from database *****/ - Usr_GetListUsrsFromQuery (&Query,Rol_STD,Sco_SCOPE_DEG); + Usr_GetListUsrsFromQuery (Query,Rol_STD,Sco_SCOPE_DEG); } } @@ -5239,7 +5239,7 @@ void Usr_GetUnorderedStdsCodesInDeg (long DegCod) /********************** Get list of users from database **********************/ /*****************************************************************************/ -static void Usr_GetListUsrsFromQuery (char **Query,Rol_Role_t Role,Sco_Scope_t Scope) +static void Usr_GetListUsrsFromQuery (char *Query,Rol_Role_t Role,Sco_Scope_t Scope) { extern const char *Txt_The_list_of_X_users_is_too_large_to_be_displayed; MYSQL_RES *mysql_res; @@ -5248,13 +5248,13 @@ static void Usr_GetListUsrsFromQuery (char **Query,Rol_Role_t Role,Sco_Scope_t S struct UsrInList *UsrInList; bool Abort = false; - if (*Query == NULL) + if (Query == NULL) { Gbl.Usrs.LstUsrs[Role].NumUsrs = 0; return; } - if (!*Query[0]) + if (!Query[0]) { Gbl.Usrs.LstUsrs[Role].NumUsrs = 0; return; @@ -5262,8 +5262,9 @@ static void Usr_GetListUsrsFromQuery (char **Query,Rol_Role_t Role,Sco_Scope_t S /***** Query database *****/ if ((Gbl.Usrs.LstUsrs[Role].NumUsrs = - (unsigned) DB_QuerySELECTusingQueryStr (Query,&mysql_res, - "can not get list of users"))) + (unsigned) DB_QuerySELECT (&mysql_res,"can not get list of users", + "%s", + Query))) { if (Gbl.Usrs.LstUsrs[Role].NumUsrs > Cfg_MAX_USRS_IN_LIST) { diff --git a/swad_web_service.c b/swad_web_service.c index 00ca62c76..1d1d667eb 100644 --- a/swad_web_service.c +++ b/swad_web_service.c @@ -3375,8 +3375,9 @@ int swad__sendMessage (struct soap *soap, if (ReplyUsrCod > 0 || ThereAreNicknames) // There are a recipient to reply or nicknames in "to" { /***** Get users *****/ - NumRows = DB_QuerySELECTusingQueryStr (&Query,&mysql_res, - "can not get users"); + NumRows = DB_QuerySELECT (&mysql_res,"can not get users", + "%s", + Query); sendMessageOut->numUsers = (int) NumRows; sendMessageOut->usersArray.__size = (int) NumRows;