diff --git a/swad_MFU.c b/swad_MFU.c index a5921bae2..c782ea80e 100644 --- a/swad_MFU.c +++ b/swad_MFU.c @@ -381,11 +381,11 @@ void MFU_UpdateMFUActions (void) Gbl.Usrs.Me.UsrDat.UsrCod,ActCod,Score); /***** Update score for other actions *****/ - DB_BuildQuery ("UPDATE actions_MFU SET Score=GREATEST(Score*'%f','%f')" - " WHERE UsrCod=%ld AND ActCod<>%ld", - MFU_DECREASE_FACTOR,MFU_MIN_SCORE, - Gbl.Usrs.Me.UsrDat.UsrCod,ActCod); - DB_QueryUPDATE_new ("can not update most frequently used actions"); + DB_QueryUPDATE ("can not update most frequently used actions", + "UPDATE actions_MFU SET Score=GREATEST(Score*'%f','%f')" + " WHERE UsrCod=%ld AND ActCod<>%ld", + MFU_DECREASE_FACTOR,MFU_MIN_SCORE, + Gbl.Usrs.Me.UsrDat.UsrCod,ActCod); Str_SetDecimalPointToLocal (); // Return to local system } diff --git a/swad_agenda.c b/swad_agenda.c index a5e439cf8..0c1342c1a 100644 --- a/swad_agenda.c +++ b/swad_agenda.c @@ -1373,10 +1373,10 @@ void Agd_HideEvent (void) Agd_GetDataOfEventByCod (&AgdEvent); /***** Set event private *****/ - DB_BuildQuery ("UPDATE agendas SET Hidden='Y'" - " WHERE AgdCod=%ld AND UsrCod=%ld", - AgdEvent.AgdCod,AgdEvent.UsrCod); - DB_QueryUPDATE_new ("can not hide event"); + DB_QueryUPDATE ("can not hide event", + "UPDATE agendas SET Hidden='Y'" + " WHERE AgdCod=%ld AND UsrCod=%ld", + AgdEvent.AgdCod,AgdEvent.UsrCod); /***** Write message to show the change made *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), @@ -1406,10 +1406,10 @@ void Agd_UnhideEvent (void) Agd_GetDataOfEventByCod (&AgdEvent); /***** Set event public *****/ - DB_BuildQuery ("UPDATE agendas SET Hidden='N'" - " WHERE AgdCod=%ld AND UsrCod=%ld", - AgdEvent.AgdCod,AgdEvent.UsrCod); - DB_QueryUPDATE_new ("can not show event"); + DB_QueryUPDATE ("can not show event", + "UPDATE agendas SET Hidden='N'" + " WHERE AgdCod=%ld AND UsrCod=%ld", + AgdEvent.AgdCod,AgdEvent.UsrCod); /***** Write message to show the change made *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), @@ -1439,10 +1439,10 @@ void Agd_MakeEventPrivate (void) Agd_GetDataOfEventByCod (&AgdEvent); /***** Make event private *****/ - DB_BuildQuery ("UPDATE agendas SET Public='N'" - " WHERE AgdCod=%ld AND UsrCod=%ld", - AgdEvent.AgdCod,AgdEvent.UsrCod); - DB_QueryUPDATE_new ("can not make event private"); + DB_QueryUPDATE ("can not make event private", + "UPDATE agendas SET Public='N'" + " WHERE AgdCod=%ld AND UsrCod=%ld", + AgdEvent.AgdCod,AgdEvent.UsrCod); /***** Write message to show the change made *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), @@ -1472,10 +1472,10 @@ void Agd_MakeEventPublic (void) Agd_GetDataOfEventByCod (&AgdEvent); /***** Make event public *****/ - DB_BuildQuery ("UPDATE agendas SET Public='Y'" - " WHERE AgdCod=%ld AND UsrCod=%ld", - AgdEvent.AgdCod,AgdEvent.UsrCod); - DB_QueryUPDATE_new ("can not make event public"); + DB_QueryUPDATE ("can not make event public", + "UPDATE agendas SET Public='Y'" + " WHERE AgdCod=%ld AND UsrCod=%ld", + AgdEvent.AgdCod,AgdEvent.UsrCod); /***** Write message to show the change made *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), @@ -1732,16 +1732,16 @@ static void Agd_CreateEvent (struct AgendaEvent *AgdEvent,const char *Txt) static void Agd_UpdateEvent (struct AgendaEvent *AgdEvent,const char *Txt) { /***** Update the data of the event *****/ - DB_BuildQuery ("UPDATE agendas SET " - "StartTime=FROM_UNIXTIME(%ld)," - "EndTime=FROM_UNIXTIME(%ld)," - "Event='%s',Location='%s',Txt='%s'" - " WHERE AgdCod=%ld AND UsrCod=%ld", - AgdEvent->TimeUTC[Agd_START_TIME], - AgdEvent->TimeUTC[Agd_END_TIME ], - AgdEvent->Event,AgdEvent->Location,Txt, - AgdEvent->AgdCod,AgdEvent->UsrCod); - DB_QueryUPDATE_new ("can not update event"); + DB_QueryUPDATE ("can not update event", + "UPDATE agendas SET " + "StartTime=FROM_UNIXTIME(%ld)," + "EndTime=FROM_UNIXTIME(%ld)," + "Event='%s',Location='%s',Txt='%s'" + " WHERE AgdCod=%ld AND UsrCod=%ld", + AgdEvent->TimeUTC[Agd_START_TIME], + AgdEvent->TimeUTC[Agd_END_TIME ], + AgdEvent->Event,AgdEvent->Location,Txt, + AgdEvent->AgdCod,AgdEvent->UsrCod); } /*****************************************************************************/ diff --git a/swad_announcement.c b/swad_announcement.c index b8b45d936..05e19a415 100644 --- a/swad_announcement.c +++ b/swad_announcement.c @@ -532,10 +532,10 @@ void Ann_HideActiveAnnouncement (void) AnnCod = Ann_GetParamAnnCod (); /***** Set global announcement as hidden *****/ - DB_BuildQuery ("UPDATE announcements SET Status=%u" - " WHERE AnnCod=%ld", - (unsigned) Ann_OBSOLETE_ANNOUNCEMENT,AnnCod); - DB_QueryUPDATE_new ("can not hide announcement"); + DB_QueryUPDATE ("can not hide announcement", + "UPDATE announcements SET Status=%u" + " WHERE AnnCod=%ld", + (unsigned) Ann_OBSOLETE_ANNOUNCEMENT,AnnCod); } /*****************************************************************************/ @@ -550,10 +550,10 @@ void Ann_RevealHiddenAnnouncement (void) AnnCod = Ann_GetParamAnnCod (); /***** Set global announcement as shown *****/ - DB_BuildQuery ("UPDATE announcements SET Status=%u" - " WHERE AnnCod=%ld", - (unsigned) Ann_ACTIVE_ANNOUNCEMENT,AnnCod); - DB_QueryUPDATE_new ("can not reveal announcement"); + DB_QueryUPDATE ("can not reveal announcement", + "UPDATE announcements SET Status=%u" + " WHERE AnnCod=%ld", + (unsigned) Ann_ACTIVE_ANNOUNCEMENT,AnnCod); } /*****************************************************************************/ diff --git a/swad_assignment.c b/swad_assignment.c index 68ae9abed..a503e4be7 100644 --- a/swad_assignment.c +++ b/swad_assignment.c @@ -1060,10 +1060,10 @@ void Asg_HideAssignment (void) Asg_GetDataOfAssignmentByCod (&Asg); /***** Hide assignment *****/ - DB_BuildQuery ("UPDATE assignments SET Hidden='Y'" - " WHERE AsgCod=%ld AND CrsCod=%ld", - Asg.AsgCod,Gbl.CurrentCrs.Crs.CrsCod); - DB_QueryUPDATE_new ("can not hide assignment"); + DB_QueryUPDATE ("can not hide assignment", + "UPDATE assignments SET Hidden='Y'" + " WHERE AsgCod=%ld AND CrsCod=%ld", + Asg.AsgCod,Gbl.CurrentCrs.Crs.CrsCod); /***** Write message to show the change made *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), @@ -1092,10 +1092,10 @@ void Asg_ShowAssignment (void) Asg_GetDataOfAssignmentByCod (&Asg); /***** Hide assignment *****/ - DB_BuildQuery ("UPDATE assignments SET Hidden='N'" - " WHERE AsgCod=%ld AND CrsCod=%ld", - Asg.AsgCod,Gbl.CurrentCrs.Crs.CrsCod); - DB_QueryUPDATE_new ("can not show assignment"); + DB_QueryUPDATE ("can not show assignment", + "UPDATE assignments SET Hidden='N'" + " WHERE AsgCod=%ld AND CrsCod=%ld", + Asg.AsgCod,Gbl.CurrentCrs.Crs.CrsCod); /***** Write message to show the change made *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), @@ -1482,10 +1482,11 @@ void Asg_RecFormAssignment (void) static void Asg_UpdateNumUsrsNotifiedByEMailAboutAssignment (long AsgCod,unsigned NumUsrsToBeNotifiedByEMail) { /***** Update number of users notified *****/ - DB_BuildQuery ("UPDATE assignments SET NumNotif=NumNotif+%u" - " WHERE AsgCod=%ld", - NumUsrsToBeNotifiedByEMail,AsgCod); - DB_QueryUPDATE_new ("can not update the number of notifications of an assignment"); + DB_QueryUPDATE ("can not update the number of notifications" + " of an assignment", + "UPDATE assignments SET NumNotif=NumNotif+%u" + " WHERE AsgCod=%ld", + NumUsrsToBeNotifiedByEMail,AsgCod); } /*****************************************************************************/ @@ -1522,18 +1523,18 @@ static void Asg_CreateAssignment (struct Assignment *Asg,const char *Txt) static void Asg_UpdateAssignment (struct Assignment *Asg,const char *Txt) { /***** Update the data of the assignment *****/ - DB_BuildQuery ("UPDATE assignments SET " - "StartTime=FROM_UNIXTIME(%ld)," - "EndTime=FROM_UNIXTIME(%ld)," - "Title='%s',Folder='%s',Txt='%s'" - " WHERE AsgCod=%ld AND CrsCod=%ld", - Asg->TimeUTC[Dat_START_TIME], - Asg->TimeUTC[Dat_END_TIME ], - Asg->Title, - Asg->Folder, - Txt, - Asg->AsgCod,Gbl.CurrentCrs.Crs.CrsCod); - DB_QueryUPDATE_new ("can not update assignment"); + DB_QueryUPDATE ("can not update assignment", + "UPDATE assignments SET " + "StartTime=FROM_UNIXTIME(%ld)," + "EndTime=FROM_UNIXTIME(%ld)," + "Title='%s',Folder='%s',Txt='%s'" + " WHERE AsgCod=%ld AND CrsCod=%ld", + Asg->TimeUTC[Dat_START_TIME], + Asg->TimeUTC[Dat_END_TIME ], + Asg->Title, + Asg->Folder, + Txt, + Asg->AsgCod,Gbl.CurrentCrs.Crs.CrsCod); /***** Update groups *****/ /* Remove old groups */ diff --git a/swad_attendance.c b/swad_attendance.c index fb216be2a..bd674d8c4 100644 --- a/swad_attendance.c +++ b/swad_attendance.c @@ -979,10 +979,10 @@ void Att_HideAttEvent (void) Att_GetDataOfAttEventByCodAndCheckCrs (&Att); /***** Hide attendance event *****/ - DB_BuildQuery ("UPDATE att_events SET Hidden='Y'" - " WHERE AttCod=%ld AND CrsCod=%ld", - Att.AttCod,Gbl.CurrentCrs.Crs.CrsCod); - DB_QueryUPDATE_new ("can not hide attendance event"); + DB_QueryUPDATE ("can not hide attendance event", + "UPDATE att_events SET Hidden='Y'" + " WHERE AttCod=%ld AND CrsCod=%ld", + Att.AttCod,Gbl.CurrentCrs.Crs.CrsCod); /***** Write message to show the change made *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), @@ -1011,10 +1011,10 @@ void Att_ShowAttEvent (void) Att_GetDataOfAttEventByCodAndCheckCrs (&Att); /***** Hide attendance event *****/ - DB_BuildQuery ("UPDATE att_events SET Hidden='N'" - " WHERE AttCod=%ld AND CrsCod=%ld", - Att.AttCod,Gbl.CurrentCrs.Crs.CrsCod); - DB_QueryUPDATE_new ("can not show attendance event"); + DB_QueryUPDATE ("can not show attendance event", + "UPDATE att_events SET Hidden='N'" + " WHERE AttCod=%ld AND CrsCod=%ld", + Att.AttCod,Gbl.CurrentCrs.Crs.CrsCod); /***** Write message to show the change made *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), @@ -1386,22 +1386,22 @@ void Att_CreateAttEvent (struct AttendanceEvent *Att,const char *Txt) void Att_UpdateAttEvent (struct AttendanceEvent *Att,const char *Txt) { /***** Update the data of the attendance event *****/ - DB_BuildQuery ("UPDATE att_events SET " - "Hidden='%c'," - "StartTime=FROM_UNIXTIME(%ld)," - "EndTime=FROM_UNIXTIME(%ld)," - "CommentTchVisible='%c',Title='%s',Txt='%s'" - " WHERE AttCod=%ld AND CrsCod=%ld", - Att->Hidden ? 'Y' : - 'N', - Att->TimeUTC[Att_START_TIME], - Att->TimeUTC[Att_END_TIME ], - Att->CommentTchVisible ? 'Y' : - 'N', - Att->Title, - Txt, - Att->AttCod,Gbl.CurrentCrs.Crs.CrsCod); - DB_QueryUPDATE_new ("can not update attendance event"); + DB_QueryUPDATE ("can not update attendance event", + "UPDATE att_events SET " + "Hidden='%c'," + "StartTime=FROM_UNIXTIME(%ld)," + "EndTime=FROM_UNIXTIME(%ld)," + "CommentTchVisible='%c',Title='%s',Txt='%s'" + " WHERE AttCod=%ld AND CrsCod=%ld", + Att->Hidden ? 'Y' : + 'N', + Att->TimeUTC[Att_START_TIME], + Att->TimeUTC[Att_END_TIME ], + Att->CommentTchVisible ? 'Y' : + 'N', + Att->Title, + Txt, + Att->AttCod,Gbl.CurrentCrs.Crs.CrsCod); /***** Update groups *****/ /* Remove old groups */ @@ -2592,13 +2592,11 @@ void Att_RegUsrInAttEventNotChangingComments (long AttCod,long UsrCod) { // If already present ==> nothing to do if (!Present) - { /***** Set user as present in database *****/ - DB_BuildQuery ("UPDATE att_usr SET Present='Y'" - " WHERE AttCod=%ld AND UsrCod=%ld", - AttCod,UsrCod); - DB_QueryUPDATE_new ("can not set user as present in an event"); - } + DB_QueryUPDATE ("can not set user as present in an event", + "UPDATE att_usr SET Present='Y'" + " WHERE AttCod=%ld AND UsrCod=%ld", + AttCod,UsrCod); } else // User is not in table att_usr Att_RegUsrInAttEventChangingComments (AttCod,UsrCod,true,"",""); diff --git a/swad_banner.c b/swad_banner.c index deec166db..251e6f54b 100644 --- a/swad_banner.c +++ b/swad_banner.c @@ -572,14 +572,12 @@ static void Ban_ShowOrHideBanner (bool Hide) /***** Mark file as hidden/visible in database *****/ if (Ban.Hidden != Hide) - { - DB_BuildQuery ("UPDATE banners SET Hidden='%c'" - " WHERE BanCod=%ld", - Hide ? 'Y' : - 'N', - Ban.BanCod); - DB_QueryUPDATE_new ("can not change status of a banner in database"); - } + DB_QueryUPDATE ("can not change status of a banner in database", + "UPDATE banners SET Hidden='%c'" + " WHERE BanCod=%ld", + Hide ? 'Y' : + 'N', + Ban.BanCod); /***** Write message to show the change made *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), @@ -725,9 +723,9 @@ static void Ban_UpdateBanNameDB (long BanCod,const char *FieldName, const char *NewBanName) { /***** Update banner changing old name by new name *****/ - DB_BuildQuery ("UPDATE banners SET %s='%s' WHERE BanCod=%ld", - FieldName,NewBanName,BanCod); - DB_QueryUPDATE_new ("can not update the name of a banner"); + DB_QueryUPDATE ("can not update the name of a banner", + "UPDATE banners SET %s='%s' WHERE BanCod=%ld", + FieldName,NewBanName,BanCod); } /*****************************************************************************/ @@ -755,9 +753,9 @@ void Ban_ChangeBannerImg (void) if (NewImg[0]) { /* Update the table changing old image by new image */ - DB_BuildQuery ("UPDATE banners SET Img='%s' WHERE BanCod=%ld", - NewImg,Ban->BanCod); - DB_QueryUPDATE_new ("can not update the image of a banner"); + DB_QueryUPDATE ("can not update the image of a banner", + "UPDATE banners SET Img='%s' WHERE BanCod=%ld", + NewImg,Ban->BanCod); /***** Write message to show the change made *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), @@ -800,9 +798,9 @@ void Ban_ChangeBannerWWW (void) if (NewWWW[0]) { /* Update the table changing old WWW by new WWW */ - DB_BuildQuery ("UPDATE banners SET WWW='%s' WHERE BanCod=%ld", - NewWWW,Ban->BanCod); - DB_QueryUPDATE_new ("can not update the web of a banner"); + DB_QueryUPDATE ("can not update the web of a banner", + "UPDATE banners SET WWW='%s' WHERE BanCod=%ld", + NewWWW,Ban->BanCod); /***** Write message to show the change made *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), diff --git a/swad_calendar.c b/swad_calendar.c index ecdfbed72..b9c5c7bb6 100644 --- a/swad_calendar.c +++ b/swad_calendar.c @@ -151,13 +151,11 @@ void Cal_ChangeFirstDayOfWeek (void) /***** Store icon first day of week database *****/ if (Gbl.Usrs.Me.Logged) - { - DB_BuildQuery ("UPDATE usr_data SET FirstDayOfWeek=%u" - " WHERE UsrCod=%ld", - Gbl.Prefs.FirstDayOfWeek, - Gbl.Usrs.Me.UsrDat.UsrCod); - DB_QueryUPDATE_new ("can not update your preference about first day of week"); - } + DB_QueryUPDATE ("can not update your preference about first day of week", + "UPDATE usr_data SET FirstDayOfWeek=%u" + " WHERE UsrCod=%ld", + Gbl.Prefs.FirstDayOfWeek, + Gbl.Usrs.Me.UsrDat.UsrCod); /***** Set preferences from current IP *****/ Pre_SetPrefsFromIP (); diff --git a/swad_centre.c b/swad_centre.c index a803b2cef..daab57d36 100644 --- a/swad_centre.c +++ b/swad_centre.c @@ -1876,9 +1876,9 @@ void Ctr_ContEditAfterChgCtrInConfig (void) static void Ctr_UpdateCtrInsDB (long CtrCod,long InsCod) { /***** Update institution in table of centres *****/ - DB_BuildQuery ("UPDATE centres SET InsCod=%ld WHERE CtrCod=%ld", - InsCod,CtrCod); - DB_QueryUPDATE_new ("can not update the institution of a centre"); + DB_QueryUPDATE ("can not update the institution of a centre", + "UPDATE centres SET InsCod=%ld WHERE CtrCod=%ld", + InsCod,CtrCod); } /*****************************************************************************/ @@ -1939,9 +1939,9 @@ void Ctr_ChangeCtrPlcInConfig (void) static void Ctr_UpdateCtrPlcDB (long CtrCod,long NewPlcCod) { - DB_BuildQuery ("UPDATE centres SET PlcCod=%ld WHERE CtrCod=%ld", - NewPlcCod,CtrCod); - DB_QueryUPDATE_new ("can not update the place of a centre"); + DB_QueryUPDATE ("can not update the place of a centre", + "UPDATE centres SET PlcCod=%ld WHERE CtrCod=%ld", + NewPlcCod,CtrCod); } /*****************************************************************************/ @@ -2079,9 +2079,9 @@ static bool Ctr_CheckIfCtrNameExistsInIns (const char *FieldName,const char *Nam static void Ctr_UpdateInsNameDB (long CtrCod,const char *FieldName,const char *NewCtrName) { /***** Update centre changing old name by new name */ - DB_BuildQuery ("UPDATE centres SET %s='%s' WHERE CtrCod=%ld", - FieldName,NewCtrName,CtrCod); - DB_QueryUPDATE_new ("can not update the name of a centre"); + DB_QueryUPDATE ("can not update the name of a centre", + "UPDATE centres SET %s='%s' WHERE CtrCod=%ld", + FieldName,NewCtrName,CtrCod); } /*****************************************************************************/ @@ -2165,9 +2165,9 @@ static void Ctr_UpdateCtrWWWDB (long CtrCod, const char NewWWW[Cns_MAX_BYTES_WWW + 1]) { /***** Update database changing old WWW by new WWW *****/ - DB_BuildQuery ("UPDATE centres SET WWW='%s' WHERE CtrCod=%ld", - NewWWW,CtrCod); - DB_QueryUPDATE_new ("can not update the web of a centre"); + DB_QueryUPDATE ("can not update the web of a centre", + "UPDATE centres SET WWW='%s' WHERE CtrCod=%ld", + NewWWW,CtrCod); } /*****************************************************************************/ @@ -2198,9 +2198,9 @@ void Ctr_ChangeCtrStatus (void) Ctr_GetDataOfCentreByCod (&Gbl.Ctrs.EditingCtr); /***** Update status in table of centres *****/ - DB_BuildQuery ("UPDATE centres SET Status=%u WHERE CtrCod=%ld", - (unsigned) Status,Gbl.Ctrs.EditingCtr.CtrCod); - DB_QueryUPDATE_new ("can not update the status of a centre"); + DB_QueryUPDATE ("can not update the status of a centre", + "UPDATE centres SET Status=%u WHERE CtrCod=%ld", + (unsigned) Status,Gbl.Ctrs.EditingCtr.CtrCod); Gbl.Ctrs.EditingCtr.Status = Status; /***** Write message to show the change made @@ -2480,10 +2480,11 @@ void Ctr_ChangeCtrPhotoAttribution (void) Par_GetParToText ("Attribution",NewPhotoAttribution,Img_MAX_BYTES_ATTRIBUTION); /***** Update the table changing old attribution by new attribution *****/ - DB_BuildQuery ("UPDATE centres SET PhotoAttribution='%s'" - " WHERE CtrCod=%ld", - NewPhotoAttribution,Gbl.CurrentCtr.Ctr.CtrCod); - DB_QueryUPDATE_new ("can not update the photo attribution of the current centre"); + DB_QueryUPDATE ("can not update the photo attribution" + " of the current centre", + "UPDATE centres SET PhotoAttribution='%s'" + " WHERE CtrCod=%ld", + NewPhotoAttribution,Gbl.CurrentCtr.Ctr.CtrCod); /***** Show the centre information again *****/ Ctr_ShowConfiguration (); diff --git a/swad_changelog.h b/swad_changelog.h index 24eef3340..da0feb7be 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.23 (2018-11-03)" +#define Log_PLATFORM_VERSION "SWAD 18.11.24 (2018-11-03)" #define CSS_FILE "swad18.4.css" #define JS_FILE "swad17.17.1.js" /* + Version 18.11.24: Nov 03, 2018 Joining building and performing query into one function. (236636 lines) Version 18.11.23: Nov 03, 2018 Joining building and performing query into one function. (236630 lines) Version 18.11.22: Nov 02, 2018 Joining building and performing query into one function. (236589 lines) Version 18.11.21: Nov 02, 2018 Joining building and performing query into one function. (236580 lines) diff --git a/swad_country.c b/swad_country.c index 61ac7347c..1e3d4544c 100644 --- a/swad_country.c +++ b/swad_country.c @@ -1868,9 +1868,9 @@ static bool Cty_CheckIfCountryNameExists (Txt_Language_t Language,const char *Na static void Cty_UpdateCtyNameDB (long CtyCod,const char *FieldName,const char *NewCtyName) { /***** Update country changing old name by new name */ - DB_BuildQuery ("UPDATE countries SET %s='%s' WHERE CtyCod='%03ld'", - FieldName,NewCtyName,CtyCod); - DB_QueryUPDATE_new ("can not update the name of a country"); + DB_QueryUPDATE ("can not update the name of a country", + "UPDATE countries SET %s='%s' WHERE CtyCod='%03ld'", + FieldName,NewCtyName,CtyCod); /***** Flush cache *****/ Cty_FlushCacheCountryName (); @@ -1903,10 +1903,10 @@ void Cty_ChangeCtyWWW (void) Cty_GetDataOfCountryByCod (Cty,Cty_GET_EXTRA_DATA); /***** Update the table changing old WWW by new WWW *****/ - DB_BuildQuery ("UPDATE countries SET WWW_%s='%s'" - " WHERE CtyCod='%03ld'", - Txt_STR_LANG_ID[Language],NewWWW,Cty->CtyCod); - DB_QueryUPDATE_new ("can not update the web of a country"); + DB_QueryUPDATE ("can not update the web of a country", + "UPDATE countries SET WWW_%s='%s'" + " WHERE CtyCod='%03ld'", + Txt_STR_LANG_ID[Language],NewWWW,Cty->CtyCod); Str_Copy (Cty->WWW[Language],NewWWW, Cns_MAX_BYTES_WWW); @@ -1933,10 +1933,10 @@ void Cty_ChangeCtyMapAttribution (void) Par_GetParToText ("Attribution",NewMapAttribution,Img_MAX_BYTES_ATTRIBUTION); /***** Update the table changing old attribution by new attribution *****/ - DB_BuildQuery ("UPDATE countries SET MapAttribution='%s'" - " WHERE CtyCod='%03ld'", - NewMapAttribution,Gbl.CurrentCty.Cty.CtyCod); - DB_QueryUPDATE_new ("can not update the map attribution of a country"); + DB_QueryUPDATE ("can not update the map attribution of a country", + "UPDATE countries SET MapAttribution='%s'" + " WHERE CtyCod='%03ld'", + NewMapAttribution,Gbl.CurrentCty.Cty.CtyCod); /***** Show the country information again *****/ Cty_ShowConfiguration (); diff --git a/swad_course.c b/swad_course.c index 12a01560e..befea977e 100644 --- a/swad_course.c +++ b/swad_course.c @@ -2183,10 +2183,10 @@ static void Crs_EmptyCourseCompletely (long CrsCod) /***** Remove exam announcements in the course *****/ /* Mark all exam announcements in the course as deleted */ - DB_BuildQuery ("UPDATE exam_announcements SET Status=%u" - " WHERE CrsCod=%ld", - (unsigned) Exa_DELETED_EXAM_ANNOUNCEMENT,CrsCod); - DB_QueryUPDATE_new ("can not remove exam announcements of a course"); + DB_QueryUPDATE ("can not remove exam announcements of a course", + "UPDATE exam_announcements SET Status=%u" + " WHERE CrsCod=%ld", + (unsigned) Exa_DELETED_EXAM_ANNOUNCEMENT,CrsCod); /***** Remove course cards of the course *****/ /* Remove content of course cards */ @@ -2445,9 +2445,9 @@ void Crs_ContEditAfterChgCrsInConfig (void) static void Crs_UpdateCrsDegDB (long CrsCod,long DegCod) { /***** Update degree in table of courses *****/ - DB_BuildQuery ("UPDATE courses SET DegCod=%ld WHERE CrsCod=%ld", - DegCod,CrsCod); - DB_QueryUPDATE_new ("can not move course to another degree"); + DB_QueryUPDATE ("can not move course to another degree", + "UPDATE courses SET DegCod=%ld WHERE CrsCod=%ld", + DegCod,CrsCod); } /*****************************************************************************/ @@ -2591,9 +2591,9 @@ void Crs_ChangeCrsYear (void) static void Crs_UpdateCrsYear (struct Course *Crs,unsigned NewYear) { /***** Update year/semester in table of courses *****/ - DB_BuildQuery ("UPDATE courses SET Year=%u WHERE CrsCod=%ld", - NewYear,Crs->CrsCod); - DB_QueryUPDATE_new ("can not update the year of a course"); + DB_QueryUPDATE ("can not update the year of a course", + "UPDATE courses SET Year=%u WHERE CrsCod=%ld", + NewYear,Crs->CrsCod); /***** Copy course year/semester *****/ Crs->Year = NewYear; @@ -2606,10 +2606,10 @@ static void Crs_UpdateCrsYear (struct Course *Crs,unsigned NewYear) void Crs_UpdateInstitutionalCrsCod (struct Course *Crs,const char *NewInstitutionalCrsCod) { /***** Update institutional course code in table of courses *****/ - DB_BuildQuery ("UPDATE courses SET InsCrsCod='%s' WHERE CrsCod=%ld", - NewInstitutionalCrsCod,Crs->CrsCod); - DB_QueryUPDATE_new ("can not update the institutional code" - " of the current course"); + DB_QueryUPDATE ("can not update the institutional code" + " of the current course", + "UPDATE courses SET InsCrsCod='%s' WHERE CrsCod=%ld", + NewInstitutionalCrsCod,Crs->CrsCod); /***** Copy institutional course code *****/ Str_Copy (Crs->InstitutionalCrsCod,NewInstitutionalCrsCod, @@ -2766,9 +2766,9 @@ static bool Crs_CheckIfCrsNameExistsInYearOfDeg (const char *FieldName,const cha static void Crs_UpdateCrsNameDB (long CrsCod,const char *FieldName,const char *NewCrsName) { /***** Update course changing old name by new name *****/ - DB_BuildQuery ("UPDATE courses SET %s='%s' WHERE CrsCod=%ld", - FieldName,NewCrsName,CrsCod); - DB_QueryUPDATE_new ("can not update the name of a course"); + DB_QueryUPDATE ("can not update the name of a course", + "UPDATE courses SET %s='%s' WHERE CrsCod=%ld", + FieldName,NewCrsName,CrsCod); } /*****************************************************************************/ @@ -2800,9 +2800,9 @@ void Crs_ChangeCrsStatus (void) Crs_GetDataOfCourseByCod (&Gbl.Degs.EditingCrs); /***** Update status in table of courses *****/ - DB_BuildQuery ("UPDATE courses SET Status=%u WHERE CrsCod=%ld", - (unsigned) Status,Gbl.Degs.EditingCrs.CrsCod); - DB_QueryUPDATE_new ("can not update the status of a course"); + DB_QueryUPDATE ("can not update the status of a course", + "UPDATE courses SET Status=%u WHERE CrsCod=%ld", + (unsigned) Status,Gbl.Degs.EditingCrs.CrsCod); Gbl.Degs.EditingCrs.Status = Status; /***** Create message to show the change made *****/ @@ -3356,13 +3356,11 @@ void Crs_UpdateCrsLast (void) { if (Gbl.CurrentCrs.Crs.CrsCod > 0 && Gbl.Usrs.Me.Role.Logged >= Rol_STD) - { /***** Update my last access to current course *****/ - DB_BuildQuery ("REPLACE INTO crs_last (CrsCod,LastTime)" - " VALUES (%ld,NOW())", - Gbl.CurrentCrs.Crs.CrsCod); - DB_QueryUPDATE_new ("can not update last access to current course"); - } + DB_QueryUPDATE ("can not update last access to current course", + "REPLACE INTO crs_last (CrsCod,LastTime)" + " VALUES (%ld,NOW())", + Gbl.CurrentCrs.Crs.CrsCod); } /*****************************************************************************/ diff --git a/swad_database.c b/swad_database.c index d71a525ff..65fbc5bf6 100644 --- a/swad_database.c +++ b/swad_database.c @@ -3313,9 +3313,22 @@ void DB_QueryREPLACE (const char *MsgError,const char *fmt,...) /******************** Make a UPDATE query from database **********************/ /*****************************************************************************/ -void DB_QueryUPDATE_new (const char *MsgError) +void DB_QueryUPDATE (const char *MsgError,const char *fmt,...) { - DB_QueryUPDATE_old (&Gbl.DB.QueryPtr,MsgError); + va_list ap; + int NumBytesPrinted; + char *Query = NULL; + + va_start (ap,fmt); + NumBytesPrinted = vasprintf (&Query,fmt,ap); + va_end (ap); + + if (NumBytesPrinted < 0) // If memory allocation wasn't possible, + // or some other error occurs, + // vasprintf will return -1 + Lay_NotEnoughMemoryExit (); + + DB_QueryUPDATE_old (&Query,MsgError); } void DB_QueryUPDATE_old (char **Query,const char *MsgError) diff --git a/swad_database.h b/swad_database.h index e2f2879d2..59aa80f55 100644 --- a/swad_database.h +++ b/swad_database.h @@ -55,7 +55,7 @@ long DB_QueryINSERTandReturnCode (const char *MsgError,const char *fmt,...); void DB_QueryREPLACE (const char *MsgError,const char *fmt,...); -void DB_QueryUPDATE_new (const char *MsgError); +void DB_QueryUPDATE (const char *MsgError,const char *fmt,...); void DB_QueryUPDATE_old (char **Query,const char *MsgError); void DB_QueryDELETE (const char *MsgError,const char *fmt,...); diff --git a/swad_date.c b/swad_date.c index e214301a9..8fdf6de52 100644 --- a/swad_date.c +++ b/swad_date.c @@ -184,13 +184,11 @@ void Dat_ChangeDateFormat (void) /***** Store date format in database *****/ if (Gbl.Usrs.Me.Logged) - { - DB_BuildQuery ("UPDATE usr_data SET DateFormat=%u" - " WHERE UsrCod=%ld", - (unsigned) Gbl.Prefs.DateFormat, - Gbl.Usrs.Me.UsrDat.UsrCod); - DB_QueryUPDATE_new ("can not update your preference about date format"); - } + DB_QueryUPDATE ("can not update your preference about date format", + "UPDATE usr_data SET DateFormat=%u" + " WHERE UsrCod=%ld", + (unsigned) Gbl.Prefs.DateFormat, + Gbl.Usrs.Me.UsrDat.UsrCod); /***** Set preferences from current IP *****/ Pre_SetPrefsFromIP (); diff --git a/swad_degree.c b/swad_degree.c index 45eca5b38..d2817a68c 100644 --- a/swad_degree.c +++ b/swad_degree.c @@ -2040,9 +2040,9 @@ static bool Deg_CheckIfDegNameExistsInCtr (const char *FieldName,const char *Nam static void Deg_UpdateDegNameDB (long DegCod,const char *FieldName,const char *NewDegName) { /***** Update degree changing old name by new name *****/ - DB_BuildQuery ("UPDATE degrees SET %s='%s' WHERE DegCod=%ld", - FieldName,NewDegName,DegCod); - DB_QueryUPDATE_new ("can not update the name of a degree"); + DB_QueryUPDATE ("can not update the name of a degree", + "UPDATE degrees SET %s='%s' WHERE DegCod=%ld", + FieldName,NewDegName,DegCod); } /*****************************************************************************/ @@ -2119,9 +2119,9 @@ void Deg_ContEditAfterChgDegInConfig (void) static void Deg_UpdateDegCtrDB (long DegCod,long CtrCod) { /***** Update centre in table of degrees *****/ - DB_BuildQuery ("UPDATE degrees SET CtrCod=%ld WHERE DegCod=%ld", - CtrCod,DegCod); - DB_QueryUPDATE_new ("can not update the centre of a degree"); + DB_QueryUPDATE ("can not update the centre of a degree", + "UPDATE degrees SET CtrCod=%ld WHERE DegCod=%ld", + CtrCod,DegCod); } /*****************************************************************************/ @@ -2205,9 +2205,9 @@ void Deg_ChangeDegWWWInConfig (void) static void Deg_UpdateDegWWWDB (long DegCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1]) { /***** Update database changing old WWW by new WWW *****/ - DB_BuildQuery ("UPDATE degrees SET WWW='%s' WHERE DegCod=%ld", - NewWWW,DegCod); - DB_QueryUPDATE_new ("can not update the web of a degree"); + DB_QueryUPDATE ("can not update the web of a degree", + "UPDATE degrees SET WWW='%s' WHERE DegCod=%ld", + NewWWW,DegCod); } /*****************************************************************************/ @@ -2239,9 +2239,9 @@ void Deg_ChangeDegStatus (void) Deg_GetDataOfDegreeByCod (&Gbl.Degs.EditingDeg); /***** Update status in table of degrees *****/ - DB_BuildQuery ("UPDATE degrees SET Status=%u WHERE DegCod=%ld", - (unsigned) Status,Gbl.Degs.EditingDeg.DegCod); - DB_QueryUPDATE_new ("can not update the status of a degree"); + DB_QueryUPDATE ("can not update the status of a degree", + "UPDATE degrees SET Status=%u WHERE DegCod=%ld", + (unsigned) Status,Gbl.Degs.EditingDeg.DegCod); Gbl.Degs.EditingDeg.Status = Status; diff --git a/swad_degree_type.c b/swad_degree_type.c index ffbd0f99f..f1e534207 100644 --- a/swad_degree_type.c +++ b/swad_degree_type.c @@ -957,10 +957,10 @@ void DT_RenameDegreeType (void) else { /* Update the table changing old name by new name */ - DB_BuildQuery ("UPDATE deg_types SET DegTypName='%s'" - " WHERE DegTypCod=%ld", - NewNameDegTyp,DegTyp->DegTypCod); - DB_QueryUPDATE_new ("can not update the type of a degree"); + DB_QueryUPDATE ("can not update the type of a degree", + "UPDATE deg_types SET DegTypName='%s'" + " WHERE DegTypCod=%ld", + NewNameDegTyp,DegTyp->DegTypCod); /* Write message to show the change made */ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), @@ -1017,9 +1017,9 @@ void DT_ChangeDegreeType (void) Deg_GetDataOfDegreeByCod (&Gbl.Degs.EditingDeg); /***** Update the table of degrees changing old type by new type *****/ - DB_BuildQuery ("UPDATE degrees SET DegTypCod=%ld WHERE DegCod=%ld", - NewDegTypCod,Gbl.Degs.EditingDeg.DegCod); - DB_QueryUPDATE_new ("can not update the type of a degree"); + DB_QueryUPDATE ("can not update the type of a degree", + "UPDATE degrees SET DegTypCod=%ld WHERE DegCod=%ld", + NewDegTypCod,Gbl.Degs.EditingDeg.DegCod); /***** Write message to show the change made and put button to go to degree changed *****/ diff --git a/swad_department.c b/swad_department.c index 89f8ad085..141e945a1 100644 --- a/swad_department.c +++ b/swad_department.c @@ -652,9 +652,9 @@ void Dpt_ChangeDepartIns (void) Dpt->InsCod = Ins_GetAndCheckParamOtherInsCod (1); /***** Update institution in table of departments *****/ - DB_BuildQuery ("UPDATE departments SET InsCod=%ld WHERE DptCod=%ld", - Dpt->InsCod,Dpt->DptCod); - DB_QueryUPDATE_new ("can not update the institution of a department"); + DB_QueryUPDATE ("can not update the institution of a department", + "UPDATE departments SET InsCod=%ld WHERE DptCod=%ld", + Dpt->InsCod,Dpt->DptCod); /***** Write message to show the change made *****/ Ale_ShowAlert (Ale_SUCCESS,Txt_The_institution_of_the_department_has_changed); @@ -794,9 +794,9 @@ static bool Dpt_CheckIfDepartmentNameExists (const char *FieldName,const char *N static void Dpt_UpdateDegNameDB (long DptCod,const char *FieldName,const char *NewDptName) { /***** Update department changing old name by new name *****/ - DB_BuildQuery ("UPDATE departments SET %s='%s' WHERE DptCod=%ld", - FieldName,NewDptName,DptCod); - DB_QueryUPDATE_new ("can not update the name of a department"); + DB_QueryUPDATE ("can not update the name of a department", + "UPDATE departments SET %s='%s' WHERE DptCod=%ld", + FieldName,NewDptName,DptCod); } /******************************************************************************/ @@ -823,9 +823,9 @@ void Dpt_ChangeDptWWW (void) if (NewWWW[0]) { /* Update the table changing old WWW by new WWW */ - DB_BuildQuery ("UPDATE departments SET WWW='%s' WHERE DptCod=%ld", - NewWWW,Dpt->DptCod); - DB_QueryUPDATE_new ("can not update the web of a department"); + DB_QueryUPDATE ("can not update the web of a department", + "UPDATE departments SET WWW='%s' WHERE DptCod=%ld", + NewWWW,Dpt->DptCod); /***** Write message to show the change made *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), diff --git a/swad_enrolment.c b/swad_enrolment.c index 060abcbc8..ae202ef76 100644 --- a/swad_enrolment.c +++ b/swad_enrolment.c @@ -221,10 +221,10 @@ void Enr_ModifyRoleInCurrentCrs (struct UsrData *UsrDat,Rol_Role_t NewRole) } /***** Update the role of a user in a course *****/ - DB_BuildQuery ("UPDATE crs_usr SET Role=%u" - " WHERE CrsCod=%ld AND UsrCod=%ld", - (unsigned) NewRole,Gbl.CurrentCrs.Crs.CrsCod,UsrDat->UsrCod); - DB_QueryUPDATE_new ("can not modify user's role in course"); + DB_QueryUPDATE ("can not modify user's role in course", + "UPDATE crs_usr SET Role=%u" + " WHERE CrsCod=%ld AND UsrCod=%ld", + (unsigned) NewRole,Gbl.CurrentCrs.Crs.CrsCod,UsrDat->UsrCod); /***** Flush caches *****/ Usr_FlushCachesUsr (); @@ -526,27 +526,27 @@ void Enr_UpdateUsrData (struct UsrData *UsrDat) /***** Update user's common data *****/ Usr_CreateBirthdayStrDB (UsrDat,BirthdayStrDB); // It can include start and ending apostrophes - DB_BuildQuery ("UPDATE usr_data" - " SET Password='%s'," - "Surname1='%s',Surname2='%s',FirstName='%s',Sex='%s'," - "CtyCod=%ld," - "LocalAddress='%s',LocalPhone='%s'," - "FamilyAddress='%s',FamilyPhone='%s'," - "OriginPlace='%s',Birthday=%s," - "Comments='%s'" - " WHERE UsrCod=%ld", - UsrDat->Password, - UsrDat->Surname1,UsrDat->Surname2,UsrDat->FirstName, - Usr_StringsSexDB[UsrDat->Sex], - UsrDat->CtyCod, - UsrDat->LocalAddress,UsrDat->LocalPhone, - UsrDat->FamilyAddress,UsrDat->FamilyPhone, - UsrDat->OriginPlace, - BirthdayStrDB, - UsrDat->Comments ? UsrDat->Comments : - "", - UsrDat->UsrCod); - DB_QueryUPDATE_new ("can not update user's data"); + DB_QueryUPDATE ("can not update user's data", + "UPDATE usr_data" + " SET Password='%s'," + "Surname1='%s',Surname2='%s',FirstName='%s',Sex='%s'," + "CtyCod=%ld," + "LocalAddress='%s',LocalPhone='%s'," + "FamilyAddress='%s',FamilyPhone='%s'," + "OriginPlace='%s',Birthday=%s," + "Comments='%s'" + " WHERE UsrCod=%ld", + UsrDat->Password, + UsrDat->Surname1,UsrDat->Surname2,UsrDat->FirstName, + Usr_StringsSexDB[UsrDat->Sex], + UsrDat->CtyCod, + UsrDat->LocalAddress,UsrDat->LocalPhone, + UsrDat->FamilyAddress,UsrDat->FamilyPhone, + UsrDat->OriginPlace, + BirthdayStrDB, + UsrDat->Comments ? UsrDat->Comments : + "", + UsrDat->UsrCod); } /*****************************************************************************/ @@ -569,15 +569,15 @@ void Enr_FilterUsrDat (struct UsrData *UsrDat) void Enr_UpdateInstitutionCentreDepartment (void) { - DB_BuildQuery ("UPDATE usr_data" - " SET InsCtyCod=%ld,InsCod=%ld,CtrCod=%ld,DptCod=%ld" - " WHERE UsrCod=%ld", - Gbl.Usrs.Me.UsrDat.InsCtyCod, - Gbl.Usrs.Me.UsrDat.InsCod, - Gbl.Usrs.Me.UsrDat.Tch.CtrCod, - Gbl.Usrs.Me.UsrDat.Tch.DptCod, - Gbl.Usrs.Me.UsrDat.UsrCod); - DB_QueryUPDATE_new ("can not update institution, centre and department"); + DB_QueryUPDATE ("can not update institution, centre and department", + "UPDATE usr_data" + " SET InsCtyCod=%ld,InsCod=%ld,CtrCod=%ld,DptCod=%ld" + " WHERE UsrCod=%ld", + Gbl.Usrs.Me.UsrDat.InsCtyCod, + Gbl.Usrs.Me.UsrDat.InsCod, + Gbl.Usrs.Me.UsrDat.Tch.CtrCod, + Gbl.Usrs.Me.UsrDat.Tch.DptCod, + Gbl.Usrs.Me.UsrDat.UsrCod); } /*****************************************************************************/ @@ -2044,15 +2044,13 @@ void Enr_SignUpInCrs (void) /***** Request user in current course in database *****/ if (ReqCod > 0) // Old request exists in database - { - DB_BuildQuery ("UPDATE crs_usr_requests SET Role=%u,RequestTime=NOW()" - " WHERE ReqCod=%ld AND CrsCod=%ld AND UsrCod=%ld", - (unsigned) RoleFromForm, - ReqCod, - Gbl.CurrentCrs.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod); - DB_QueryUPDATE_new ("can not update enrolment request"); - } + DB_QueryUPDATE ("can not update enrolment request", + "UPDATE crs_usr_requests SET Role=%u,RequestTime=NOW()" + " WHERE ReqCod=%ld AND CrsCod=%ld AND UsrCod=%ld", + (unsigned) RoleFromForm, + ReqCod, + Gbl.CurrentCrs.Crs.CrsCod, + Gbl.Usrs.Me.UsrDat.UsrCod); else // No request in database for this user in this course ReqCod = DB_QueryINSERTandReturnCode ("can not save enrolment request", @@ -3061,15 +3059,15 @@ static void Enr_RemoveExpiredEnrolmentRequests (void) { /***** Mark possible notifications as removed Important: do this before removing the request *****/ - DB_BuildQuery ("UPDATE notif,crs_usr_requests" - " SET notif.Status=(notif.Status | %u)" - " WHERE notif.NotifyEvent=%u" - " AND notif.Cod=crs_usr_requests.ReqCod" - " AND crs_usr_requests.RequestTime