From d90d736fa838ea8827e2e276232f966829000e55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Sat, 27 Oct 2018 14:46:08 +0200 Subject: [PATCH] Version 18.8.12 --- swad_ID.c | 11 ++++----- swad_MFU.c | 13 +++++------ swad_announcement.c | 14 +++++------- swad_attendance.c | 34 ++++++++++++---------------- swad_changelog.h | 3 ++- swad_connected.c | 15 +++++-------- swad_enrolment.c | 14 +++++------- swad_file_browser.c | 44 +++++++++++++++++------------------- swad_follow.c | 28 ++++++++++------------- swad_forum.c | 47 ++++++++++++++++---------------------- swad_info.c | 15 +++++-------- swad_mail.c | 41 +++++++++++++++------------------ swad_network.c | 27 ++++++++++------------ swad_nickname.c | 26 +++++++++------------ swad_notification.c | 18 +++++++-------- swad_password.c | 24 +++++++++----------- swad_photo.c | 18 +++++++-------- swad_preference.c | 55 +++++++++++++++++++++------------------------ swad_project.c | 16 ++++++------- 19 files changed, 200 insertions(+), 263 deletions(-) diff --git a/swad_ID.c b/swad_ID.c index 7f471512f..11b7e70dd 100644 --- a/swad_ID.c +++ b/swad_ID.c @@ -857,14 +857,11 @@ static bool ID_CheckIfConfirmed (long UsrCod,const char *UsrID) static void ID_RemoveUsrIDFromDB (long UsrCod,const char *UsrID) { - char *Query; - /***** Remove one of my user's IDs *****/ - if (asprintf (&Query,"DELETE FROM usr_IDs" - " WHERE UsrCod=%ld AND UsrID='%s'", - UsrCod,UsrID) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryREPLACE_free (Query,"can not remove a user's ID"); + DB_BuildQuery ("DELETE FROM usr_IDs" + " WHERE UsrCod=%ld AND UsrID='%s'", + UsrCod,UsrID); + DB_QueryREPLACE_new ("can not remove a user's ID"); } /*****************************************************************************/ diff --git a/swad_MFU.c b/swad_MFU.c index f5d71950e..7d909a2be 100644 --- a/swad_MFU.c +++ b/swad_MFU.c @@ -372,13 +372,12 @@ void MFU_UpdateMFUActions (void) DB_FreeMySQLResult (&mysql_res); /***** Update score for the current action *****/ - if (asprintf (&Query,"REPLACE INTO actions_MFU" - " (UsrCod,ActCod,Score,LastClick)" - " VALUES" - " (%ld,%ld,'%f',NOW())", - Gbl.Usrs.Me.UsrDat.UsrCod,ActCod,Score) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryREPLACE_free (Query,"can not update most frequently used actions"); + DB_BuildQuery ("REPLACE INTO actions_MFU" + " (UsrCod,ActCod,Score,LastClick)" + " VALUES" + " (%ld,%ld,'%f',NOW())", + Gbl.Usrs.Me.UsrDat.UsrCod,ActCod,Score); + DB_QueryREPLACE_new ("can not update most frequently used actions"); /***** Update score for other actions *****/ if (asprintf (&Query,"UPDATE actions_MFU SET Score=GREATEST(Score*'%f','%f')" diff --git a/swad_announcement.c b/swad_announcement.c index 3b174efa8..7985938b0 100644 --- a/swad_announcement.c +++ b/swad_announcement.c @@ -599,20 +599,18 @@ void Ann_RemoveAnnouncement (void) void Ann_MarkAnnouncementAsSeen (void) { - char *Query; long AnnCod; /***** Get the code of the global announcement *****/ AnnCod = Ann_GetParamAnnCod (); /***** Mark announcement as seen *****/ - if (asprintf (&Query,"REPLACE INTO ann_seen" - " (AnnCod,UsrCod)" - " VALUES" - " (%ld,%ld)", - AnnCod,Gbl.Usrs.Me.UsrDat.UsrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryREPLACE_free (Query,"can not mark announcement as seen"); + DB_BuildQuery ("REPLACE INTO ann_seen" + " (AnnCod,UsrCod)" + " VALUES" + " (%ld,%ld)", + AnnCod,Gbl.Usrs.Me.UsrDat.UsrCod); + DB_QueryREPLACE_new ("can not mark announcement as seen"); /***** Show other announcements again *****/ Ann_ShowMyAnnouncementsNotMarkedAsSeen (); diff --git a/swad_attendance.c b/swad_attendance.c index d9f65008c..cfd3320eb 100644 --- a/swad_attendance.c +++ b/swad_attendance.c @@ -2611,20 +2611,17 @@ void Att_RegUsrInAttEventNotChangingComments (long AttCod,long UsrCod) static void Att_RegUsrInAttEventChangingComments (long AttCod,long UsrCod,bool Present, const char *CommentStd,const char *CommentTch) { - char *Query; - /***** Register user as assistant to an event in database *****/ - if (asprintf (&Query,"REPLACE INTO att_usr" - " (AttCod,UsrCod,Present,CommentStd,CommentTch)" - " VALUES" - " (%ld,%ld,'%c','%s','%s')", - AttCod,UsrCod, - Present ? 'Y' : - 'N', - CommentStd, - CommentTch) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryREPLACE_free (Query,"can not register user in an event"); + DB_BuildQuery ("REPLACE INTO att_usr" + " (AttCod,UsrCod,Present,CommentStd,CommentTch)" + " VALUES" + " (%ld,%ld,'%c','%s','%s')", + AttCod,UsrCod, + Present ? 'Y' : + 'N', + CommentStd, + CommentTch); + DB_QueryREPLACE_new ("can not register user in an event"); } /*****************************************************************************/ @@ -2633,14 +2630,11 @@ static void Att_RegUsrInAttEventChangingComments (long AttCod,long UsrCod,bool P static void Att_RemoveUsrFromAttEvent (long AttCod,long UsrCod) { - char *Query; - /***** Remove user if there is no comment in database *****/ - if (asprintf (&Query,"DELETE FROM att_usr" - " WHERE AttCod=%ld AND UsrCod=%ld", - AttCod,UsrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryREPLACE_free (Query,"can not remove student from an event"); + DB_BuildQuery ("DELETE FROM att_usr" + " WHERE AttCod=%ld AND UsrCod=%ld", + AttCod,UsrCod); + DB_QueryREPLACE_new ("can not remove student from an event"); } /*****************************************************************************/ diff --git a/swad_changelog.h b/swad_changelog.h index 7fe7dbb42..c8c5895d0 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.11 (2018-10-27)" +#define Log_PLATFORM_VERSION "SWAD 18.8.12 (2018-10-27)" #define CSS_FILE "swad18.4.css" #define JS_FILE "swad17.17.1.js" /* + 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) Version 18.8.9: Oct 26, 2018 Some asprintf for database queries changed by internal function. (237082 lines) diff --git a/swad_connected.c b/swad_connected.c index 31c29aba2..7266b5b6b 100644 --- a/swad_connected.c +++ b/swad_connected.c @@ -640,19 +640,16 @@ static void Con_ShowConnectedUsrsWithARoleBelongingToCurrentCrsOnRightColumn (Ro void Con_UpdateMeInConnectedList (void) { - char *Query; - /***** Update my entry in connected list. The role which is stored is the role of the last click *****/ - if (asprintf (&Query,"REPLACE INTO connected" - " (UsrCod,RoleInLastCrs,LastCrsCod,LastTime)" - " VALUES" - " (%ld,%u,%ld,NOW())", + DB_BuildQuery ("REPLACE INTO connected" + " (UsrCod,RoleInLastCrs,LastCrsCod,LastTime)" + " VALUES" + " (%ld,%u,%ld,NOW())", Gbl.Usrs.Me.UsrDat.UsrCod, (unsigned) Gbl.Usrs.Me.Role.Logged, - Gbl.CurrentCrs.Crs.CrsCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryREPLACE_free (Query,"can not update list of connected users"); + Gbl.CurrentCrs.Crs.CrsCod); + DB_QueryREPLACE_new ("can not update list of connected users"); } /*****************************************************************************/ diff --git a/swad_enrolment.c b/swad_enrolment.c index 7e7737e57..361d91e79 100644 --- a/swad_enrolment.c +++ b/swad_enrolment.c @@ -3437,7 +3437,6 @@ static void Enr_RegisterAdmin (struct UsrData *UsrDat,Sco_Scope_t Scope,long Cod extern const char *Sco_ScopeDB[Sco_NUM_SCOPES]; extern const char *Txt_THE_USER_X_is_already_an_administrator_of_Y; extern const char *Txt_THE_USER_X_has_been_enroled_as_administrator_of_Y; - char *Query; /***** Check if user was and administrator of current institution/centre/degree *****/ if (Usr_CheckIfUsrIsAdm (UsrDat->UsrCod,Scope,Cod)) @@ -3447,13 +3446,12 @@ static void Enr_RegisterAdmin (struct UsrData *UsrDat,Sco_Scope_t Scope,long Cod else // User was not administrator of current institution/centre/degree { /***** Insert or replace administrator in current institution/centre/degree *****/ - if (asprintf (&Query,"REPLACE INTO admin" - " (UsrCod,Scope,Cod)" - " VALUES" - " (%ld,'%s',%ld)", - UsrDat->UsrCod,Sco_ScopeDB[Scope],Cod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryREPLACE_free (Query,"can not create administrator"); + DB_BuildQuery ("REPLACE INTO admin" + " (UsrCod,Scope,Cod)" + " VALUES" + " (%ld,'%s',%ld)", + UsrDat->UsrCod,Sco_ScopeDB[Scope],Cod); + DB_QueryREPLACE_new ("can not create administrator"); snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), Txt_THE_USER_X_has_been_enroled_as_administrator_of_Y, diff --git a/swad_file_browser.c b/swad_file_browser.c index bedc3de40..af66420b9 100644 --- a/swad_file_browser.c +++ b/swad_file_browser.c @@ -4528,22 +4528,20 @@ static void Brw_StoreSizeOfFileTreeInDB (void) { long Cod = Brw_GetCodForFiles (); long ZoneUsrCod = Brw_GetZoneUsrCodForFiles (); - char *Query; /***** Update size of the file browser in database *****/ - if (asprintf (&Query,"REPLACE INTO file_browser_size" - " (FileBrowser,Cod,ZoneUsrCod," - "NumLevels,NumFolders,NumFiles,TotalSize)" - " VALUES" - " (%u,%ld,%ld," - "%u,'%lu','%lu','%llu')", - (unsigned) Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type],Cod,ZoneUsrCod, - Gbl.FileBrowser.Size.NumLevls, - Gbl.FileBrowser.Size.NumFolds, - Gbl.FileBrowser.Size.NumFiles, - Gbl.FileBrowser.Size.TotalSiz) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryREPLACE_free (Query,"can not store the size of a file browser"); + DB_BuildQuery ("REPLACE INTO file_browser_size" + " (FileBrowser,Cod,ZoneUsrCod," + "NumLevels,NumFolders,NumFiles,TotalSize)" + " VALUES" + " (%u,%ld,%ld," + "%u,'%lu','%lu','%llu')", + (unsigned) Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type],Cod,ZoneUsrCod, + Gbl.FileBrowser.Size.NumLevls, + Gbl.FileBrowser.Size.NumFolds, + Gbl.FileBrowser.Size.NumFiles, + Gbl.FileBrowser.Size.TotalSiz); + DB_QueryREPLACE_new ("can not store the size of a file browser"); } /*****************************************************************************/ @@ -5552,7 +5550,6 @@ void Brw_CreateDirDownloadTmp (void) static void Brw_GetAndUpdateDateLastAccFileBrowser (void) { long Cod; - char *Query; MYSQL_RES *mysql_res; MYSQL_ROW row; unsigned long NumRows; @@ -5630,15 +5627,14 @@ static void Brw_GetAndUpdateDateLastAccFileBrowser (void) DB_FreeMySQLResult (&mysql_res); /***** Update date of my last access to file browser in this course *****/ - if (asprintf (&Query,"REPLACE INTO file_browser_last" - " (UsrCod,FileBrowser,Cod,LastClick)" - " VALUES" - " (%ld,%u,%ld,NOW())", - Gbl.Usrs.Me.UsrDat.UsrCod, - (unsigned) Brw_FileBrowserForDB_file_browser_last[Gbl.FileBrowser.Type], - Cod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryREPLACE_free (Query,"can not update date of last access to a file browser"); + DB_BuildQuery ("REPLACE INTO file_browser_last" + " (UsrCod,FileBrowser,Cod,LastClick)" + " VALUES" + " (%ld,%u,%ld,NOW())", + Gbl.Usrs.Me.UsrDat.UsrCod, + (unsigned) Brw_FileBrowserForDB_file_browser_last[Gbl.FileBrowser.Type], + Cod); + DB_QueryREPLACE_new ("can not update date of last access to a file browser"); } /*****************************************************************************/ diff --git a/swad_follow.c b/swad_follow.c index 7cab91ff8..ccc16a291 100644 --- a/swad_follow.c +++ b/swad_follow.c @@ -998,7 +998,6 @@ static void Fol_PutIconToUnfollow (struct UsrData *UsrDat) void Fol_FollowUsr1 (void) { extern const char *Txt_User_not_found_or_you_do_not_have_permission_; - char *Query; bool CreateNotif; bool NotifyByEmail; @@ -1012,14 +1011,13 @@ void Fol_FollowUsr1 (void) Gbl.Usrs.Other.UsrDat.UsrCod)) { /***** Follow user in database *****/ - if (asprintf (&Query,"REPLACE INTO usr_follow" - " (FollowerCod,FollowedCod,FollowTime)" - " VALUES" - " (%ld,%ld,NOW())", - Gbl.Usrs.Me.UsrDat.UsrCod, - Gbl.Usrs.Other.UsrDat.UsrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryREPLACE_free (Query,"can not follow user"); + DB_BuildQuery ("REPLACE INTO usr_follow" + " (FollowerCod,FollowedCod,FollowTime)" + " VALUES" + " (%ld,%ld,NOW())", + Gbl.Usrs.Me.UsrDat.UsrCod, + Gbl.Usrs.Other.UsrDat.UsrCod); + DB_QueryREPLACE_new ("can not follow user"); /***** This follow must be notified by email? *****/ CreateNotif = (Gbl.Usrs.Other.UsrDat.Prefs.NotifNtfEvents & (1 << Ntf_EVENT_FOLLOWER)); @@ -1067,7 +1065,6 @@ void Fol_FollowUsr2 (void) void Fol_UnfollowUsr1 (void) { extern const char *Txt_User_not_found_or_you_do_not_have_permission_; - char *Query; /***** Get user to be unfollowed *****/ if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ()) @@ -1077,12 +1074,11 @@ void Fol_UnfollowUsr1 (void) Gbl.Usrs.Other.UsrDat.UsrCod)) { /***** Unfollow user in database *****/ - if (asprintf (&Query,"DELETE FROM usr_follow" - " WHERE FollowerCod=%ld AND FollowedCod=%ld", - Gbl.Usrs.Me.UsrDat.UsrCod, - Gbl.Usrs.Other.UsrDat.UsrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryREPLACE_free (Query,"can not unfollow user"); + DB_BuildQuery ("DELETE FROM usr_follow" + " WHERE FollowerCod=%ld AND FollowedCod=%ld", + Gbl.Usrs.Me.UsrDat.UsrCod, + Gbl.Usrs.Other.UsrDat.UsrCod); + DB_QueryREPLACE_new ("can not unfollow user"); } Gbl.Alert.Type = Ale_SUCCESS; } diff --git a/swad_forum.c b/swad_forum.c index fbc9649e4..81c3c7798 100644 --- a/swad_forum.c +++ b/swad_forum.c @@ -484,16 +484,13 @@ static void For_DeletePstFromDisabledPstTable (long PstCod) static void For_InsertPstIntoBannedPstTable (long PstCod) { - char *Query; - /***** Remove post from banned posts table *****/ - if (asprintf (&Query,"REPLACE INTO forum_disabled_post" - " (PstCod,UsrCod,DisableTime)" - " VALUES" - " (%ld,%ld,NOW())", - PstCod,Gbl.Usrs.Me.UsrDat.UsrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryREPLACE_free (Query,"can not ban a post of a forum"); + DB_BuildQuery ("REPLACE INTO forum_disabled_post" + " (PstCod,UsrCod,DisableTime)" + " VALUES" + " (%ld,%ld,NOW())", + PstCod,Gbl.Usrs.Me.UsrDat.UsrCod); + DB_QueryREPLACE_new ("can not ban a post of a forum"); } /*****************************************************************************/ @@ -794,17 +791,14 @@ static long For_GetLastPstCod (long ThrCod) static void For_UpdateThrReadTime (long ThrCod, time_t CreatTimeUTCOfTheMostRecentPostRead) { - char *Query; - /***** Insert or replace pair ThrCod-UsrCod in forum_thr_read *****/ - if (asprintf (&Query,"REPLACE INTO forum_thr_read" - " (ThrCod,UsrCod,ReadTime)" - " VALUES" - " (%ld,%ld,FROM_UNIXTIME(%ld))", - ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod, - (long) CreatTimeUTCOfTheMostRecentPostRead) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryREPLACE_free (Query,"can not update the status of reading of a thread of a forum"); + DB_BuildQuery ("REPLACE INTO forum_thr_read" + " (ThrCod,UsrCod,ReadTime)" + " VALUES" + " (%ld,%ld,FROM_UNIXTIME(%ld))", + ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod, + (long) CreatTimeUTCOfTheMostRecentPostRead); + DB_QueryREPLACE_new ("can not update the status of reading of a thread of a forum"); } /*****************************************************************************/ @@ -4443,19 +4437,16 @@ static void For_MoveThrToCurrentForum (long ThrCod) static void For_InsertThrInClipboard (long ThrCod) { - char *Query; - /***** Remove expired thread clipboards *****/ For_RemoveExpiredThrsClipboards (); /***** Add thread to my clipboard *****/ - if (asprintf (&Query,"REPLACE INTO forum_thr_clip" - " (ThrCod,UsrCod)" - " VALUES" - " (%ld,%ld)", - ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryREPLACE_free (Query,"can not add thread to clipboard"); + DB_BuildQuery ("REPLACE INTO forum_thr_clip" + " (ThrCod,UsrCod)" + " VALUES" + " (%ld,%ld)", + ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod); + DB_QueryREPLACE_new ("can not add thread to clipboard"); } /*****************************************************************************/ diff --git a/swad_info.c b/swad_info.c index 9032b5d8b..71ceea864 100644 --- a/swad_info.c +++ b/swad_info.c @@ -1701,18 +1701,15 @@ Inf_InfoSrc_t Inf_ConvertFromStrDBToInfoSrc (const char *StrInfoSrcDB) static void Inf_SetInfoTxtIntoDB (const char *InfoTxtHTML,const char *InfoTxtMD) { - char *Query; - /***** Insert or replace info source for a specific type of course information *****/ - if (asprintf (&Query,"REPLACE INTO crs_info_txt" - " (CrsCod,InfoType,InfoTxtHTML,InfoTxtMD)" - " VALUES" - " (%ld,'%s','%s','%s')", + DB_BuildQuery ("REPLACE INTO crs_info_txt" + " (CrsCod,InfoType,InfoTxtHTML,InfoTxtMD)" + " VALUES" + " (%ld,'%s','%s','%s')", Gbl.CurrentCrs.Crs.CrsCod, Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type], - InfoTxtHTML,InfoTxtMD) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryREPLACE_free (Query,"can not update info text"); + InfoTxtHTML,InfoTxtMD); + DB_QueryREPLACE_new ("can not update info text"); } /*****************************************************************************/ diff --git a/swad_mail.c b/swad_mail.c index 98c6d80e5..c6765c566 100644 --- a/swad_mail.c +++ b/swad_mail.c @@ -1491,14 +1491,11 @@ static void Mai_RemoveEmail (struct UsrData *UsrDat) static void Mai_RemoveEmailFromDB (long UsrCod,const char Email[Cns_MAX_BYTES_EMAIL_ADDRESS + 1]) { - char *Query; - /***** Remove an old email address *****/ - if (asprintf (&Query,"DELETE FROM usr_emails" - " WHERE UsrCod=%ld AND E_mail='%s'", - UsrCod,Email) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryREPLACE_free (Query,"can not remove an old email address"); + DB_BuildQuery ("DELETE FROM usr_emails" + " WHERE UsrCod=%ld AND E_mail='%s'", + UsrCod,Email); + DB_QueryREPLACE_new ("can not remove an old email address"); } /*****************************************************************************/ @@ -1653,13 +1650,12 @@ bool Mai_UpdateEmailInDB (const struct UsrData *UsrDat,const char NewEmail[Cns_M DB_QueryDELETE_free (Query,"can not remove not confirmed email for other users"); /***** Update email in database *****/ - if (asprintf (&Query,"REPLACE INTO usr_emails" - " (UsrCod,E_mail,CreatTime)" - " VALUES" - " (%ld,'%s',NOW())", - UsrDat->UsrCod,NewEmail) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryREPLACE_free (Query,"can not update email"); + DB_BuildQuery ("REPLACE INTO usr_emails" + " (UsrCod,E_mail,CreatTime)" + " VALUES" + " (%ld,'%s',NOW())", + UsrDat->UsrCod,NewEmail); + DB_QueryREPLACE_new ("can not update email"); return true; // Successfully updated } @@ -1788,15 +1784,14 @@ static void Mai_InsertMailKey (const char Email[Cns_MAX_BYTES_EMAIL_ADDRESS + 1] DB_QueryDELETE_free (Query,"can not remove old pending mail keys"); /***** Insert mail key in database *****/ - if (asprintf (&Query,"INSERT INTO pending_emails" - " (UsrCod,E_mail,MailKey,DateAndTime)" - " VALUES" - " (%ld,'%s','%s',NOW())", - Gbl.Usrs.Me.UsrDat.UsrCod, - Email, - MailKey) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryREPLACE_free (Query,"can not create pending password"); + DB_BuildQuery ("INSERT INTO pending_emails" + " (UsrCod,E_mail,MailKey,DateAndTime)" + " VALUES" + " (%ld,'%s','%s',NOW())", + Gbl.Usrs.Me.UsrDat.UsrCod, + Email, + MailKey); + DB_QueryREPLACE_new ("can not create pending password"); } /*****************************************************************************/ diff --git a/swad_network.c b/swad_network.c index e63a71229..0822398b9 100644 --- a/swad_network.c +++ b/swad_network.c @@ -390,7 +390,6 @@ void Net_UpdateMyWebsAndSocialNets (void) static void Net_GetMyWebsAndSocialNetsFromForm (void) { - char *Query; Net_WebsAndSocialNetworks_t Web; char URL[Cns_MAX_BYTES_WWW + 1]; @@ -406,24 +405,22 @@ static void Net_GetMyWebsAndSocialNetsFromForm (void) if (URL[0]) { /***** Insert or replace web / social network *****/ - if (asprintf (&Query,"REPLACE INTO usr_webs" - " (UsrCod,Web,URL)" - " VALUES" - " (%ld,'%s','%s')", - Gbl.Usrs.Me.UsrDat.UsrCod, - Net_WebsAndSocialNetworksDB[Web], - URL) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryREPLACE_free (Query,"can not update user's web / social network"); + DB_BuildQuery ("REPLACE INTO usr_webs" + " (UsrCod,Web,URL)" + " VALUES" + " (%ld,'%s','%s')", + Gbl.Usrs.Me.UsrDat.UsrCod, + Net_WebsAndSocialNetworksDB[Web], + URL); + DB_QueryREPLACE_new ("can not update user's web / social network"); } else { /***** Remove web / social network *****/ - if (asprintf (&Query,"DELETE FROM usr_webs WHERE UsrCod=%ld AND Web='%s'", - Gbl.Usrs.Me.UsrDat.UsrCod, - Net_WebsAndSocialNetworksDB[Web]) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryREPLACE_free (Query,"can not remove user's web / social network"); + DB_BuildQuery ("DELETE FROM usr_webs WHERE UsrCod=%ld AND Web='%s'", + Gbl.Usrs.Me.UsrDat.UsrCod, + Net_WebsAndSocialNetworksDB[Web]); + DB_QueryDELETE_new ("can not remove user's web / social network"); } } diff --git a/swad_nickname.c b/swad_nickname.c index 5eec9e588..8f78d0956 100644 --- a/swad_nickname.c +++ b/swad_nickname.c @@ -498,14 +498,11 @@ void Nck_RemoveOtherUsrNick (void) static void Nck_RemoveNicknameFromDB (long UsrCod,const char *Nickname) { - char *Query; - /***** Remove a nickname *****/ - if (asprintf (&Query,"DELETE FROM usr_nicknames" - " WHERE UsrCod=%ld AND Nickname='%s'", - UsrCod,Nickname) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryREPLACE_free (Query,"can not remove a nickname"); + DB_BuildQuery ("DELETE FROM usr_nicknames" + " WHERE UsrCod=%ld AND Nickname='%s'", + UsrCod,Nickname); + DB_QueryREPLACE_new ("can not remove a nickname"); } /*****************************************************************************/ @@ -634,14 +631,11 @@ static void Nck_UpdateUsrNick (struct UsrData *UsrDat) void Nck_UpdateNickInDB (long UsrCod,const char *NewNickname) { - char *Query; - /***** Update user's nickname in database *****/ - if (asprintf (&Query,"REPLACE INTO usr_nicknames" - " (UsrCod,Nickname,CreatTime)" - " VALUES" - " (%ld,'%s',NOW())", - UsrCod,NewNickname) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryREPLACE_free (Query,"can not update nickname"); + DB_BuildQuery ("REPLACE INTO usr_nicknames" + " (UsrCod,Nickname,CreatTime)" + " VALUES" + " (%ld,'%s',NOW())", + UsrCod,NewNickname); + DB_QueryREPLACE_new ("can not update nickname"); } diff --git a/swad_notification.c b/swad_notification.c index 92f6c4089..5cae23739 100644 --- a/swad_notification.c +++ b/swad_notification.c @@ -1890,7 +1890,6 @@ static void Ntf_UpdateNumNotifSent (long DegCod,long CrsCod, Ntf_NotifyEvent_t NotifyEvent, unsigned NumEvents,unsigned NumMails) { - char *Query; unsigned CurrentNumEvents; unsigned CurrentNumMails; @@ -1898,15 +1897,14 @@ static void Ntf_UpdateNumNotifSent (long DegCod,long CrsCod, Ntf_GetNumNotifSent (DegCod,CrsCod,NotifyEvent,&CurrentNumEvents,&CurrentNumMails); /***** Update number of users notified *****/ - if (asprintf (&Query,"REPLACE INTO sta_notif" - " (DegCod,CrsCod,NotifyEvent,NumEvents,NumMails)" - " VALUES" - " (%ld,%ld,%u,%u,%u)", - DegCod,CrsCod,(unsigned) NotifyEvent, - CurrentNumEvents + NumEvents, - CurrentNumMails + NumMails) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryREPLACE_free (Query,"can not update the number of sent notifications"); + DB_BuildQuery ("REPLACE INTO sta_notif" + " (DegCod,CrsCod,NotifyEvent,NumEvents,NumMails)" + " VALUES" + " (%ld,%ld,%u,%u,%u)", + DegCod,CrsCod,(unsigned) NotifyEvent, + CurrentNumEvents + NumEvents, + CurrentNumMails + NumMails); + DB_QueryREPLACE_new ("can not update the number of sent notifications"); } /*****************************************************************************/ diff --git a/swad_password.c b/swad_password.c index 45ed940ec..4d447b108 100644 --- a/swad_password.c +++ b/swad_password.c @@ -512,26 +512,22 @@ static void Pwd_CreateANewPassword (char PlainPassword[Pwd_MAX_BYTES_PLAIN_PASSW void Pwd_SetMyPendingPassword (char PlainPassword[Pwd_MAX_BYTES_PLAIN_PASSWORD + 1]) { - char *Query; - /***** Encrypt my pending password *****/ Cry_EncryptSHA512Base64 (PlainPassword,Gbl.Usrs.Me.PendingPassword); /***** Remove expired pending passwords from database *****/ - if (asprintf (&Query,"DELETE FROM pending_passwd" - " WHERE DateAndTime