diff --git a/swad_changelog.h b/swad_changelog.h index 24cb50fca..f51045ac3 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.11.11 (2018-11-01)" +#define Log_PLATFORM_VERSION "SWAD 18.11.12 (2018-11-01)" #define CSS_FILE "swad18.4.css" #define JS_FILE "swad17.17.1.js" /* + Version 18.11.12: Nov 01, 2018 Joining building and performing query into one function. (235965 lines) Version 18.11.11: Nov 01, 2018 Joining building and performing query into one function. (235896 lines) Version 18.11.10: Nov 01, 2018 Joining building and performing query into one function. (235861 lines) Version 18.11.9: Oct 31, 2018 Joining building and performing query into one function. (235847 lines) diff --git a/swad_nickname.c b/swad_nickname.c index 8f78d0956..85854180b 100644 --- a/swad_nickname.c +++ b/swad_nickname.c @@ -120,10 +120,10 @@ bool Nck_GetNicknameFromUsrCod (long UsrCod, bool Found; /***** Get current (last updated) user's nickname from database *****/ - DB_BuildQuery ("SELECT Nickname FROM usr_nicknames" - " WHERE UsrCod=%ld ORDER BY CreatTime DESC LIMIT 1", - UsrCod); - if (DB_QuerySELECT_new (&mysql_res,"can not get nickname")) + if (DB_QuerySELECT (&mysql_res,"can not get nickname", + "SELECT Nickname FROM usr_nicknames" + " WHERE UsrCod=%ld ORDER BY CreatTime DESC LIMIT 1", + UsrCod)) { /* Get nickname */ row = mysql_fetch_row (mysql_res); @@ -166,12 +166,12 @@ long Nck_GetUsrCodFromNickname (const char *Nickname) /***** Get user's code from database *****/ /* Check if user code from table usr_nicknames is also in table usr_data */ - DB_BuildQuery ("SELECT usr_nicknames.UsrCod" - " FROM usr_nicknames,usr_data" - " WHERE usr_nicknames.Nickname='%s'" - " AND usr_nicknames.UsrCod=usr_data.UsrCod", - NicknameWithoutArroba); - if (DB_QuerySELECT_new (&mysql_res,"can not get user's code")) + if (DB_QuerySELECT (&mysql_res,"can not get user's code", + "SELECT usr_nicknames.UsrCod" + " FROM usr_nicknames,usr_data" + " WHERE usr_nicknames.Nickname='%s'" + " AND usr_nicknames.UsrCod=usr_data.UsrCod", + NicknameWithoutArroba)) { /* Get row */ row = mysql_fetch_row (mysql_res); @@ -237,11 +237,12 @@ static void Nck_ShowFormChangeUsrNickname (const struct UsrData *UsrDat,bool Its Lay_StartSection (Nck_NICKNAME_SECTION_ID); /***** Get my nicknames *****/ - DB_BuildQuery ("SELECT Nickname FROM usr_nicknames" - " WHERE UsrCod=%ld" - " ORDER BY CreatTime DESC", - UsrDat->UsrCod); - NumNicks = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get nicknames of a user"); + NumNicks = + (unsigned) DB_QuerySELECT (&mysql_res,"can not get nicknames of a user", + "SELECT Nickname FROM usr_nicknames" + " WHERE UsrCod=%ld" + " ORDER BY CreatTime DESC", + UsrDat->UsrCod); /***** Start box *****/ snprintf (StrRecordWidth,sizeof (StrRecordWidth), diff --git a/swad_notice.c b/swad_notice.c index 843d6aa5b..003211b09 100644 --- a/swad_notice.c +++ b/swad_notice.c @@ -349,7 +349,7 @@ void Not_ShowNotices (Not_Listing_t TypeNoticesListing) char PathRelRSSFile[PATH_MAX + 1]; long NotCod; unsigned long NumNot; - unsigned long NumNotices; + unsigned long NumNotices = 0; // Initialized to avoid warning char Content[Cns_MAX_BYTES_TEXT + 1]; time_t TimeUTC; long UsrCod; @@ -363,22 +363,31 @@ void Not_ShowNotices (Not_Listing_t TypeNoticesListing) switch (TypeNoticesListing) { case Not_LIST_BRIEF_NOTICES: - DB_BuildQuery ("SELECT NotCod,UNIX_TIMESTAMP(CreatTime) AS F,UsrCod,Content,Status" - " FROM notices" - " WHERE CrsCod=%ld AND Status=%u" - " ORDER BY CreatTime DESC", - Gbl.CurrentCrs.Crs.CrsCod, - (unsigned) Not_ACTIVE_NOTICE); + NumNotices = DB_QuerySELECT (&mysql_res,"can not get notices from database", + "SELECT NotCod," + "UNIX_TIMESTAMP(CreatTime) AS F," + "UsrCod," + "Content," + "Status" + " FROM notices" + " WHERE CrsCod=%ld AND Status=%u" + " ORDER BY CreatTime DESC", + Gbl.CurrentCrs.Crs.CrsCod, + (unsigned) Not_ACTIVE_NOTICE); break; case Not_LIST_FULL_NOTICES: - DB_BuildQuery ("SELECT NotCod,UNIX_TIMESTAMP(CreatTime) AS F,UsrCod,Content,Status" - " FROM notices" - " WHERE CrsCod=%ld" - " ORDER BY CreatTime DESC", - Gbl.CurrentCrs.Crs.CrsCod); + NumNotices = DB_QuerySELECT (&mysql_res,"can not get notices from database", + "SELECT NotCod," + "UNIX_TIMESTAMP(CreatTime) AS F," + "UsrCod," + "Content," + "Status" + " FROM notices" + " WHERE CrsCod=%ld" + " ORDER BY CreatTime DESC", + Gbl.CurrentCrs.Crs.CrsCod); break; } - NumNotices = DB_QuerySELECT_new (&mysql_res,"can not get notices from database"); if (TypeNoticesListing == Not_LIST_FULL_NOTICES) { @@ -543,12 +552,14 @@ static void Not_GetDataAndShowNotice (long NotCod) Not_Status_t Status; /***** Get notice data from database *****/ - DB_BuildQuery ("SELECT UNIX_TIMESTAMP(CreatTime) AS F,UsrCod,Content,Status" - " FROM notices" - " WHERE NotCod=%ld AND CrsCod=%ld", - NotCod, - Gbl.CurrentCrs.Crs.CrsCod); - if (DB_QuerySELECT_new (&mysql_res,"can not get notice from database")) + if (DB_QuerySELECT (&mysql_res,"can not get notice from database", + "SELECT UNIX_TIMESTAMP(CreatTime) AS F," + "UsrCod," + "Content," + "Status" + " FROM notices" + " WHERE NotCod=%ld AND CrsCod=%ld", + NotCod,Gbl.CurrentCrs.Crs.CrsCod)) { row = mysql_fetch_row (mysql_res); @@ -756,8 +767,9 @@ void Not_GetSummaryAndContentNotice (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1], // This function may be called inside a web service, so don't report error /***** Get subject of message from database *****/ - DB_BuildQuery ("SELECT Content FROM notices WHERE NotCod=%ld",NotCod); - if (DB_QuerySELECT_new (&mysql_res,"can not get content of notice") == 1) // Result should have a unique row + if (DB_QuerySELECT (&mysql_res,"can not get content of notice", + "SELECT Content FROM notices WHERE NotCod=%ld", + NotCod) == 1) // Result should have a unique row { /***** Get sumary / content *****/ row = mysql_fetch_row (mysql_res); @@ -805,66 +817,71 @@ unsigned Not_GetNumNotices (Sco_Scope_t Scope,Not_Status_t Status,unsigned *NumN switch (Scope) { case Sco_SCOPE_SYS: - DB_BuildQuery ("SELECT COUNT(*),SUM(NumNotif)" - " FROM notices" - " WHERE Status=%u", - Status); + DB_QuerySELECT (&mysql_res,"can not get number of notices", + "SELECT COUNT(*),SUM(NumNotif)" + " FROM notices" + " WHERE Status=%u", + Status); break; case Sco_SCOPE_CTY: - DB_BuildQuery ("SELECT COUNT(*),SUM(notices.NumNotif)" - " FROM institutions,centres,degrees,courses,notices" - " WHERE institutions.CtyCod=%ld" - " AND institutions.InsCod=centres.InsCod" - " AND centres.CtrCod=degrees.CtrCod" - " AND degrees.DegCod=courses.DegCod" - " AND courses.CrsCod=notices.CrsCod" - " AND notices.Status=%u", - Gbl.CurrentCty.Cty.CtyCod, - Status); + DB_QuerySELECT (&mysql_res,"can not get number of notices", + "SELECT COUNT(*),SUM(notices.NumNotif)" + " FROM institutions,centres,degrees,courses,notices" + " WHERE institutions.CtyCod=%ld" + " AND institutions.InsCod=centres.InsCod" + " AND centres.CtrCod=degrees.CtrCod" + " AND degrees.DegCod=courses.DegCod" + " AND courses.CrsCod=notices.CrsCod" + " AND notices.Status=%u", + Gbl.CurrentCty.Cty.CtyCod, + Status); break; case Sco_SCOPE_INS: - DB_BuildQuery ("SELECT COUNT(*),SUM(notices.NumNotif)" - " FROM centres,degrees,courses,notices" - " WHERE centres.InsCod=%ld" - " AND centres.CtrCod=degrees.CtrCod" - " AND degrees.DegCod=courses.DegCod" - " AND courses.CrsCod=notices.CrsCod" - " AND notices.Status=%u", - Gbl.CurrentIns.Ins.InsCod, - Status); + DB_QuerySELECT (&mysql_res,"can not get number of notices", + "SELECT COUNT(*),SUM(notices.NumNotif)" + " FROM centres,degrees,courses,notices" + " WHERE centres.InsCod=%ld" + " AND centres.CtrCod=degrees.CtrCod" + " AND degrees.DegCod=courses.DegCod" + " AND courses.CrsCod=notices.CrsCod" + " AND notices.Status=%u", + Gbl.CurrentIns.Ins.InsCod, + Status); break; case Sco_SCOPE_CTR: - DB_BuildQuery ("SELECT COUNT(*),SUM(notices.NumNotif)" - " FROM degrees,courses,notices" - " WHERE degrees.CtrCod=%ld" - " AND degrees.DegCod=courses.DegCod" - " AND courses.CrsCod=notices.CrsCod" - " AND notices.Status=%u", - Gbl.CurrentCtr.Ctr.CtrCod, - Status); + DB_QuerySELECT (&mysql_res,"can not get number of notices", + "SELECT COUNT(*),SUM(notices.NumNotif)" + " FROM degrees,courses,notices" + " WHERE degrees.CtrCod=%ld" + " AND degrees.DegCod=courses.DegCod" + " AND courses.CrsCod=notices.CrsCod" + " AND notices.Status=%u", + Gbl.CurrentCtr.Ctr.CtrCod, + Status); break; case Sco_SCOPE_DEG: - DB_BuildQuery ("SELECT COUNT(*),SUM(notices.NumNotif)" - " FROM courses,notices" - " WHERE courses.DegCod=%ld" - " AND courses.CrsCod=notices.CrsCod" - " AND notices.Status=%u", - Gbl.CurrentDeg.Deg.DegCod, - Status); + DB_QuerySELECT (&mysql_res,"can not get number of notices", + "SELECT COUNT(*),SUM(notices.NumNotif)" + " FROM courses,notices" + " WHERE courses.DegCod=%ld" + " AND courses.CrsCod=notices.CrsCod" + " AND notices.Status=%u", + Gbl.CurrentDeg.Deg.DegCod, + Status); break; case Sco_SCOPE_CRS: - DB_BuildQuery ("SELECT COUNT(*),SUM(NumNotif)" - " FROM notices" - " WHERE CrsCod=%ld" - " AND Status=%u", - Gbl.CurrentCrs.Crs.CrsCod, - Status); + DB_QuerySELECT (&mysql_res,"can not get number of notices", + "SELECT COUNT(*),SUM(NumNotif)" + " FROM notices" + " WHERE CrsCod=%ld" + " AND Status=%u", + Gbl.CurrentCrs.Crs.CrsCod, + Status); break; default: Lay_WrongScopeExit (); break; } - DB_QuerySELECT_new (&mysql_res,"can not get number of notices"); /***** Get number of notices *****/ row = mysql_fetch_row (mysql_res); @@ -902,54 +919,59 @@ unsigned Not_GetNumNoticesDeleted (Sco_Scope_t Scope,unsigned *NumNotif) switch (Scope) { case Sco_SCOPE_SYS: - DB_BuildQuery ("SELECT COUNT(*),SUM(NumNotif)" - " FROM notices_deleted"); + DB_QuerySELECT (&mysql_res,"can not get number of deleted notices", + "SELECT COUNT(*),SUM(NumNotif)" + " FROM notices_deleted"); break; case Sco_SCOPE_CTY: - DB_BuildQuery ("SELECT COUNT(*),SUM(notices_deleted.NumNotif)" - " FROM institutions,centres,degrees,courses,notices_deleted" - " WHERE institutions.CtyCod=%ld" - " AND institutions.InsCod=centres.InsCod" - " AND centres.CtrCod=degrees.CtrCod" - " AND degrees.DegCod=courses.DegCod" - " AND courses.CrsCod=notices_deleted.CrsCod", - Gbl.CurrentCty.Cty.CtyCod); + DB_QuerySELECT (&mysql_res,"can not get number of deleted notices", + "SELECT COUNT(*),SUM(notices_deleted.NumNotif)" + " FROM institutions,centres,degrees,courses,notices_deleted" + " WHERE institutions.CtyCod=%ld" + " AND institutions.InsCod=centres.InsCod" + " AND centres.CtrCod=degrees.CtrCod" + " AND degrees.DegCod=courses.DegCod" + " AND courses.CrsCod=notices_deleted.CrsCod", + Gbl.CurrentCty.Cty.CtyCod); break; case Sco_SCOPE_INS: - DB_BuildQuery ("SELECT COUNT(*),SUM(notices_deleted.NumNotif)" - " FROM centres,degrees,courses,notices_deleted" - " WHERE centres.InsCod=%ld" - " AND centres.CtrCod=degrees.CtrCod" - " AND degrees.DegCod=courses.DegCod" - " AND courses.CrsCod=notices_deleted.CrsCod", - Gbl.CurrentIns.Ins.InsCod); + DB_QuerySELECT (&mysql_res,"can not get number of deleted notices", + "SELECT COUNT(*),SUM(notices_deleted.NumNotif)" + " FROM centres,degrees,courses,notices_deleted" + " WHERE centres.InsCod=%ld" + " AND centres.CtrCod=degrees.CtrCod" + " AND degrees.DegCod=courses.DegCod" + " AND courses.CrsCod=notices_deleted.CrsCod", + Gbl.CurrentIns.Ins.InsCod); break; case Sco_SCOPE_CTR: - DB_BuildQuery ("SELECT COUNT(*),SUM(notices_deleted.NumNotif)" - " FROM degrees,courses,notices_deleted" - " WHERE degrees.CtrCod=%ld" - " AND degrees.DegCod=courses.DegCod" - " AND courses.CrsCod=notices_deleted.CrsCod", - Gbl.CurrentCtr.Ctr.CtrCod); + DB_QuerySELECT (&mysql_res,"can not get number of deleted notices", + "SELECT COUNT(*),SUM(notices_deleted.NumNotif)" + " FROM degrees,courses,notices_deleted" + " WHERE degrees.CtrCod=%ld" + " AND degrees.DegCod=courses.DegCod" + " AND courses.CrsCod=notices_deleted.CrsCod", + Gbl.CurrentCtr.Ctr.CtrCod); break; case Sco_SCOPE_DEG: - DB_BuildQuery ("SELECT COUNT(*),SUM(notices_deleted.NumNotif)" - " FROM courses,notices_deleted" - " WHERE courses.DegCod=%ld" - " AND courses.CrsCod=notices_deleted.CrsCod", - Gbl.CurrentDeg.Deg.DegCod); + DB_QuerySELECT (&mysql_res,"can not get number of deleted notices", + "SELECT COUNT(*),SUM(notices_deleted.NumNotif)" + " FROM courses,notices_deleted" + " WHERE courses.DegCod=%ld" + " AND courses.CrsCod=notices_deleted.CrsCod", + Gbl.CurrentDeg.Deg.DegCod); break; case Sco_SCOPE_CRS: - DB_BuildQuery ("SELECT COUNT(*),SUM(NumNotif)" - " FROM notices_deleted" - " WHERE CrsCod=%ld", - Gbl.CurrentCrs.Crs.CrsCod); + DB_QuerySELECT (&mysql_res,"can not get number of deleted notices", + "SELECT COUNT(*),SUM(NumNotif)" + " FROM notices_deleted" + " WHERE CrsCod=%ld", + Gbl.CurrentCrs.Crs.CrsCod); break; default: Lay_WrongScopeExit (); break; } - DB_QuerySELECT_new (&mysql_res,"can not get number of deleted notices"); /***** Get number of notices *****/ row = mysql_fetch_row (mysql_res); diff --git a/swad_notification.c b/swad_notification.c index f8c760d6e..85b2935dd 100644 --- a/swad_notification.c +++ b/swad_notification.c @@ -354,22 +354,13 @@ void Ntf_ShowMyNotifications (void) sprintf (SubQuery," AND (Status&%u)=0", Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED); - /* - if (asprintf (&Query,"SELECT NotifyEvent,FromUsrCod,InsCod,CtrCod,DegCod,CrsCod," - "Cod,UNIX_TIMESTAMP(TimeNotif),Status" - " FROM notif" - " WHERE ToUsrCod=%ld%s" - " ORDER BY TimeNotif DESC", - Gbl.Usrs.Me.UsrDat.UsrCod,SubQuery) < 0) - Lay_NotEnoughMemoryExit (); - */ - DB_BuildQuery ("SELECT NotifyEvent,FromUsrCod,InsCod,CtrCod,DegCod,CrsCod," - "Cod,UNIX_TIMESTAMP(TimeNotif),Status" - " FROM notif" - " WHERE ToUsrCod=%ld%s" - " ORDER BY TimeNotif DESC", - Gbl.Usrs.Me.UsrDat.UsrCod,SubQuery); - NumNotifications = DB_QuerySELECT_new (&mysql_res,"can not get your notifications"); + NumNotifications = DB_QuerySELECT (&mysql_res,"can not get your notifications", + "SELECT NotifyEvent,FromUsrCod,InsCod,CtrCod,DegCod,CrsCod," + "Cod,UNIX_TIMESTAMP(TimeNotif),Status" + " FROM notif" + " WHERE ToUsrCod=%ld%s" + " ORDER BY TimeNotif DESC", + Gbl.Usrs.Me.UsrDat.UsrCod,SubQuery); /***** Contextual links *****/ fprintf (Gbl.F.Out,"