diff --git a/swad_agenda.c b/swad_agenda.c index 270f9f442..d6bc68633 100644 --- a/swad_agenda.c +++ b/swad_agenda.c @@ -1359,7 +1359,6 @@ void Agd_RemoveEvent (void) void Agd_HideEvent (void) { extern const char *Txt_Event_X_is_now_hidden; - char *Query; struct AgendaEvent AgdEvent; /***** Get event code *****/ @@ -1371,11 +1370,10 @@ void Agd_HideEvent (void) Agd_GetDataOfEventByCod (&AgdEvent); /***** Set event private *****/ - if (asprintf (&Query,"UPDATE agendas SET Hidden='Y'" - " WHERE AgdCod=%ld AND UsrCod=%ld", - AgdEvent.AgdCod,AgdEvent.UsrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not hide event"); + DB_BuildQuery ("UPDATE agendas SET Hidden='Y'" + " WHERE AgdCod=%ld AND UsrCod=%ld", + AgdEvent.AgdCod,AgdEvent.UsrCod); + DB_QueryUPDATE_new ("can not hide event"); /***** Write message to show the change made *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), @@ -1394,7 +1392,6 @@ void Agd_HideEvent (void) void Agd_UnhideEvent (void) { extern const char *Txt_Event_X_is_now_visible; - char *Query; struct AgendaEvent AgdEvent; /***** Get event code *****/ @@ -1406,11 +1403,10 @@ void Agd_UnhideEvent (void) Agd_GetDataOfEventByCod (&AgdEvent); /***** Set event public *****/ - if (asprintf (&Query,"UPDATE agendas SET Hidden='N'" - " WHERE AgdCod=%ld AND UsrCod=%ld", - AgdEvent.AgdCod,AgdEvent.UsrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not show event"); + DB_BuildQuery ("UPDATE agendas SET Hidden='N'" + " WHERE AgdCod=%ld AND UsrCod=%ld", + AgdEvent.AgdCod,AgdEvent.UsrCod); + DB_QueryUPDATE_new ("can not show event"); /***** Write message to show the change made *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), @@ -1429,7 +1425,6 @@ void Agd_UnhideEvent (void) void Agd_MakeEventPrivate (void) { extern const char *Txt_Event_X_is_now_private; - char *Query; struct AgendaEvent AgdEvent; /***** Get event code *****/ @@ -1441,11 +1436,10 @@ void Agd_MakeEventPrivate (void) Agd_GetDataOfEventByCod (&AgdEvent); /***** Make event private *****/ - if (asprintf (&Query,"UPDATE agendas SET Public='N'" - " WHERE AgdCod=%ld AND UsrCod=%ld", - AgdEvent.AgdCod,AgdEvent.UsrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not 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"); /***** Write message to show the change made *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), @@ -1464,7 +1458,6 @@ void Agd_MakeEventPrivate (void) void Agd_MakeEventPublic (void) { extern const char *Txt_Event_X_is_now_visible_to_users_of_your_courses; - char *Query; struct AgendaEvent AgdEvent; /***** Get event code *****/ @@ -1476,11 +1469,10 @@ void Agd_MakeEventPublic (void) Agd_GetDataOfEventByCod (&AgdEvent); /***** Make event public *****/ - if (asprintf (&Query,"UPDATE agendas SET Public='Y'" - " WHERE AgdCod=%ld AND UsrCod=%ld", - AgdEvent.AgdCod,AgdEvent.UsrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not 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"); /***** Write message to show the change made *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), @@ -1735,20 +1727,17 @@ static void Agd_CreateEvent (struct AgendaEvent *AgdEvent,const char *Txt) static void Agd_UpdateEvent (struct AgendaEvent *AgdEvent,const char *Txt) { - char *Query; - /***** Update the data of the event *****/ - if (asprintf (&Query,"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) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update 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"); } /*****************************************************************************/ diff --git a/swad_announcement.c b/swad_announcement.c index 7985938b0..5f6fb5ecc 100644 --- a/swad_announcement.c +++ b/swad_announcement.c @@ -527,18 +527,16 @@ static void Ann_CreateAnnouncement (unsigned Roles,const char *Subject,const cha void Ann_HideActiveAnnouncement (void) { - char *Query; long AnnCod; /***** Get the code of the global announcement to hide *****/ AnnCod = Ann_GetParamAnnCod (); /***** Set global announcement as hidden *****/ - if (asprintf (&Query,"UPDATE announcements SET Status=%u" - " WHERE AnnCod=%ld", - (unsigned) Ann_OBSOLETE_ANNOUNCEMENT,AnnCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not hide announcement"); + DB_BuildQuery ("UPDATE announcements SET Status=%u" + " WHERE AnnCod=%ld", + (unsigned) Ann_OBSOLETE_ANNOUNCEMENT,AnnCod); + DB_QueryUPDATE_new ("can not hide announcement"); } /*****************************************************************************/ @@ -547,18 +545,16 @@ void Ann_HideActiveAnnouncement (void) void Ann_RevealHiddenAnnouncement (void) { - char *Query; long AnnCod; /***** Get the code of the global announcement to show *****/ AnnCod = Ann_GetParamAnnCod (); /***** Set global announcement as shown *****/ - if (asprintf (&Query,"UPDATE announcements SET Status=%u" - " WHERE AnnCod=%ld", - (unsigned) Ann_ACTIVE_ANNOUNCEMENT,AnnCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not reveal announcement"); + DB_BuildQuery ("UPDATE announcements SET Status=%u" + " WHERE AnnCod=%ld", + (unsigned) Ann_ACTIVE_ANNOUNCEMENT,AnnCod); + DB_QueryUPDATE_new ("can not reveal announcement"); } /*****************************************************************************/ diff --git a/swad_assignment.c b/swad_assignment.c index 1d37a6f8a..d55654373 100644 --- a/swad_assignment.c +++ b/swad_assignment.c @@ -1030,7 +1030,6 @@ void Asg_RemoveAssignment (void) void Asg_HideAssignment (void) { extern const char *Txt_Assignment_X_is_now_hidden; - char *Query; struct Assignment Asg; /***** Get assignment code *****/ @@ -1041,11 +1040,10 @@ void Asg_HideAssignment (void) Asg_GetDataOfAssignmentByCod (&Asg); /***** Hide assignment *****/ - if (asprintf (&Query,"UPDATE assignments SET Hidden='Y'" - " WHERE AsgCod=%ld AND CrsCod=%ld", - Asg.AsgCod,Gbl.CurrentCrs.Crs.CrsCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not 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"); /***** Write message to show the change made *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), @@ -1064,7 +1062,6 @@ void Asg_HideAssignment (void) void Asg_ShowAssignment (void) { extern const char *Txt_Assignment_X_is_now_visible; - char *Query; struct Assignment Asg; /***** Get assignment code *****/ @@ -1075,11 +1072,10 @@ void Asg_ShowAssignment (void) Asg_GetDataOfAssignmentByCod (&Asg); /***** Hide assignment *****/ - if (asprintf (&Query,"UPDATE assignments SET Hidden='N'" - " WHERE AsgCod=%ld AND CrsCod=%ld", - Asg.AsgCod,Gbl.CurrentCrs.Crs.CrsCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not show 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"); /***** Write message to show the change made *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), @@ -1465,14 +1461,11 @@ void Asg_RecFormAssignment (void) static void Asg_UpdateNumUsrsNotifiedByEMailAboutAssignment (long AsgCod,unsigned NumUsrsToBeNotifiedByEMail) { - char *Query; - /***** Update number of users notified *****/ - if (asprintf (&Query,"UPDATE assignments SET NumNotif=NumNotif+%u" - " WHERE AsgCod=%ld", - NumUsrsToBeNotifiedByEMail,AsgCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update the number of notifications of an assignment"); + 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"); } /*****************************************************************************/ @@ -1507,22 +1500,19 @@ static void Asg_CreateAssignment (struct Assignment *Asg,const char *Txt) static void Asg_UpdateAssignment (struct Assignment *Asg,const char *Txt) { - char *Query; - /***** Update the data of the assignment *****/ - if (asprintf (&Query,"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) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update 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"); /***** Update groups *****/ /* Remove old groups */ diff --git a/swad_attendance.c b/swad_attendance.c index cfd3320eb..9c07460de 100644 --- a/swad_attendance.c +++ b/swad_attendance.c @@ -959,7 +959,6 @@ void Att_RemoveAttEventFromDB (long AttCod) void Att_HideAttEvent (void) { extern const char *Txt_Event_X_is_now_hidden; - char *Query; struct AttendanceEvent Att; /***** Get attendance event code *****/ @@ -970,11 +969,10 @@ void Att_HideAttEvent (void) Att_GetDataOfAttEventByCodAndCheckCrs (&Att); /***** Hide attendance event *****/ - if (asprintf (&Query,"UPDATE att_events SET Hidden='Y'" - " WHERE AttCod=%ld AND CrsCod=%ld", - Att.AttCod,Gbl.CurrentCrs.Crs.CrsCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not 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"); /***** Write message to show the change made *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), @@ -993,7 +991,6 @@ void Att_HideAttEvent (void) void Att_ShowAttEvent (void) { extern const char *Txt_Event_X_is_now_visible; - char *Query; struct AttendanceEvent Att; /***** Get attendance event code *****/ @@ -1004,11 +1001,10 @@ void Att_ShowAttEvent (void) Att_GetDataOfAttEventByCodAndCheckCrs (&Att); /***** Hide attendance event *****/ - if (asprintf (&Query,"UPDATE att_events SET Hidden='N'" - " WHERE AttCod=%ld AND CrsCod=%ld", - Att.AttCod,Gbl.CurrentCrs.Crs.CrsCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not show 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"); /***** Write message to show the change made *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), @@ -1378,26 +1374,23 @@ void Att_CreateAttEvent (struct AttendanceEvent *Att,const char *Txt) void Att_UpdateAttEvent (struct AttendanceEvent *Att,const char *Txt) { - char *Query; - /***** Update the data of the attendance event *****/ - if (asprintf (&Query,"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) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update 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"); /***** Update groups *****/ /* Remove old groups */ @@ -2584,7 +2577,6 @@ static bool Att_CheckIfUsrIsPresentInAttEventAndGetComments (long AttCod,long Us void Att_RegUsrInAttEventNotChangingComments (long AttCod,long UsrCod) { bool Present; - char *Query; /***** Check if user is already in table att_usr (present or not) *****/ if (Att_CheckIfUsrIsInTableAttUsr (AttCod,UsrCod,&Present)) // User is in table att_usr @@ -2593,11 +2585,10 @@ void Att_RegUsrInAttEventNotChangingComments (long AttCod,long UsrCod) if (!Present) { /***** Set user as present in database *****/ - if (asprintf (&Query,"UPDATE att_usr SET Present='Y'" - " WHERE AttCod=%ld AND UsrCod=%ld", - AttCod,UsrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not set user as present in an event"); + 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"); } } else // User is not in table att_usr diff --git a/swad_banner.c b/swad_banner.c index 3c9160971..c72174d2b 100644 --- a/swad_banner.c +++ b/swad_banner.c @@ -73,7 +73,8 @@ static void Ban_ShowOrHideBanner (bool Hide); static void Ban_RenameBanner (Cns_ShrtOrFullName_t ShrtOrFullName); static bool Ban_CheckIfBannerNameExists (const char *FieldName,const char *Name,long BanCod); -static void Ban_UpdateBanNameDB (long BanCod,const char *FieldName,const char *NewBanName); +static void Ban_UpdateBanNameDB (long BanCod,const char *FieldName, + const char *NewBanName); static void Ban_PutFormToCreateBanner (void); static void Ban_PutHeadBanners (void); @@ -562,7 +563,6 @@ static void Ban_ShowOrHideBanner (bool Hide) { extern const char *Txt_The_banner_X_is_now_hidden; extern const char *Txt_The_banner_X_is_now_visible; - char *Query; struct Banner Ban; /***** Get banner code *****/ @@ -575,13 +575,12 @@ static void Ban_ShowOrHideBanner (bool Hide) /***** Mark file as hidden/visible in database *****/ if (Ban.Hidden != Hide) { - if (asprintf (&Query,"UPDATE banners SET Hidden='%c'" - " WHERE BanCod=%ld", - Hide ? 'Y' : - 'N', - Ban.BanCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not change status of a banner in database"); + 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"); } /***** Write message to show the change made *****/ @@ -724,15 +723,13 @@ static bool Ban_CheckIfBannerNameExists (const char *FieldName,const char *Name, /***************** Update banner name in table of banners ********************/ /*****************************************************************************/ -static void Ban_UpdateBanNameDB (long BanCod,const char *FieldName,const char *NewBanName) +static void Ban_UpdateBanNameDB (long BanCod,const char *FieldName, + const char *NewBanName) { - char *Query; - /***** Update banner changing old name by new name *****/ - if (asprintf (&Query,"UPDATE banners SET %s='%s' WHERE BanCod=%ld", - FieldName,NewBanName,BanCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update the name of a banner"); + DB_BuildQuery ("UPDATE banners SET %s='%s' WHERE BanCod=%ld", + FieldName,NewBanName,BanCod); + DB_QueryUPDATE_new ("can not update the name of a banner"); } /*****************************************************************************/ @@ -744,7 +741,6 @@ void Ban_ChangeBannerImg (void) extern const char *Txt_The_new_image_is_X; extern const char *Txt_You_can_not_leave_the_image_empty; struct Banner *Ban; - char *Query; char NewImg[Ban_MAX_BYTES_IMAGE + 1]; Ban = &Gbl.Banners.EditingBan; @@ -761,10 +757,9 @@ void Ban_ChangeBannerImg (void) if (NewImg[0]) { /* Update the table changing old image by new image */ - if (asprintf (&Query,"UPDATE banners SET Img='%s' WHERE BanCod=%ld", - NewImg,Ban->BanCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update the image of a banner"); + DB_BuildQuery ("UPDATE banners SET Img='%s' WHERE BanCod=%ld", + NewImg,Ban->BanCod); + DB_QueryUPDATE_new ("can not update the image of a banner"); /***** Write message to show the change made *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), @@ -791,7 +786,6 @@ void Ban_ChangeBannerWWW (void) extern const char *Txt_The_new_web_address_is_X; extern const char *Txt_You_can_not_leave_the_web_address_empty; struct Banner *Ban; - char *Query; char NewWWW[Cns_MAX_BYTES_WWW + 1]; Ban = &Gbl.Banners.EditingBan; @@ -808,10 +802,9 @@ void Ban_ChangeBannerWWW (void) if (NewWWW[0]) { /* Update the table changing old WWW by new WWW */ - if (asprintf (&Query,"UPDATE banners SET WWW='%s' WHERE BanCod=%ld", - NewWWW,Ban->BanCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update the web of a banner"); + DB_BuildQuery ("UPDATE banners SET WWW='%s' WHERE BanCod=%ld", + NewWWW,Ban->BanCod); + DB_QueryUPDATE_new ("can not update the web of a banner"); /***** 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 243e6e18b..ecdfbed72 100644 --- a/swad_calendar.c +++ b/swad_calendar.c @@ -146,20 +146,17 @@ void Cal_ShowFormToSelFirstDayOfWeek (Act_Action_t Action,void (*FuncParams) (), void Cal_ChangeFirstDayOfWeek (void) { - char *Query; - /***** Get param with icon set *****/ Gbl.Prefs.FirstDayOfWeek = Cal_GetParamFirstDayOfWeek (); /***** Store icon first day of week database *****/ if (Gbl.Usrs.Me.Logged) { - if (asprintf (&Query,"UPDATE usr_data SET FirstDayOfWeek=%u" - " WHERE UsrCod=%ld", - Gbl.Prefs.FirstDayOfWeek, - Gbl.Usrs.Me.UsrDat.UsrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update your preference about first day of week"); + 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"); } /***** Set preferences from current IP *****/ diff --git a/swad_centre.c b/swad_centre.c index 90b5fae9d..fb2fdef78 100644 --- a/swad_centre.c +++ b/swad_centre.c @@ -1869,13 +1869,10 @@ void Ctr_ContEditAfterChgCtrInConfig (void) static void Ctr_UpdateCtrInsDB (long CtrCod,long InsCod) { - char *Query; - /***** Update institution in table of centres *****/ - if (asprintf (&Query,"UPDATE centres SET InsCod=%ld WHERE CtrCod=%ld", - InsCod,CtrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update the institution of a centre"); + DB_BuildQuery ("UPDATE centres SET InsCod=%ld WHERE CtrCod=%ld", + InsCod,CtrCod); + DB_QueryUPDATE_new ("can not update the institution of a centre"); } /*****************************************************************************/ @@ -1936,12 +1933,9 @@ void Ctr_ChangeCtrPlcInConfig (void) static void Ctr_UpdateCtrPlcDB (long CtrCod,long NewPlcCod) { - char *Query; - - if (asprintf (&Query,"UPDATE centres SET PlcCod=%ld WHERE CtrCod=%ld", - NewPlcCod,CtrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update the place of a centre"); + DB_BuildQuery ("UPDATE centres SET PlcCod=%ld WHERE CtrCod=%ld", + NewPlcCod,CtrCod); + DB_QueryUPDATE_new ("can not update the place of a centre"); } /*****************************************************************************/ @@ -2078,13 +2072,10 @@ static bool Ctr_CheckIfCtrNameExistsInIns (const char *FieldName,const char *Nam static void Ctr_UpdateInsNameDB (long CtrCod,const char *FieldName,const char *NewCtrName) { - char *Query; - /***** Update centre changing old name by new name */ - if (asprintf (&Query,"UPDATE centres SET %s='%s' WHERE CtrCod=%ld", - FieldName,NewCtrName,CtrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update the name of a centre"); + DB_BuildQuery ("UPDATE centres SET %s='%s' WHERE CtrCod=%ld", + FieldName,NewCtrName,CtrCod); + DB_QueryUPDATE_new ("can not update the name of a centre"); } /*****************************************************************************/ @@ -2167,13 +2158,10 @@ void Ctr_ChangeCtrWWWInConfig (void) static void Ctr_UpdateCtrWWWDB (long CtrCod, const char NewWWW[Cns_MAX_BYTES_WWW + 1]) { - char *Query; - /***** Update database changing old WWW by new WWW *****/ - if (asprintf (&Query,"UPDATE centres SET WWW='%s' WHERE CtrCod=%ld", - NewWWW,CtrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update the web of a centre"); + DB_BuildQuery ("UPDATE centres SET WWW='%s' WHERE CtrCod=%ld", + NewWWW,CtrCod); + DB_QueryUPDATE_new ("can not update the web of a centre"); } /*****************************************************************************/ @@ -2183,7 +2171,6 @@ static void Ctr_UpdateCtrWWWDB (long CtrCod, void Ctr_ChangeCtrStatus (void) { extern const char *Txt_The_status_of_the_centre_X_has_changed; - char *Query; Ctr_Status_t Status; Ctr_StatusTxt_t StatusTxt; @@ -2205,10 +2192,9 @@ void Ctr_ChangeCtrStatus (void) Ctr_GetDataOfCentreByCod (&Gbl.Ctrs.EditingCtr); /***** Update status in table of centres *****/ - if (asprintf (&Query,"UPDATE centres SET Status=%u WHERE CtrCod=%ld", - (unsigned) Status,Gbl.Ctrs.EditingCtr.CtrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update the status of a centre"); + 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"); Gbl.Ctrs.EditingCtr.Status = Status; /***** Write message to show the change made @@ -2481,7 +2467,6 @@ void Ctr_ReceivePhoto (void) void Ctr_ChangeCtrPhotoAttribution (void) { - char *Query; char NewPhotoAttribution[Img_MAX_BYTES_ATTRIBUTION + 1]; /***** Get parameters from form *****/ @@ -2489,11 +2474,10 @@ void Ctr_ChangeCtrPhotoAttribution (void) Par_GetParToText ("Attribution",NewPhotoAttribution,Img_MAX_BYTES_ATTRIBUTION); /***** Update the table changing old attribution by new attribution *****/ - if (asprintf (&Query,"UPDATE centres SET PhotoAttribution='%s'" - " WHERE CtrCod=%ld", - NewPhotoAttribution,Gbl.CurrentCtr.Ctr.CtrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update the photo attribution of the current centre"); + 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"); /***** Show the centre information again *****/ Ctr_ShowConfiguration (); diff --git a/swad_changelog.h b/swad_changelog.h index c8c5895d0..6b1eb58de 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.8.12 (2018-10-27)" +#define Log_PLATFORM_VERSION "SWAD 18.8.13 (2018-10-27)" #define CSS_FILE "swad18.4.css" #define JS_FILE "swad17.17.1.js" /* + Version 18.8.13: Oct 27, 2018 Some asprintf for database queries changed by internal function. (236661 lines) Version 18.8.12: Oct 27, 2018 Some asprintf for database queries changed by internal function. (236870 lines) Version 18.8.11: Oct 27, 2018 Some asprintf for database queries changed by internal function. (236921 lines) Version 18.8.10: Oct 27, 2018 Some asprintf for database queries changed by internal function. (236975 lines) diff --git a/swad_country.c b/swad_country.c index 53e32becc..1d5a1e305 100644 --- a/swad_country.c +++ b/swad_country.c @@ -1861,13 +1861,10 @@ static bool Cty_CheckIfCountryNameExists (Txt_Language_t Language,const char *Na static void Cty_UpdateCtyNameDB (long CtyCod,const char *FieldName,const char *NewCtyName) { - char *Query; - /***** Update country changing old name by new name */ - if (asprintf (&Query,"UPDATE countries SET %s='%s' WHERE CtyCod='%03ld'", - FieldName,NewCtyName,CtyCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update the name of a country"); + DB_BuildQuery ("UPDATE countries SET %s='%s' WHERE CtyCod='%03ld'", + FieldName,NewCtyName,CtyCod); + DB_QueryUPDATE_new ("can not update the name of a country"); /***** Flush cache *****/ Cty_FlushCacheCountryName (); @@ -1881,7 +1878,6 @@ void Cty_ChangeCtyWWW (void) { extern const char *Txt_The_new_web_address_is_X; extern const char *Txt_STR_LANG_ID[1 + Txt_NUM_LANGUAGES]; - char *Query; struct Country *Cty; char NewWWW[Cns_MAX_BYTES_WWW + 1]; Txt_Language_t Language; @@ -1901,11 +1897,10 @@ void Cty_ChangeCtyWWW (void) Cty_GetDataOfCountryByCod (Cty,Cty_GET_EXTRA_DATA); /***** Update the table changing old WWW by new WWW *****/ - if (asprintf (&Query,"UPDATE countries SET WWW_%s='%s'" - " WHERE CtyCod='%03ld'", - Txt_STR_LANG_ID[Language],NewWWW,Cty->CtyCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update the web of a country"); + 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"); Str_Copy (Cty->WWW[Language],NewWWW, Cns_MAX_BYTES_WWW); @@ -1925,7 +1920,6 @@ void Cty_ChangeCtyWWW (void) void Cty_ChangeCtyMapAttribution (void) { - char *Query; char NewMapAttribution[Img_MAX_BYTES_ATTRIBUTION + 1]; /***** Get parameters from form *****/ @@ -1933,11 +1927,10 @@ void Cty_ChangeCtyMapAttribution (void) Par_GetParToText ("Attribution",NewMapAttribution,Img_MAX_BYTES_ATTRIBUTION); /***** Update the table changing old attribution by new attribution *****/ - if (asprintf (&Query,"UPDATE countries SET MapAttribution='%s'" - " WHERE CtyCod='%03ld'", - NewMapAttribution,Gbl.CurrentCty.Cty.CtyCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update the map attribution of a country"); + 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"); /***** Show the country information again *****/ Cty_ShowConfiguration (); diff --git a/swad_course.c b/swad_course.c index 40f09a81f..748bf9681 100644 --- a/swad_course.c +++ b/swad_course.c @@ -2179,11 +2179,10 @@ static void Crs_EmptyCourseCompletely (long CrsCod) /***** Remove exam announcements in the course *****/ /* Mark all exam announcements in the course as deleted */ - if (asprintf (&Query,"UPDATE exam_announcements SET Status=%u" - " WHERE CrsCod=%ld", - (unsigned) Exa_DELETED_EXAM_ANNOUNCEMENT,CrsCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not remove exam announcements of a course"); + 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"); /***** Remove course cards of the course *****/ /* Remove content of course cards */ @@ -2447,13 +2446,10 @@ void Crs_ContEditAfterChgCrsInConfig (void) static void Crs_UpdateCrsDegDB (long CrsCod,long DegCod) { - char *Query; - /***** Update degree in table of courses *****/ - if (asprintf (&Query,"UPDATE courses SET DegCod=%ld WHERE CrsCod=%ld", - DegCod,CrsCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not move course to another degree"); + DB_BuildQuery ("UPDATE courses SET DegCod=%ld WHERE CrsCod=%ld", + DegCod,CrsCod); + DB_QueryUPDATE_new ("can not move course to another degree"); } /*****************************************************************************/ @@ -2596,13 +2592,10 @@ void Crs_ChangeCrsYear (void) static void Crs_UpdateCrsYear (struct Course *Crs,unsigned NewYear) { - char *Query; - /***** Update year/semester in table of courses *****/ - if (asprintf (&Query,"UPDATE courses SET Year=%u WHERE CrsCod=%ld", - NewYear,Crs->CrsCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update the year of a course"); + DB_BuildQuery ("UPDATE courses SET Year=%u WHERE CrsCod=%ld", + NewYear,Crs->CrsCod); + DB_QueryUPDATE_new ("can not update the year of a course"); /***** Copy course year/semester *****/ Crs->Year = NewYear; @@ -2777,13 +2770,10 @@ static bool Crs_CheckIfCrsNameExistsInYearOfDeg (const char *FieldName,const cha static void Crs_UpdateCrsNameDB (long CrsCod,const char *FieldName,const char *NewCrsName) { - char *Query; - /***** Update course changing old name by new name *****/ - if (asprintf (&Query,"UPDATE courses SET %s='%s' WHERE CrsCod=%ld", - FieldName,NewCrsName,CrsCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update the name of a course"); + DB_BuildQuery ("UPDATE courses SET %s='%s' WHERE CrsCod=%ld", + FieldName,NewCrsName,CrsCod); + DB_QueryUPDATE_new ("can not update the name of a course"); } /*****************************************************************************/ @@ -2793,7 +2783,6 @@ static void Crs_UpdateCrsNameDB (long CrsCod,const char *FieldName,const char *N void Crs_ChangeCrsStatus (void) { extern const char *Txt_The_status_of_the_course_X_has_changed; - char *Query; Crs_Status_t Status; Crs_StatusTxt_t StatusTxt; @@ -2816,10 +2805,9 @@ void Crs_ChangeCrsStatus (void) Crs_GetDataOfCourseByCod (&Gbl.Degs.EditingCrs); /***** Update status in table of courses *****/ - if (asprintf (&Query,"UPDATE courses SET Status=%u WHERE CrsCod=%ld", - (unsigned) Status,Gbl.Degs.EditingCrs.CrsCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update the status of a course"); + 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"); Gbl.Degs.EditingCrs.Status = Status; /***** Create message to show the change made *****/ @@ -3369,17 +3357,14 @@ static void Crs_WriteRowCrsData (unsigned NumCrs,MYSQL_ROW row,bool WriteColumnA void Crs_UpdateCrsLast (void) { - char *Query; - if (Gbl.CurrentCrs.Crs.CrsCod > 0 && Gbl.Usrs.Me.Role.Logged >= Rol_STD) { /***** Update my last access to current course *****/ - if (asprintf (&Query,"REPLACE INTO crs_last (CrsCod,LastTime)" - " VALUES (%ld,NOW())", - Gbl.CurrentCrs.Crs.CrsCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update 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"); } } diff --git a/swad_database.c b/swad_database.c index e98d53623..23fc6c685 100644 --- a/swad_database.c +++ b/swad_database.c @@ -3269,17 +3269,6 @@ void DB_QueryREPLACE_new (const char *MsgError) DB_ExitOnMySQLError (MsgError); } -void DB_QueryREPLACE_free (const char *Query,const char *MsgError) - { - int Result; - - /***** Query database *****/ - Result = mysql_query (&Gbl.mysql,Query); // Returns 0 on success - free ((void *) Query); - if (Result) - DB_ExitOnMySQLError (MsgError); - } - void DB_QueryREPLACE (const char *Query,const char *MsgError) { /***** Query database *****/ diff --git a/swad_database.h b/swad_database.h index c8322e214..6a487d00e 100644 --- a/swad_database.h +++ b/swad_database.h @@ -52,7 +52,6 @@ long DB_QueryINSERTandReturnCode_new (const char *MsgError); long DB_QueryINSERTandReturnCode (const char *Query,const char *MsgError); void DB_QueryREPLACE_new (const char *MsgError); -void DB_QueryREPLACE_free (const char *Query,const char *MsgError); void DB_QueryREPLACE (const char *Query,const char *MsgError); void DB_QueryUPDATE_new (const char *MsgError); diff --git a/swad_date.c b/swad_date.c index d5abd7847..7627aa54e 100644 --- a/swad_date.c +++ b/swad_date.c @@ -179,20 +179,17 @@ void Dat_PutScriptDateFormat (Dat_Format_t Format) void Dat_ChangeDateFormat (void) { - char *Query; - /***** Get param with date format *****/ Gbl.Prefs.DateFormat = Dat_GetParamDateFormat (); /***** Store date format in database *****/ if (Gbl.Usrs.Me.Logged) { - if (asprintf (&Query,"UPDATE usr_data SET DateFormat=%u" - " WHERE UsrCod=%ld", - (unsigned) Gbl.Prefs.DateFormat, - Gbl.Usrs.Me.UsrDat.UsrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update your preference about date format"); + 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"); } /***** Set preferences from current IP *****/ diff --git a/swad_degree.c b/swad_degree.c index 35e4df9f2..48a082e48 100644 --- a/swad_degree.c +++ b/swad_degree.c @@ -2030,13 +2030,10 @@ static bool Deg_CheckIfDegNameExistsInCtr (const char *FieldName,const char *Nam static void Deg_UpdateDegNameDB (long DegCod,const char *FieldName,const char *NewDegName) { - char *Query; - /***** Update degree changing old name by new name *****/ - if (asprintf (&Query,"UPDATE degrees SET %s='%s' WHERE DegCod=%ld", - FieldName,NewDegName,DegCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update the name of a degree"); + DB_BuildQuery ("UPDATE degrees SET %s='%s' WHERE DegCod=%ld", + FieldName,NewDegName,DegCod); + DB_QueryUPDATE_new ("can not update the name of a degree"); } /*****************************************************************************/ @@ -2112,13 +2109,10 @@ void Deg_ContEditAfterChgDegInConfig (void) static void Deg_UpdateDegCtrDB (long DegCod,long CtrCod) { - char *Query; - /***** Update centre in table of degrees *****/ - if (asprintf (&Query,"UPDATE degrees SET CtrCod=%ld WHERE DegCod=%ld", - CtrCod,DegCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update the centre of a degree"); + DB_BuildQuery ("UPDATE degrees SET CtrCod=%ld WHERE DegCod=%ld", + CtrCod,DegCod); + DB_QueryUPDATE_new ("can not update the centre of a degree"); } /*****************************************************************************/ @@ -2201,13 +2195,10 @@ void Deg_ChangeDegWWWInConfig (void) static void Deg_UpdateDegWWWDB (long DegCod,const char NewWWW[Cns_MAX_BYTES_WWW + 1]) { - char *Query; - /***** Update database changing old WWW by new WWW *****/ - if (asprintf (&Query,"UPDATE degrees SET WWW='%s' WHERE DegCod=%ld", - NewWWW,DegCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update the web of a degree"); + DB_BuildQuery ("UPDATE degrees SET WWW='%s' WHERE DegCod=%ld", + NewWWW,DegCod); + DB_QueryUPDATE_new ("can not update the web of a degree"); } /*****************************************************************************/ @@ -2217,7 +2208,6 @@ static void Deg_UpdateDegWWWDB (long DegCod,const char NewWWW[Cns_MAX_BYTES_WWW void Deg_ChangeDegStatus (void) { extern const char *Txt_The_status_of_the_degree_X_has_changed; - char *Query; Deg_Status_t Status; Deg_StatusTxt_t StatusTxt; @@ -2240,10 +2230,9 @@ void Deg_ChangeDegStatus (void) Deg_GetDataOfDegreeByCod (&Gbl.Degs.EditingDeg); /***** Update status in table of degrees *****/ - if (asprintf (&Query,"UPDATE degrees SET Status=%u WHERE DegCod=%ld", - (unsigned) Status,Gbl.Degs.EditingDeg.DegCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update the status of a degree"); + 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"); Gbl.Degs.EditingDeg.Status = Status; diff --git a/swad_degree_type.c b/swad_degree_type.c index 2f0e275d7..306fa62ab 100644 --- a/swad_degree_type.c +++ b/swad_degree_type.c @@ -915,7 +915,6 @@ void DT_RenameDegreeType (void) extern const char *Txt_The_type_of_degree_X_has_been_renamed_as_Y; extern const char *Txt_The_name_of_the_type_of_degree_X_has_not_changed; struct DegreeType *DegTyp; - char *Query; char NewNameDegTyp[Deg_MAX_BYTES_DEGREE_TYPE_NAME + 1]; DegTyp = &Gbl.Degs.EditingDegTyp; @@ -955,11 +954,10 @@ void DT_RenameDegreeType (void) else { /* Update the table changing old name by new name */ - if (asprintf (&Query,"UPDATE deg_types SET DegTypName='%s'" - " WHERE DegTypCod=%ld", - NewNameDegTyp,DegTyp->DegTypCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update the type of a degree"); + 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"); /* Write message to show the change made */ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), @@ -1004,7 +1002,6 @@ void DT_ChangeDegreeType (void) { extern const char *Txt_The_type_of_degree_of_the_degree_X_has_changed; long NewDegTypCod; - char *Query; /***** Get parameters from form *****/ /* Get degree code */ @@ -1017,10 +1014,9 @@ void DT_ChangeDegreeType (void) Deg_GetDataOfDegreeByCod (&Gbl.Degs.EditingDeg); /***** Update the table of degrees changing old type by new type *****/ - if (asprintf (&Query,"UPDATE degrees SET DegTypCod=%ld WHERE DegCod=%ld", - NewDegTypCod,Gbl.Degs.EditingDeg.DegCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update the type of a degree"); + 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"); /***** 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 a7f646463..80618d0a7 100644 --- a/swad_department.c +++ b/swad_department.c @@ -645,7 +645,6 @@ void Dpt_ChangeDepartIns (void) { extern const char *Txt_The_institution_of_the_department_has_changed; struct Department *Dpt; - char *Query; Dpt = &Gbl.Dpts.EditingDpt; @@ -657,10 +656,9 @@ void Dpt_ChangeDepartIns (void) Dpt->InsCod = Ins_GetAndCheckParamOtherInsCod (1); /***** Update institution in table of departments *****/ - if (asprintf (&Query,"UPDATE departments SET InsCod=%ld WHERE DptCod=%ld", - Dpt->InsCod,Dpt->DptCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update the institution of a department"); + 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"); /***** Write message to show the change made *****/ Ale_ShowAlert (Ale_SUCCESS,Txt_The_institution_of_the_department_has_changed); @@ -799,13 +797,10 @@ static bool Dpt_CheckIfDepartmentNameExists (const char *FieldName,const char *N static void Dpt_UpdateDegNameDB (long DptCod,const char *FieldName,const char *NewDptName) { - char *Query; - /***** Update department changing old name by new name *****/ - if (asprintf (&Query,"UPDATE departments SET %s='%s' WHERE DptCod=%ld", - FieldName,NewDptName,DptCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update the name of a department"); + DB_BuildQuery ("UPDATE departments SET %s='%s' WHERE DptCod=%ld", + FieldName,NewDptName,DptCod); + DB_QueryUPDATE_new ("can not update the name of a department"); } /******************************************************************************/ @@ -817,7 +812,6 @@ void Dpt_ChangeDptWWW (void) extern const char *Txt_The_new_web_address_is_X; extern const char *Txt_You_can_not_leave_the_web_address_empty; struct Department *Dpt; - char *Query; char NewWWW[Cns_MAX_BYTES_WWW + 1]; Dpt = &Gbl.Dpts.EditingDpt; @@ -833,10 +827,9 @@ void Dpt_ChangeDptWWW (void) if (NewWWW[0]) { /* Update the table changing old WWW by new WWW */ - if (asprintf (&Query,"UPDATE departments SET WWW='%s' WHERE DptCod=%ld", - NewWWW,Dpt->DptCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update the web of a department"); + DB_BuildQuery ("UPDATE departments SET WWW='%s' WHERE DptCod=%ld", + NewWWW,Dpt->DptCod); + DB_QueryUPDATE_new ("can not update the web of a department"); /***** 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 361d91e79..26615456a 100644 --- a/swad_enrolment.c +++ b/swad_enrolment.c @@ -209,8 +209,6 @@ void Enr_PutLinkToRequestSignUp (void) void Enr_ModifyRoleInCurrentCrs (struct UsrData *UsrDat,Rol_Role_t NewRole) { - char *Query; - /***** Check if user's role is allowed *****/ switch (NewRole) { @@ -223,11 +221,10 @@ void Enr_ModifyRoleInCurrentCrs (struct UsrData *UsrDat,Rol_Role_t NewRole) } /***** Update the role of a user in a course *****/ - if (asprintf (&Query,"UPDATE crs_usr SET Role=%u" - " WHERE CrsCod=%ld AND UsrCod=%ld", - (unsigned) NewRole,Gbl.CurrentCrs.Crs.CrsCod,UsrDat->UsrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not modify user's role in 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"); /***** Flush caches *****/ Usr_FlushCachesUsr (); @@ -519,7 +516,6 @@ void Enr_UpdateUsrData (struct UsrData *UsrDat) { extern const char *Usr_StringsSexDB[Usr_NUM_SEXS]; char BirthdayStrDB[Usr_BIRTHDAY_STR_DB_LENGTH + 1]; - char *Query; /***** Check if user's code is initialized *****/ if (UsrDat->UsrCod <= 0) @@ -530,28 +526,27 @@ void Enr_UpdateUsrData (struct UsrData *UsrDat) /***** Update user's common data *****/ Usr_CreateBirthdayStrDB (UsrDat,BirthdayStrDB); // It can include start and ending apostrophes - if (asprintf (&Query,"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) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update user's data"); + 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"); } /*****************************************************************************/ @@ -574,18 +569,15 @@ void Enr_FilterUsrDat (struct UsrData *UsrDat) void Enr_UpdateInstitutionCentreDepartment (void) { - char *Query; - - if (asprintf (&Query,"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) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryUPDATE_free (Query,"can not update institution, centre and department"); + 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"); } /*****************************************************************************/ @@ -3031,27 +3023,23 @@ static void Enr_RemoveEnrolmentRequest (long CrsCod,long UsrCod) static void Enr_RemoveExpiredEnrolmentRequests (void) { - char *Query; - /***** Mark possible notifications as removed Important: do this before removing the request *****/ - if (asprintf (&Query,"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