diff --git a/swad_changelog.h b/swad_changelog.h index 564c709cb..9c9a42fc0 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.16 (2018-10-28)" +#define Log_PLATFORM_VERSION "SWAD 18.8.17 (2018-10-28)" #define CSS_FILE "swad18.4.css" #define JS_FILE "swad17.17.1.js" /* + Version 18.8.17: Oct 28, 2018 Some asprintf for database queries changed by internal function. (236116 lines) Version 18.8.16: Oct 28, 2018 Some asprintf for database queries changed by internal function. (236263 lines) Version 18.8.15: Oct 28, 2018 Some asprintf for database queries changed by internal function. (236425 lines) Version 18.8.14: Oct 28, 2018 Some asprintf for database queries changed by internal function. (236493 lines) diff --git a/swad_database.c b/swad_database.c index 6d1a183a3..3bc79ccdc 100644 --- a/swad_database.c +++ b/swad_database.c @@ -3331,17 +3331,6 @@ void DB_QueryDELETE_new (const char *MsgError) DB_ExitOnMySQLError (MsgError); } -void DB_QueryDELETE_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_QueryDELETE (const char *Query,const char *MsgError) { /***** Query database *****/ diff --git a/swad_database.h b/swad_database.h index 3a4091ed4..52f7854b7 100644 --- a/swad_database.h +++ b/swad_database.h @@ -58,7 +58,6 @@ void DB_QueryUPDATE_new (const char *MsgError); void DB_QueryUPDATE (const char *Query,const char *MsgError); void DB_QueryDELETE_new (const char *MsgError); -void DB_QueryDELETE_free (const char *Query,const char *MsgError); void DB_QueryDELETE (const char *Query,const char *MsgError); void DB_Query_free (const char *Query,const char *MsgError); diff --git a/swad_follow.c b/swad_follow.c index ccc16a291..c8a0cf587 100644 --- a/swad_follow.c +++ b/swad_follow.c @@ -1203,11 +1203,8 @@ void Fol_GetNotifFollower (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1], void Fol_RemoveUsrFromUsrFollow (long UsrCod) { - char *Query; - - if (asprintf (&Query,"DELETE FROM usr_follow" - " WHERE FollowerCod=%ld OR FollowedCod=%ld", - UsrCod,UsrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryDELETE_free (Query,"can not remove user from followers and followed"); + DB_BuildQuery ("DELETE FROM usr_follow" + " WHERE FollowerCod=%ld OR FollowedCod=%ld", + UsrCod,UsrCod); + DB_QueryDELETE_new ("can not remove user from followers and followed"); } diff --git a/swad_forum.c b/swad_forum.c index 7d8f9c595..203ac1073 100644 --- a/swad_forum.c +++ b/swad_forum.c @@ -469,13 +469,9 @@ static bool For_GetIfPstIsEnabled (long PstCod) static void For_DeletePstFromDisabledPstTable (long PstCod) { - char *Query; - /***** Remove post from disabled posts table *****/ - if (asprintf (&Query,"DELETE FROM forum_disabled_post WHERE PstCod=%ld", - PstCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryDELETE_free (Query,"can not unban a post of a forum"); + DB_BuildQuery ("DELETE FROM forum_disabled_post WHERE PstCod=%ld",PstCod); + DB_QueryDELETE_new ("can not unban a post of a forum"); } /*****************************************************************************/ @@ -533,7 +529,6 @@ static long For_InsertForumPst (long ThrCod,long UsrCod, static bool For_RemoveForumPst (long PstCod,struct Image *Image) { - char *Query; long ThrCod; bool ThreadDeleted = false; @@ -548,10 +543,8 @@ static bool For_RemoveForumPst (long PstCod,struct Image *Image) } /***** Delete post from forum post table *****/ - if (asprintf (&Query,"DELETE FROM forum_post WHERE PstCod=%ld", - PstCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryDELETE_free (Query,"can not remove a post from a forum"); + DB_BuildQuery ("DELETE FROM forum_post WHERE PstCod=%ld",PstCod); + DB_QueryDELETE_new ("can not remove a post from a forum"); /***** Delete the post from the table of disabled forum posts *****/ For_DeletePstFromDisabledPstTable (PstCod); @@ -615,8 +608,6 @@ static long For_InsertForumThread (long FirstPstCod) static void For_RemoveThreadOnly (long ThrCod) { - char *Query; - /***** Indicate that this thread has not been read by anyone *****/ For_DeleteThrFromReadThrs (ThrCod); @@ -624,10 +615,8 @@ static void For_RemoveThreadOnly (long ThrCod) For_RemoveThrCodFromThrClipboard (ThrCod); /***** Delete thread from forum thread table *****/ - if (asprintf (&Query,"DELETE FROM forum_thread WHERE ThrCod=%ld", - ThrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryDELETE_free (Query,"can not remove a thread from a forum"); + DB_BuildQuery ("DELETE FROM forum_thread WHERE ThrCod=%ld",ThrCod); + DB_QueryDELETE_new ("can not remove a thread from a forum"); } /*****************************************************************************/ @@ -636,22 +625,17 @@ static void For_RemoveThreadOnly (long ThrCod) static void For_RemoveThreadAndItsPsts (long ThrCod) { - char *Query; - /***** Delete banned posts in thread *****/ - if (asprintf (&Query,"DELETE forum_disabled_post" - " FROM forum_post,forum_disabled_post" - " WHERE forum_post.ThrCod=%ld" - " AND forum_post.PstCod=forum_disabled_post.PstCod", - ThrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryDELETE_free (Query,"can not unban the posts of a thread of a forum"); + DB_BuildQuery ("DELETE forum_disabled_post" + " FROM forum_post,forum_disabled_post" + " WHERE forum_post.ThrCod=%ld" + " AND forum_post.PstCod=forum_disabled_post.PstCod", + ThrCod); + DB_QueryDELETE_new ("can not unban the posts of a thread of a forum"); /***** Delete thread posts *****/ - if (asprintf (&Query,"DELETE FROM forum_post WHERE ThrCod=%ld", - ThrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryDELETE_free (Query,"can not remove the posts of a thread of a forum"); + DB_BuildQuery ("DELETE FROM forum_post WHERE ThrCod=%ld",ThrCod); + DB_QueryDELETE_new ("can not remove the posts of a thread of a forum"); /***** Delete thread from forum thread table *****/ For_RemoveThreadOnly (ThrCod); @@ -912,13 +896,9 @@ static time_t For_GetThrReadTime (long ThrCod) static void For_DeleteThrFromReadThrs (long ThrCod) { - char *Query; - /***** Delete pairs ThrCod-UsrCod in forum_thr_read for a thread *****/ - if (asprintf (&Query,"DELETE FROM forum_thr_read WHERE ThrCod=%ld", - ThrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryDELETE_free (Query,"can not remove the status of reading of a thread of a forum"); + DB_BuildQuery ("DELETE FROM forum_thr_read WHERE ThrCod=%ld",ThrCod); + DB_QueryDELETE_new ("can not remove the status of reading of a thread of a forum"); } /*****************************************************************************/ @@ -927,13 +907,9 @@ static void For_DeleteThrFromReadThrs (long ThrCod) void For_RemoveUsrFromReadThrs (long UsrCod) { - char *Query; - /***** Delete pairs ThrCod-UsrCod in forum_thr_read for a user *****/ - if (asprintf (&Query,"DELETE FROM forum_thr_read WHERE UsrCod=%ld", - UsrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryDELETE_free (Query,"can not remove the status of reading by a user of all the threads of a forum"); + DB_BuildQuery ("DELETE FROM forum_thr_read WHERE UsrCod=%ld",UsrCod); + DB_QueryDELETE_new ("can not remove the status of reading by a user of all the threads of a forum"); } /*****************************************************************************/ @@ -4439,14 +4415,11 @@ static void For_InsertThrInClipboard (long ThrCod) static void For_RemoveExpiredThrsClipboards (void) { - char *Query; - /***** Remove all expired clipboards *****/ - if (asprintf (&Query,"DELETE LOW_PRIORITY FROM forum_thr_clip" - " WHERE TimeInsert%ld", - NewEmail,UsrDat->UsrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryDELETE_free (Query,"can not remove pending email for other users"); + DB_BuildQuery ("DELETE FROM pending_emails" + " WHERE E_mail='%s' AND UsrCod<>%ld", + NewEmail,UsrDat->UsrCod); + DB_QueryDELETE_new ("can not remove pending email for other users"); - if (asprintf (&Query,"DELETE FROM usr_emails" - " WHERE E_mail='%s' AND Confirmed='N'" - " AND UsrCod<>%ld", - NewEmail,UsrDat->UsrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryDELETE_free (Query,"can not remove not confirmed email for other users"); + DB_BuildQuery ("DELETE FROM usr_emails" + " WHERE E_mail='%s' AND Confirmed='N'" + " AND UsrCod<>%ld", + NewEmail,UsrDat->UsrCod); + DB_QueryDELETE_new ("can not remove not confirmed email for other users"); /***** Update email in database *****/ DB_BuildQuery ("REPLACE INTO usr_emails" @@ -1771,14 +1764,11 @@ bool Mai_SendMailMsgToConfirmEmail (void) static void Mai_InsertMailKey (const char Email[Cns_MAX_BYTES_EMAIL_ADDRESS + 1], const char MailKey[Mai_LENGTH_EMAIL_CONFIRM_KEY + 1]) { - char *Query; - /***** Remove expired pending emails from database *****/ - if (asprintf (&Query,"DELETE FROM pending_emails" - " WHERE DateAndTime remove it { /***** Remove place *****/ - if (asprintf (&Query,"DELETE FROM places WHERE PlcCod=%ld", - Plc.PlcCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryDELETE_free (Query,"can not remove a place"); + DB_BuildQuery ("DELETE FROM places WHERE PlcCod=%ld",Plc.PlcCod); + DB_QueryDELETE_new ("can not remove a place"); /***** Write message to show the change made *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), diff --git a/swad_plugin.c b/swad_plugin.c index efff5f02d..821b1521c 100644 --- a/swad_plugin.c +++ b/swad_plugin.c @@ -486,7 +486,6 @@ long Plg_GetParamPlgCod (void) void Plg_RemovePlugin (void) { extern const char *Txt_Plugin_X_removed; - char *Query; struct Plugin Plg; /***** Get plugin code *****/ @@ -497,10 +496,8 @@ void Plg_RemovePlugin (void) Plg_GetDataOfPluginByCod (&Plg); /***** Remove plugin *****/ - if (asprintf (&Query,"DELETE FROM plugins WHERE PlgCod=%ld", - Plg.PlgCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryDELETE_free (Query,"can not remove a plugin"); + DB_BuildQuery ("DELETE FROM plugins WHERE PlgCod=%ld",Plg.PlgCod); + DB_QueryDELETE_new ("can not remove a plugin"); /***** Write message to show the change made *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), diff --git a/swad_preference.c b/swad_preference.c index 321d23500..279a51977 100644 --- a/swad_preference.c +++ b/swad_preference.c @@ -216,14 +216,11 @@ void Pre_SetPrefsFromIP (void) void Pre_RemoveOldPrefsFromIP (void) { - char *Query; - /***** Remove old preferences *****/ - if (asprintf (&Query,"DELETE LOW_PRIORITY FROM IP_prefs" - " WHERE LastChangeCrsCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryDELETE_free (Query,"can not remove user's record in a course"); + DB_BuildQuery ("DELETE FROM crs_records" + " WHERE UsrCod=%ld AND FieldCod IN" + " (SELECT FieldCod FROM crs_record_fields WHERE CrsCod=%ld)", + UsrCod,Crs->CrsCod); + DB_QueryDELETE_new ("can not remove user's record in a course"); } /*****************************************************************************/ @@ -2049,12 +2043,9 @@ void Rec_RemoveFieldsCrsRecordInCrs (long UsrCod,struct Course *Crs) void Rec_RemoveFieldsCrsRecordAll (long UsrCod) { - char *Query; - /***** Remove text of the field of record course *****/ - if (asprintf (&Query,"DELETE FROM crs_records WHERE UsrCod=%ld",UsrCod) < 0) - Lay_NotEnoughMemoryExit (); - DB_QueryDELETE_free (Query,"can not remove user's records in all courses"); + DB_BuildQuery ("DELETE FROM crs_records WHERE UsrCod=%ld",UsrCod); + DB_QueryDELETE_new ("can not remove user's records in all courses"); } /*****************************************************************************/