From 8ec272448b971b56498d27645148cc55460b008e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Fri, 2 Nov 2018 19:37:11 +0100 Subject: [PATCH] Version 18.11.19 --- swad_ID.c | 24 +++++----- swad_account.c | 18 ++++---- swad_announcement.c | 12 ++--- swad_assignment.c | 15 +++--- swad_attendance.c | 15 +++--- swad_banner.c | 12 ++--- swad_changelog.h | 3 +- swad_country.c | 14 +++--- swad_course.c | 14 +++--- swad_database.c | 28 +++++------ swad_database.h | 5 +- swad_degree_type.c | 6 +-- swad_department.c | 12 ++--- swad_duplicate.c | 14 +++--- swad_enrolment.c | 38 +++++++-------- swad_file_browser.c | 48 +++++++++---------- swad_game.c | 46 +++++++++--------- swad_group.c | 28 +++++------ swad_holiday.c | 26 +++++------ swad_info.c | 18 ++++---- swad_link.c | 12 ++--- swad_mail.c | 12 ++--- swad_mark.c | 20 ++++---- swad_message.c | 103 +++++++++++++++++++++-------------------- swad_notice.c | 14 +++--- swad_notification.c | 19 ++++---- swad_photo.c | 12 ++--- swad_place.c | 12 ++--- swad_plugin.c | 18 ++++---- swad_profile.c | 54 +++++++++++----------- swad_project.c | 16 +++---- swad_record.c | 36 +++++++-------- swad_report.c | 36 +++++++-------- swad_session.c | 54 +++++++++++----------- swad_social.c | 77 ++++++++++++++++--------------- swad_statistic.c | 67 +++++++++++++-------------- swad_survey.c | 40 ++++++++-------- swad_test.c | 110 ++++++++++++++++++++++---------------------- swad_timetable.c | 58 +++++++++++------------ swad_user.c | 32 ++++++------- swad_web_service.c | 76 +++++++++++++----------------- 41 files changed, 620 insertions(+), 654 deletions(-) diff --git a/swad_ID.c b/swad_ID.c index 7f854add2..a5c5f245b 100644 --- a/swad_ID.c +++ b/swad_ID.c @@ -1015,14 +1015,14 @@ static void ID_NewUsrID (const struct UsrData *UsrDat,bool ItsMe) static void ID_InsertANewUsrIDInDB (long UsrCod,const char *NewID,bool Confirmed) { /***** Update my nickname in database *****/ - DB_BuildQuery ("INSERT INTO usr_IDs" - " (UsrCod,UsrID,CreatTime,Confirmed)" - " VALUES" - " (%ld,'%s',NOW(),'%c')", - UsrCod,NewID, - Confirmed ? 'Y' : - 'N'); - DB_QueryINSERT_new ("can not insert a new ID"); + DB_QueryINSERT ("can not insert a new ID", + "INSERT INTO usr_IDs" + " (UsrCod,UsrID,CreatTime,Confirmed)" + " VALUES" + " (%ld,'%s',NOW(),'%c')", + UsrCod,NewID, + Confirmed ? 'Y' : + 'N'); } /*****************************************************************************/ @@ -1148,8 +1148,8 @@ void ID_ConfirmOtherUsrID (void) void ID_ConfirmUsrID (const struct UsrData *UsrDat,const char *UsrID) { /***** Update database *****/ - DB_BuildQuery ("UPDATE usr_IDs SET Confirmed='Y'" - " WHERE UsrCod=%ld AND UsrID='%s' AND Confirmed<>'Y'", - UsrDat->UsrCod,UsrID); - DB_QueryINSERT_new ("can not confirm a user's ID"); + DB_QueryINSERT ("can not confirm a user's ID", + "UPDATE usr_IDs SET Confirmed='Y'" + " WHERE UsrCod=%ld AND UsrID='%s' AND Confirmed<>'Y'", + UsrDat->UsrCod,UsrID); } diff --git a/swad_account.c b/swad_account.c index 36793b2f3..671dc36a8 100644 --- a/swad_account.c +++ b/swad_account.c @@ -775,15 +775,15 @@ void Acc_CreateNewUsr (struct UsrData *UsrDat,bool CreatingMyOwnAccount) NumID++) { Str_ConvertToUpperText (UsrDat->IDs.List[NumID].ID); - DB_BuildQuery ("INSERT INTO usr_IDs" - " (UsrCod,UsrID,CreatTime,Confirmed)" - " VALUES" - " (%ld,'%s',NOW(),'%c')", - UsrDat->UsrCod, - UsrDat->IDs.List[NumID].ID, - UsrDat->IDs.List[NumID].Confirmed ? 'Y' : - 'N'); - DB_QueryINSERT_new ("can not store user's ID when creating user"); + DB_QueryINSERT ("can not store user's ID when creating user", + "INSERT INTO usr_IDs" + " (UsrCod,UsrID,CreatTime,Confirmed)" + " VALUES" + " (%ld,'%s',NOW(),'%c')", + UsrDat->UsrCod, + UsrDat->IDs.List[NumID].ID, + UsrDat->IDs.List[NumID].Confirmed ? 'Y' : + 'N'); } /***** Create directory for the user, if not exists *****/ diff --git a/swad_announcement.c b/swad_announcement.c index b1a2f0ae4..9b8c898c5 100644 --- a/swad_announcement.c +++ b/swad_announcement.c @@ -512,12 +512,12 @@ void Ann_ReceiveAnnouncement (void) static void Ann_CreateAnnouncement (unsigned Roles,const char *Subject,const char *Content) { /***** Select announcements not seen *****/ - DB_BuildQuery ("INSERT INTO announcements" - " (Roles,Subject,Content)" - " VALUES" - " (%u,'%s','%s')", - Roles,Subject,Content); - DB_QueryINSERT_new ("can not create announcement"); + DB_QueryINSERT ("can not create announcement", + "INSERT INTO announcements" + " (Roles,Subject,Content)" + " VALUES" + " (%u,'%s','%s')", + Roles,Subject,Content); } /*****************************************************************************/ diff --git a/swad_assignment.c b/swad_assignment.c index db621a358..e5afab202 100644 --- a/swad_assignment.c +++ b/swad_assignment.c @@ -1617,15 +1617,14 @@ static void Asg_CreateGrps (long AsgCod) for (NumGrpSel = 0; NumGrpSel < Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps; NumGrpSel++) - { /* Create group */ - DB_BuildQuery ("INSERT INTO asg_grp" - " (AsgCod,GrpCod)" - " VALUES" - " (%ld,%ld)", - AsgCod,Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods[NumGrpSel]); - DB_QueryINSERT_new ("can not associate a group to an assignment"); - } + DB_QueryINSERT ("can not associate a group to an assignment", + "INSERT INTO asg_grp" + " (AsgCod,GrpCod)" + " VALUES" + " (%ld,%ld)", + AsgCod, + Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods[NumGrpSel]); } /*****************************************************************************/ diff --git a/swad_attendance.c b/swad_attendance.c index 50b3e7bbe..b130acf5b 100644 --- a/swad_attendance.c +++ b/swad_attendance.c @@ -1483,15 +1483,14 @@ static void Att_CreateGrps (long AttCod) for (NumGrpSel = 0; NumGrpSel < Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps; NumGrpSel++) - { /* Create group */ - DB_BuildQuery ("INSERT INTO att_grp" - " (AttCod,GrpCod)" - " VALUES" - " (%ld,%ld)", - AttCod,Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods[NumGrpSel]); - DB_QueryINSERT_new ("can not associate a group to an attendance event"); - } + DB_QueryINSERT ("can not associate a group to an attendance event", + "INSERT INTO att_grp" + " (AttCod,GrpCod)" + " VALUES" + " (%ld,%ld)", + AttCod, + Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods[NumGrpSel]); } /*****************************************************************************/ diff --git a/swad_banner.c b/swad_banner.c index 4f84df576..9452f1431 100644 --- a/swad_banner.c +++ b/swad_banner.c @@ -986,12 +986,12 @@ static void Ban_CreateBanner (struct Banner *Ban) extern const char *Txt_Created_new_banner_X; /***** Create a new banner *****/ - DB_BuildQuery ("INSERT INTO banners" - " (Hidden,ShortName,FullName,Img,WWW)" - " VALUES" - " ('N','%s','%s','%s','%s')", - Ban->ShrtName,Ban->FullName,Ban->Img,Ban->WWW); - DB_QueryINSERT_new ("can not create banner"); + DB_QueryINSERT ("can not create banner", + "INSERT INTO banners" + " (Hidden,ShortName,FullName,Img,WWW)" + " VALUES" + " ('N','%s','%s','%s','%s')", + Ban->ShrtName,Ban->FullName,Ban->Img,Ban->WWW); /***** Write success message *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), diff --git a/swad_changelog.h b/swad_changelog.h index 03d15364c..dfa44cf68 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.18 (2018-11-02)" +#define Log_PLATFORM_VERSION "SWAD 18.11.19 (2018-11-02)" #define CSS_FILE "swad18.4.css" #define JS_FILE "swad17.17.1.js" /* + Version 18.11.19: Nov 02, 2018 Joining building and performing query into one function. (236465 lines) Version 18.11.18: Nov 02, 2018 Joining building and performing query into one function. (236499 lines) Version 18.11.17: Nov 02, 2018 Joining building and performing query into one function. (236504 lines) Version 18.11.16: Nov 02, 2018 Joining building and performing query into one function. (236332 lines) diff --git a/swad_country.c b/swad_country.c index 1febb158a..5126dcb31 100644 --- a/swad_country.c +++ b/swad_country.c @@ -2255,13 +2255,13 @@ static void Cty_CreateCountry (struct Country *Cty) Str_Concat (SubQueryWWW2,"'", Cty_MAX_BYTES_SUBQUERY_CTYS_WWW); } - DB_BuildQuery ("INSERT INTO countries" - " (CtyCod,Alpha2%s%s)" - " VALUES" - " ('%03ld','%s'%s%s)", - SubQueryNam1,SubQueryWWW1, - Cty->CtyCod,Cty->Alpha2,SubQueryNam2,SubQueryWWW2); - DB_QueryINSERT_new ("can not create country"); + DB_QueryINSERT ("can not create country", + "INSERT INTO countries" + " (CtyCod,Alpha2%s%s)" + " VALUES" + " ('%03ld','%s'%s%s)", + SubQueryNam1,SubQueryWWW1, + Cty->CtyCod,Cty->Alpha2,SubQueryNam2,SubQueryWWW2); /***** Write success message *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), diff --git a/swad_course.c b/swad_course.c index 919d6c73a..57c393d36 100644 --- a/swad_course.c +++ b/swad_course.c @@ -2208,13 +2208,13 @@ static void Crs_EmptyCourseCompletely (long CrsCod) /***** Remove notices in the course *****/ /* Copy all notices from the course to table of deleted notices */ - DB_BuildQuery ("INSERT INTO notices_deleted" - " (NotCod,CrsCod,UsrCod,CreatTime,Content,NumNotif)" - " SELECT NotCod,CrsCod,UsrCod,CreatTime,Content,NumNotif" - " FROM notices" - " WHERE CrsCod=%ld", - CrsCod); - DB_QueryINSERT_new ("can not remove notices in a course"); + DB_QueryINSERT ("can not remove notices in a course", + "INSERT INTO notices_deleted" + " (NotCod,CrsCod,UsrCod,CreatTime,Content,NumNotif)" + " SELECT NotCod,CrsCod,UsrCod,CreatTime,Content,NumNotif" + " FROM notices" + " WHERE CrsCod=%ld", + CrsCod); /* Remove all notices from the course */ DB_BuildQuery ("DELETE FROM notices WHERE CrsCod=%ld",CrsCod); diff --git a/swad_database.c b/swad_database.c index 6f1e64d16..6d6d2f49a 100644 --- a/swad_database.c +++ b/swad_database.c @@ -3154,8 +3154,7 @@ unsigned long DB_QuerySELECT_old (char **Query,MYSQL_RES **mysql_res,const char /**************** Make a SELECT COUNT query from database ********************/ /*****************************************************************************/ -unsigned long DB_QueryCOUNT (const char *MsgError, - const char *fmt,...) +unsigned long DB_QueryCOUNT (const char *MsgError,const char *fmt,...) { va_list ap; int NumBytesPrinted; @@ -3202,21 +3201,22 @@ unsigned long DB_QueryCOUNT_old (char **Query,const char *MsgError) /******************** Make an INSERT query in database ***********************/ /*****************************************************************************/ -void DB_QueryINSERT_new (const char *MsgError) +void DB_QueryINSERT (const char *MsgError,const char *fmt,...) { - int Result; + va_list ap; + int NumBytesPrinted; + char *Query = NULL; - /***** Check that query string pointer - does point to an allocated string *****/ - if (Gbl.DB.QueryPtr == NULL) - Lay_ShowErrorAndExit ("Wrong query string."); + va_start (ap,fmt); + NumBytesPrinted = vasprintf (&Query,fmt,ap); + va_end (ap); - /***** Query database and free query string pointer *****/ - Result = mysql_query (&Gbl.mysql,Gbl.DB.QueryPtr); // Returns 0 on success - free ((void *) Gbl.DB.QueryPtr); - Gbl.DB.QueryPtr = NULL; - if (Result) - DB_ExitOnMySQLError (MsgError); + if (NumBytesPrinted < 0) // If memory allocation wasn't possible, + // or some other error occurs, + // vasprintf will return -1 + Lay_NotEnoughMemoryExit (); + + DB_QueryINSERT_old (&Query,MsgError); } /*****************************************************************************/ diff --git a/swad_database.h b/swad_database.h index 545659092..7ba2dd72e 100644 --- a/swad_database.h +++ b/swad_database.h @@ -44,12 +44,11 @@ unsigned long DB_QuerySELECT (MYSQL_RES **mysql_res,const char *MsgError, const char *fmt,...); unsigned long DB_QuerySELECT_old (char **Query,MYSQL_RES **mysql_res,const char *MsgError); -unsigned long DB_QueryCOUNT (const char *MsgError, - const char *fmt,...); +unsigned long DB_QueryCOUNT (const char *MsgError,const char *fmt,...); unsigned long DB_QueryCOUNT_new (const char *MsgError); unsigned long DB_QueryCOUNT_old (char **Query,const char *MsgError); -void DB_QueryINSERT_new (const char *MsgError); +void DB_QueryINSERT (const char *MsgError,const char *fmt,...); void DB_QueryINSERT_old (char **Query,const char *MsgError); long DB_QueryINSERTandReturnCode_new (const char *MsgError); diff --git a/swad_degree_type.c b/swad_degree_type.c index f404764ce..5d66ce201 100644 --- a/swad_degree_type.c +++ b/swad_degree_type.c @@ -546,9 +546,9 @@ static void DT_CreateDegreeType (struct DegreeType *DegTyp) extern const char *Txt_Created_new_type_of_degree_X; /***** Create a new degree type *****/ - DB_BuildQuery ("INSERT INTO deg_types SET DegTypName='%s'", - DegTyp->DegTypName); - DB_QueryINSERT_new ("can not create a new type of degree"); + DB_QueryINSERT ("can not create a new type of degree", + "INSERT INTO deg_types SET DegTypName='%s'", + DegTyp->DegTypName); /***** Write success message *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), diff --git a/swad_department.c b/swad_department.c index ea20f8af9..4262493ed 100644 --- a/swad_department.c +++ b/swad_department.c @@ -1051,12 +1051,12 @@ static void Dpt_CreateDepartment (struct Department *Dpt) extern const char *Txt_Created_new_department_X; /***** Create a new department *****/ - DB_BuildQuery ("INSERT INTO departments" - " (InsCod,ShortName,FullName,WWW)" - " VALUES" - " (%ld,'%s','%s','%s')", - Dpt->InsCod,Dpt->ShrtName,Dpt->FullName,Dpt->WWW); - DB_QueryINSERT_new ("can not create a new department"); + DB_QueryINSERT ("can not create a new department", + "INSERT INTO departments" + " (InsCod,ShortName,FullName,WWW)" + " VALUES" + " (%ld,'%s','%s','%s')", + Dpt->InsCod,Dpt->ShrtName,Dpt->FullName,Dpt->WWW); /***** Write success message *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), diff --git a/swad_duplicate.c b/swad_duplicate.c index 8de9b777b..ec186b285 100644 --- a/swad_duplicate.c +++ b/swad_duplicate.c @@ -92,13 +92,13 @@ void Dup_ReportUsrAsPossibleDuplicate (void) if (!ItsMe && Gbl.Usrs.Me.Role.Logged >= Rol_TCH) { /***** Insert possible duplicate into database *****/ - DB_BuildQuery ("REPLACE INTO usr_duplicated" - " (UsrCod,InformerCod,InformTime)" - " VALUES" - " (%ld,%ld,NOW())", - Gbl.Usrs.Other.UsrDat.UsrCod, - Gbl.Usrs.Me.UsrDat.UsrCod); - DB_QueryINSERT_new ("can not report duplicate"); + DB_QueryINSERT ("can not report duplicate", + "REPLACE INTO usr_duplicated" + " (UsrCod,InformerCod,InformTime)" + " VALUES" + " (%ld,%ld,NOW())", + Gbl.Usrs.Other.UsrDat.UsrCod, + Gbl.Usrs.Me.UsrDat.UsrCod); /***** Show feedback message *****/ Ale_ShowAlert (Ale_SUCCESS,Txt_Thank_you_for_reporting_a_possible_duplicate_user); diff --git a/swad_enrolment.c b/swad_enrolment.c index e183a2475..3a85a9908 100644 --- a/swad_enrolment.c +++ b/swad_enrolment.c @@ -264,25 +264,25 @@ void Enr_RegisterUsrInCurrentCrs (struct UsrData *UsrDat,Rol_Role_t NewRole, } /***** Register user in current course in database *****/ - DB_BuildQuery ("INSERT INTO crs_usr" - " (CrsCod,UsrCod,Role,Accepted," - "LastDowGrpCod,LastComGrpCod,LastAssGrpCod," - "NumAccTst,LastAccTst,NumQstsLastTst," - "UsrListType,ColsClassPhoto,ListWithPhotos)" - " VALUES" - " (%ld,%ld,%u,'%c'," - "-1,-1,-1," - "0,FROM_UNIXTIME(%ld),0," - "'%s',%u,'%c')", - Gbl.CurrentCrs.Crs.CrsCod,UsrDat->UsrCod,(unsigned) NewRole, - KeepOrSetAccepted == Enr_SET_ACCEPTED_TO_TRUE ? 'Y' : - 'N', - (long) (time_t) 0, // The user never accessed to tests in this course - Usr_StringsUsrListTypeInDB[Usr_SHOW_USRS_TYPE_DEFAULT], - Usr_CLASS_PHOTO_COLS_DEF, - Usr_LIST_WITH_PHOTOS_DEF ? 'Y' : - 'N'); - DB_QueryINSERT_new ("can not register user in course"); + DB_QueryINSERT ("can not register user in course", + "INSERT INTO crs_usr" + " (CrsCod,UsrCod,Role,Accepted," + "LastDowGrpCod,LastComGrpCod,LastAssGrpCod," + "NumAccTst,LastAccTst,NumQstsLastTst," + "UsrListType,ColsClassPhoto,ListWithPhotos)" + " VALUES" + " (%ld,%ld,%u,'%c'," + "-1,-1,-1," + "0,FROM_UNIXTIME(%ld),0," + "'%s',%u,'%c')", + Gbl.CurrentCrs.Crs.CrsCod,UsrDat->UsrCod,(unsigned) NewRole, + KeepOrSetAccepted == Enr_SET_ACCEPTED_TO_TRUE ? 'Y' : + 'N', + (long) (time_t) 0, // The user never accessed to tests in this course + Usr_StringsUsrListTypeInDB[Usr_SHOW_USRS_TYPE_DEFAULT], + Usr_CLASS_PHOTO_COLS_DEF, + Usr_LIST_WITH_PHOTOS_DEF ? 'Y' : + 'N'); /***** Flush caches *****/ Usr_FlushCachesUsr (); diff --git a/swad_file_browser.c b/swad_file_browser.c index 60e62d4dd..2a1e46983 100644 --- a/swad_file_browser.c +++ b/swad_file_browser.c @@ -7806,14 +7806,14 @@ static void Brw_AddPathToClipboards (void) long WorksUsrCod = Brw_GetWorksUsrCodForClipboard (); /***** Add path to clipboards *****/ - DB_BuildQuery ("INSERT INTO clipboard" - " (UsrCod,FileBrowser,Cod,WorksUsrCod,FileType,Path)" - " VALUES" - " (%ld,%u,%ld,%ld,%u,'%s')", - Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Gbl.FileBrowser.Type, - Cod,WorksUsrCod, - (unsigned) Gbl.FileBrowser.FileType,Gbl.FileBrowser.Priv.FullPathInTree); - DB_QueryINSERT_new ("can not add source of copy to clipboard"); + DB_QueryINSERT ("can not add source of copy to clipboard", + "INSERT INTO clipboard" + " (UsrCod,FileBrowser,Cod,WorksUsrCod,FileType,Path)" + " VALUES" + " (%ld,%u,%ld,%ld,%u,'%s')", + Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Gbl.FileBrowser.Type, + Cod,WorksUsrCod, + (unsigned) Gbl.FileBrowser.FileType,Gbl.FileBrowser.Priv.FullPathInTree); } /*****************************************************************************/ @@ -7956,15 +7956,15 @@ static void Brw_InsertFolderInExpandedFolders (const char Path[PATH_MAX + 1]) /***** Update path time in table of expanded folders *****/ // Path must be stored with final '/' - DB_BuildQuery ("INSERT INTO expanded_folders" - " (UsrCod,FileBrowser,Cod,WorksUsrCod,Path,ClickTime)" - " VALUES" - " (%ld,%u,%ld,%ld,'%s/',NOW())", - Gbl.Usrs.Me.UsrDat.UsrCod, - (unsigned) Brw_FileBrowserForDB_expanded_folders[Gbl.FileBrowser.Type], - Cod,WorksUsrCod, - Path); - DB_QueryINSERT_new ("can not expand the content of a folder"); + DB_QueryINSERT ("can not expand the content of a folder", + "INSERT INTO expanded_folders" + " (UsrCod,FileBrowser,Cod,WorksUsrCod,Path,ClickTime)" + " VALUES" + " (%ld,%u,%ld,%ld,'%s/',NOW())", + Gbl.Usrs.Me.UsrDat.UsrCod, + (unsigned) Brw_FileBrowserForDB_expanded_folders[Gbl.FileBrowser.Type], + Cod,WorksUsrCod, + Path); } /*****************************************************************************/ @@ -11542,15 +11542,13 @@ static void Brw_UpdateFileViews (unsigned NumViews,long FilCod) DB_QueryUPDATE_new ("can not update number of views of a file"); } else // NumViews == 0 - { /* Insert number of views in database */ - DB_BuildQuery ("INSERT INTO file_view" - " (FilCod,UsrCod,NumViews)" - " VALUES" - " (%ld,%ld,1)", - FilCod,Gbl.Usrs.Me.UsrDat.UsrCod); - DB_QueryINSERT_new ("can not insert number of views of a file"); - } + DB_QueryINSERT ("can not insert number of views of a file", + "INSERT INTO file_view" + " (FilCod,UsrCod,NumViews)" + " VALUES" + " (%ld,%ld,1)", + FilCod,Gbl.Usrs.Me.UsrDat.UsrCod); } /*****************************************************************************/ diff --git a/swad_game.c b/swad_game.c index 648248b0c..4f71ca1e3 100644 --- a/swad_game.c +++ b/swad_game.c @@ -2313,15 +2313,13 @@ static void Gam_CreateGrps (long GamCod) for (NumGrpSel = 0; NumGrpSel < Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps; NumGrpSel++) - { /* Create group */ - DB_BuildQuery ("INSERT INTO gam_grp" - " (GamCod,GrpCod)" - " VALUES" - " (%ld,%ld)", - GamCod,Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods[NumGrpSel]); - DB_QueryINSERT_new ("can not associate a group to a game"); - } + DB_QueryINSERT ("can not associate a group to a game", + "INSERT INTO gam_grp" + " (GamCod,GrpCod)" + " VALUES" + " (%ld,%ld)", + GamCod,Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods[NumGrpSel]); } /*****************************************************************************/ @@ -3031,12 +3029,12 @@ void Gam_AddTstQuestionsToGame (void) MaxQstInd = Gam_GetMaxQuestionIndexInGame (Game.GamCod); // -1 if no questions /* Insert question in the table of questions */ - DB_BuildQuery ("INSERT INTO gam_questions" - " (GamCod,QstCod,QstInd)" - " VALUES" - " (%ld,%ld,%u)", - Game.GamCod,QstCod,(unsigned) (MaxQstInd + 1)); - DB_QueryINSERT_new ("can not create question"); + DB_QueryINSERT ("can not create question", + "INSERT INTO gam_questions" + " (GamCod,QstCod,QstInd)" + " VALUES" + " (%ld,%ld,%u)", + Game.GamCod,QstCod,(unsigned) (MaxQstInd + 1)); } /***** Free space for selected question codes *****/ @@ -3750,10 +3748,10 @@ static void Gam_IncreaseAnswerInDB (long QstCod,unsigned AnsInd) { /***** Increase number of users who have selected the answer AnsInd in the question QstCod *****/ - DB_BuildQuery ("UPDATE gam_answers SET NumUsrs=NumUsrs+1" - " WHERE QstCod=%ld AND AnsInd=%u", - QstCod,AnsInd); - DB_QueryINSERT_new ("can not register your answer to the game"); + DB_QueryINSERT ("can not register your answer to the game", + "UPDATE gam_answers SET NumUsrs=NumUsrs+1" + " WHERE QstCod=%ld AND AnsInd=%u", + QstCod,AnsInd); } /*****************************************************************************/ @@ -3762,12 +3760,12 @@ static void Gam_IncreaseAnswerInDB (long QstCod,unsigned AnsInd) static void Gam_RegisterIHaveAnsweredGame (long GamCod) { - DB_BuildQuery ("INSERT INTO gam_users" - " (GamCod,UsrCod)" - " VALUES" - " (%ld,%ld)", - GamCod,Gbl.Usrs.Me.UsrDat.UsrCod); - DB_QueryINSERT_new ("can not register that you have answered the game"); + DB_QueryINSERT ("can not register that you have answered the game", + "INSERT INTO gam_users" + " (GamCod,UsrCod)" + " VALUES" + " (%ld,%ld)", + GamCod,Gbl.Usrs.Me.UsrDat.UsrCod); } /*****************************************************************************/ diff --git a/swad_group.c b/swad_group.c index ade310ae2..2e8f831f3 100644 --- a/swad_group.c +++ b/swad_group.c @@ -1266,12 +1266,12 @@ static void Grp_RemoveUsrFromGroup (long UsrCod,long GrpCod) static void Grp_AddUsrToGroup (struct UsrData *UsrDat,long GrpCod) { /***** Register in group *****/ - DB_BuildQuery ("INSERT INTO crs_grp_usr" - " (GrpCod,UsrCod)" - " VALUES" - " (%ld,%ld)", - GrpCod,UsrDat->UsrCod); - DB_QueryINSERT_new ("can not add a user to a group"); + DB_QueryINSERT ("can not add a user to a group", + "INSERT INTO crs_grp_usr" + " (GrpCod,UsrCod)" + " VALUES" + " (%ld,%ld)", + GrpCod,UsrDat->UsrCod); } /*****************************************************************************/ @@ -3846,14 +3846,14 @@ static void Grp_CreateGroupType (void) static void Grp_CreateGroup (void) { /***** Create a new group *****/ - DB_BuildQuery ("INSERT INTO crs_grp" - " (GrpTypCod,GrpName,MaxStudents,Open,FileZones)" - " VALUES" - " (%ld,'%s',%u,'N','N')", - Gbl.CurrentCrs.Grps.GrpTyp.GrpTypCod, - Gbl.CurrentCrs.Grps.GrpName, - Gbl.CurrentCrs.Grps.MaxStudents); - DB_QueryINSERT_new ("can not create group"); + DB_QueryINSERT ("can not create group", + "INSERT INTO crs_grp" + " (GrpTypCod,GrpName,MaxStudents,Open,FileZones)" + " VALUES" + " (%ld,'%s',%u,'N','N')", + Gbl.CurrentCrs.Grps.GrpTyp.GrpTypCod, + Gbl.CurrentCrs.Grps.GrpName, + Gbl.CurrentCrs.Grps.MaxStudents); } /*****************************************************************************/ diff --git a/swad_holiday.c b/swad_holiday.c index f0a5897a2..b0fcd818c 100644 --- a/swad_holiday.c +++ b/swad_holiday.c @@ -1199,17 +1199,17 @@ void Hld_RecFormNewHoliday2 (void) static void Hld_CreateHoliday (struct Holiday *Hld) { /***** Create a new holiday or no school period *****/ - DB_BuildQuery ("INSERT INTO holidays" - " (InsCod,PlcCod,HldTyp,StartDate,EndDate,Name)" - " VALUES" - " (%ld,%ld,%u,'%04u%02u%02u','%04u%02u%02u','%s')", - Gbl.CurrentIns.Ins.InsCod,Hld->PlcCod,(unsigned) Hld->HldTyp, - Hld->StartDate.Year, - Hld->StartDate.Month, - Hld->StartDate.Day, - Hld->EndDate.Year, - Hld->EndDate.Month, - Hld->EndDate.Day, - Hld->Name); - DB_QueryINSERT_new ("can not create holiday"); + DB_QueryINSERT ("can not create holiday", + "INSERT INTO holidays" + " (InsCod,PlcCod,HldTyp,StartDate,EndDate,Name)" + " VALUES" + " (%ld,%ld,%u,'%04u%02u%02u','%04u%02u%02u','%s')", + Gbl.CurrentIns.Ins.InsCod,Hld->PlcCod,(unsigned) Hld->HldTyp, + Hld->StartDate.Year, + Hld->StartDate.Month, + Hld->StartDate.Day, + Hld->EndDate.Year, + Hld->EndDate.Month, + Hld->EndDate.Day, + Hld->Name); } diff --git a/swad_info.c b/swad_info.c index 9b2699994..dd631700f 100644 --- a/swad_info.c +++ b/swad_info.c @@ -1502,16 +1502,14 @@ void Inf_SetInfoSrcIntoDB (Inf_InfoSrc_t InfoSrc) DB_QueryUPDATE_new ("can not update info source"); } else // Info is not stored in database, so insert it - { - DB_BuildQuery ("INSERT INTO crs_info_src" - " (CrsCod,InfoType,InfoSrc,MustBeRead)" - " VALUES" - " (%ld,'%s','%s','N')", - Gbl.CurrentCrs.Crs.CrsCod, - Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type], - Inf_NamesInDBForInfoSrc[InfoSrc]); - DB_QueryINSERT_new ("can not insert info source"); - } + DB_QueryINSERT ("can not insert info source", + "INSERT INTO crs_info_src" + " (CrsCod,InfoType,InfoSrc,MustBeRead)" + " VALUES" + " (%ld,'%s','%s','N')", + Gbl.CurrentCrs.Crs.CrsCod, + Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type], + Inf_NamesInDBForInfoSrc[InfoSrc]); } diff --git a/swad_link.c b/swad_link.c index 3b53dfb76..c0e3d1179 100644 --- a/swad_link.c +++ b/swad_link.c @@ -846,12 +846,12 @@ static void Lnk_CreateLink (struct Link *Lnk) extern const char *Txt_Created_new_link_X; /***** Create a new link *****/ - DB_BuildQuery ("INSERT INTO links" - " (ShortName,FullName,WWW)" - " VALUES" - " ('%s','%s','%s')", - Lnk->ShrtName,Lnk->FullName,Lnk->WWW); - DB_QueryINSERT_new ("can not create institutional link"); + DB_QueryINSERT ("can not create institutional link", + "INSERT INTO links" + " (ShortName,FullName,WWW)" + " VALUES" + " ('%s','%s','%s')", + Lnk->ShrtName,Lnk->FullName,Lnk->WWW); /***** Write success message *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), diff --git a/swad_mail.c b/swad_mail.c index db1bc535e..52e810676 100644 --- a/swad_mail.c +++ b/swad_mail.c @@ -856,12 +856,12 @@ static void Mai_CreateMailDomain (struct Mail *Mai) extern const char *Txt_Created_new_email_domain_X; /***** Create a new mail *****/ - DB_BuildQuery ("INSERT INTO mail_domains" - " (Domain,Info)" - " VALUES" - " ('%s','%s')", - Mai->Domain,Mai->Info); - DB_QueryINSERT_new ("can not create mail domain"); + DB_QueryINSERT ("can not create mail domain", + "INSERT INTO mail_domains" + " (Domain,Info)" + " VALUES" + " ('%s','%s')", + Mai->Domain,Mai->Info); /***** Write success message *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), diff --git a/swad_mark.c b/swad_mark.c index d576d0dd2..d1269f89e 100644 --- a/swad_mark.c +++ b/swad_mark.c @@ -88,16 +88,16 @@ static bool Mrk_GetUsrMarks (FILE *FileUsrMarks,struct UsrData *UsrDat, void Mrk_AddMarksToDB (long FilCod,struct MarksProperties *Marks) { /***** Add file of marks to the database *****/ - DB_BuildQuery ("INSERT INTO marks_properties" - " (FilCod,%s,%s)" - " VALUES" - " (%ld,%u,%u)", - Mrk_HeadOrFootStr[Brw_HEADER], - Mrk_HeadOrFootStr[Brw_FOOTER], - FilCod, - Marks->Header, - Marks->Footer); - DB_QueryINSERT_new ("can not add properties of marks to database"); + DB_QueryINSERT ("can not add properties of marks to database", + "INSERT INTO marks_properties" + " (FilCod,%s,%s)" + " VALUES" + " (%ld,%u,%u)", + Mrk_HeadOrFootStr[Brw_HEADER], + Mrk_HeadOrFootStr[Brw_FOOTER], + FilCod, + Marks->Header, + Marks->Footer); } /*****************************************************************************/ diff --git a/swad_message.c b/swad_message.c index e040ab7ae..de0aca0c3 100644 --- a/swad_message.c +++ b/swad_message.c @@ -1324,14 +1324,14 @@ static long Msg_InsertNewMsg (const char *Subject,const char *Content, MsgCod = DB_QueryINSERTandReturnCode_new ("can not create message"); /***** Insert message in sent messages *****/ - DB_BuildQuery ("INSERT INTO msg_snt" - " (MsgCod,CrsCod,UsrCod,Expanded,CreatTime)" - " VALUES" - " (%ld,%ld,%ld,'N',NOW())", - MsgCod, - Gbl.CurrentCrs.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod); - DB_QueryINSERT_new ("can not create message"); + DB_QueryINSERT ("can not create message", + "INSERT INTO msg_snt" + " (MsgCod,CrsCod,UsrCod,Expanded,CreatTime)" + " VALUES" + " (%ld,%ld,%ld,'N',NOW())", + MsgCod, + Gbl.CurrentCrs.Crs.CrsCod, + Gbl.Usrs.Me.UsrDat.UsrCod); /***** Increment number of messages sent by me *****/ Prf_IncrementNumMsgSntUsr (Gbl.Usrs.Me.UsrDat.UsrCod); @@ -1393,11 +1393,12 @@ void Msg_DelAllRecAndSntMsgsUsr (long UsrCod) { /***** Move messages from msg_rcv to msg_rcv_deleted *****/ /* Insert messages into msg_rcv_deleted */ - DB_BuildQuery ("INSERT IGNORE INTO msg_rcv_deleted" - " (MsgCod,UsrCod,Notified,Open,Replied)" - " SELECT MsgCod,UsrCod,Notified,Open,Replied FROM msg_rcv WHERE UsrCod=%ld", - UsrCod); - DB_QueryINSERT_new ("can not remove received messages"); + DB_QueryINSERT ("can not remove received messages", + "INSERT IGNORE INTO msg_rcv_deleted" + " (MsgCod,UsrCod,Notified,Open,Replied)" + " SELECT MsgCod,UsrCod,Notified,Open,Replied FROM msg_rcv" + " WHERE UsrCod=%ld", + UsrCod); /* Delete messages from msg_rcv *****/ DB_BuildQuery ("DELETE FROM msg_rcv WHERE UsrCod=%ld",UsrCod); @@ -1405,12 +1406,12 @@ void Msg_DelAllRecAndSntMsgsUsr (long UsrCod) /***** Move message from msg_snt to msg_snt_deleted *****/ /* Insert message into msg_snt_deleted */ - DB_BuildQuery ("INSERT IGNORE INTO msg_snt_deleted" - " (MsgCod,CrsCod,UsrCod,CreatTime)" - " SELECT MsgCod,CrsCod,UsrCod,CreatTime" - " FROM msg_snt WHERE UsrCod=%ld", - UsrCod); - DB_QueryINSERT_new ("can not remove sent messages"); + DB_QueryINSERT ("can not remove sent messages", + "INSERT IGNORE INTO msg_snt_deleted" + " (MsgCod,CrsCod,UsrCod,CreatTime)" + " SELECT MsgCod,CrsCod,UsrCod,CreatTime" + " FROM msg_snt WHERE UsrCod=%ld", + UsrCod); /* Delete message from msg_snt *****/ DB_BuildQuery ("DELETE FROM msg_snt WHERE UsrCod=%ld",UsrCod); @@ -1424,14 +1425,14 @@ void Msg_DelAllRecAndSntMsgsUsr (long UsrCod) static void Msg_InsertReceivedMsgIntoDB (long MsgCod,long UsrCod,bool NotifyByEmail) { /***** Insert message received in the database *****/ - DB_BuildQuery ("INSERT INTO msg_rcv" - " (MsgCod,UsrCod,Notified,Open,Replied,Expanded)" - " VALUES" - " (%ld,%ld,'%c','N','N','N')", - MsgCod,UsrCod, - NotifyByEmail ? 'Y' : - 'N'); - DB_QueryINSERT_new ("can not create received message"); + DB_QueryINSERT ("can not create received message", + "INSERT INTO msg_rcv" + " (MsgCod,UsrCod,Notified,Open,Replied,Expanded)" + " VALUES" + " (%ld,%ld,'%c','N','N','N')", + MsgCod,UsrCod, + NotifyByEmail ? 'Y' : + 'N'); } /*****************************************************************************/ @@ -1455,12 +1456,12 @@ static void Msg_MoveReceivedMsgToDeleted (long MsgCod,long UsrCod) { /***** Move message from msg_rcv to msg_rcv_deleted *****/ /* Insert message into msg_rcv_deleted */ - DB_BuildQuery ("INSERT IGNORE INTO msg_rcv_deleted" - " (MsgCod,UsrCod,Notified,Open,Replied)" - " SELECT MsgCod,UsrCod,Notified,Open,Replied" - " FROM msg_rcv WHERE MsgCod=%ld AND UsrCod=%ld", - MsgCod,UsrCod); - DB_QueryINSERT_new ("can not remove a received message"); + DB_QueryINSERT ("can not remove a received message", + "INSERT IGNORE INTO msg_rcv_deleted" + " (MsgCod,UsrCod,Notified,Open,Replied)" + " SELECT MsgCod,UsrCod,Notified,Open,Replied" + " FROM msg_rcv WHERE MsgCod=%ld AND UsrCod=%ld", + MsgCod,UsrCod); /* Delete message from msg_rcv *****/ DB_BuildQuery ("DELETE FROM msg_rcv WHERE MsgCod=%ld AND UsrCod=%ld", @@ -1484,12 +1485,12 @@ static void Msg_MoveSentMsgToDeleted (long MsgCod) { /***** Move message from msg_snt to msg_snt_deleted *****/ /* Insert message into msg_snt_deleted */ - DB_BuildQuery ("INSERT IGNORE INTO msg_snt_deleted" - " (MsgCod,CrsCod,UsrCod,CreatTime)" - " SELECT MsgCod,CrsCod,UsrCod,CreatTime" - " FROM msg_snt WHERE MsgCod=%ld", - MsgCod); - DB_QueryINSERT_new ("can not remove a sent message"); + DB_QueryINSERT ("can not remove a sent message", + "INSERT IGNORE INTO msg_snt_deleted" + " (MsgCod,CrsCod,UsrCod,CreatTime)" + " SELECT MsgCod,CrsCod,UsrCod,CreatTime" + " FROM msg_snt WHERE MsgCod=%ld", + MsgCod); /* Delete message from msg_snt *****/ DB_BuildQuery ("DELETE FROM msg_snt WHERE MsgCod=%ld",MsgCod); @@ -1508,12 +1509,12 @@ static void Msg_MoveMsgContentToDeleted (long MsgCod) { /***** Move message from msg_content to msg_content_deleted *****/ /* Insert message content into msg_content_deleted */ - DB_BuildQuery ("INSERT IGNORE INTO msg_content_deleted" - " (MsgCod,Subject,Content,ImageName,ImageTitle,ImageURL)" - " SELECT MsgCod,Subject,Content,ImageName,ImageTitle,ImageURL" - " FROM msg_content WHERE MsgCod=%ld", - MsgCod); - DB_QueryINSERT_new ("can not remove the content of a message"); + DB_QueryINSERT ("can not remove the content of a message", + "INSERT IGNORE INTO msg_content_deleted" + " (MsgCod,Subject,Content,ImageName,ImageTitle,ImageURL)" + " SELECT MsgCod,Subject,Content,ImageName,ImageTitle,ImageURL" + " FROM msg_content WHERE MsgCod=%ld", + MsgCod); /* TODO: Messages in msg_content_deleted older than a certain time should be deleted to ensure the protection of personal data */ @@ -1531,12 +1532,12 @@ void Msg_MoveUnusedMsgsContentToDeleted (void) { /***** Move messages from msg_content to msg_content_deleted *****/ /* Insert message content into msg_content_deleted */ - DB_BuildQuery ("INSERT IGNORE INTO msg_content_deleted" - " (MsgCod,Subject,Content)" - " SELECT MsgCod,Subject,Content FROM msg_content" - " WHERE MsgCod NOT IN (SELECT MsgCod FROM msg_snt)" - " AND MsgCod NOT IN (SELECT DISTINCT MsgCod FROM msg_rcv)"); - DB_QueryINSERT_new ("can not remove the content of some messages"); + DB_QueryINSERT ("can not remove the content of some messages", + "INSERT IGNORE INTO msg_content_deleted" + " (MsgCod,Subject,Content)" + " SELECT MsgCod,Subject,Content FROM msg_content" + " WHERE MsgCod NOT IN (SELECT MsgCod FROM msg_snt)" + " AND MsgCod NOT IN (SELECT DISTINCT MsgCod FROM msg_rcv)"); /* Messages in msg_content_deleted older than a certain time should be deleted to ensure the protection of personal data */ diff --git a/swad_notice.c b/swad_notice.c index 003211b09..2c2ccb988 100644 --- a/swad_notice.c +++ b/swad_notice.c @@ -299,13 +299,13 @@ void Not_RemoveNotice (void) /***** Remove notice *****/ /* Copy notice to table of deleted notices */ - DB_BuildQuery ("INSERT IGNORE INTO notices_deleted" - " (NotCod,CrsCod,UsrCod,CreatTime,Content,NumNotif)" - " SELECT NotCod,CrsCod,UsrCod,CreatTime,Content,NumNotif" - " FROM notices" - " WHERE NotCod=%ld AND CrsCod=%ld", - NotCod,Gbl.CurrentCrs.Crs.CrsCod); - DB_QueryINSERT_new ("can not remove notice"); + DB_QueryINSERT ("can not remove notice", + "INSERT IGNORE INTO notices_deleted" + " (NotCod,CrsCod,UsrCod,CreatTime,Content,NumNotif)" + " SELECT NotCod,CrsCod,UsrCod,CreatTime,Content,NumNotif" + " FROM notices" + " WHERE NotCod=%ld AND CrsCod=%ld", + NotCod,Gbl.CurrentCrs.Crs.CrsCod); /* Remove notice */ DB_BuildQuery ("DELETE FROM notices" diff --git a/swad_notification.c b/swad_notification.c index a54b6c779..2a9abd3a0 100644 --- a/swad_notification.c +++ b/swad_notification.c @@ -1494,15 +1494,16 @@ void Ntf_StoreNotifyEventToOneUser (Ntf_NotifyEvent_t NotifyEvent, } /***** Store notify event *****/ - DB_BuildQuery ("INSERT INTO notif" - " (NotifyEvent,ToUsrCod,FromUsrCod," - "InsCod,CtrCod,DegCod,CrsCod,Cod,TimeNotif,Status)" - " VALUES" - " (%u,%ld,%ld," - "%ld,%ld,%ld,%ld,%ld,NOW(),%u)", - (unsigned) NotifyEvent,UsrDat->UsrCod,Gbl.Usrs.Me.UsrDat.UsrCod, - InsCod,CtrCod,DegCod,CrsCod,Cod,(unsigned) Status); - DB_QueryINSERT_new ("can not create new notification event"); + DB_QueryINSERT ("can not create new notification event", + "INSERT INTO notif" + " (NotifyEvent,ToUsrCod,FromUsrCod," + "InsCod,CtrCod,DegCod,CrsCod,Cod,TimeNotif,Status)" + " VALUES" + " (%u,%ld,%ld," + "%ld,%ld,%ld,%ld,%ld,NOW(),%u)", + (unsigned) NotifyEvent, + UsrDat->UsrCod,Gbl.Usrs.Me.UsrDat.UsrCod, + InsCod,CtrCod,DegCod,CrsCod,Cod,(unsigned) Status); } /*****************************************************************************/ diff --git a/swad_photo.c b/swad_photo.c index 3ff7b6b42..2033c6377 100644 --- a/swad_photo.c +++ b/swad_photo.c @@ -1009,12 +1009,12 @@ unsigned Pho_UpdateMyClicksWithoutPhoto (void) else // The user does not exist ==> add him/her { /* Add the user, with one access */ - DB_BuildQuery ("INSERT INTO clicks_without_photo" - " (UsrCod,NumClicks)" - " VALUES" - " (%ld,1)", - Gbl.Usrs.Me.UsrDat.UsrCod); - DB_QueryINSERT_new ("can not create number of clicks without photo"); + DB_QueryINSERT ("can not create number of clicks without photo", + "INSERT INTO clicks_without_photo" + " (UsrCod,NumClicks)" + " VALUES" + " (%ld,1)", + Gbl.Usrs.Me.UsrDat.UsrCod); NumClicks = 1; } diff --git a/swad_place.c b/swad_place.c index fbb47633a..2998a1011 100644 --- a/swad_place.c +++ b/swad_place.c @@ -880,12 +880,12 @@ static void Plc_CreatePlace (struct Place *Plc) extern const char *Txt_Created_new_place_X; /***** Create a new place *****/ - DB_BuildQuery ("INSERT INTO places" - " (InsCod,ShortName,FullName)" - " VALUES" - " (%ld,'%s','%s')", - Gbl.CurrentIns.Ins.InsCod,Plc->ShrtName,Plc->FullName); - DB_QueryINSERT_new ("can not create place"); + DB_QueryINSERT ("can not create place", + "INSERT INTO places" + " (InsCod,ShortName,FullName)" + " VALUES" + " (%ld,'%s','%s')", + Gbl.CurrentIns.Ins.InsCod,Plc->ShrtName,Plc->FullName); /***** Write success message *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), diff --git a/swad_plugin.c b/swad_plugin.c index 66616ccad..cf420fbcf 100644 --- a/swad_plugin.c +++ b/swad_plugin.c @@ -1041,15 +1041,15 @@ static void Plg_CreatePlugin (struct Plugin *Plg) extern const char *Txt_Created_new_plugin_X; /***** Create a new plugin *****/ - DB_BuildQuery ("INSERT INTO plugins" - " (Name,Description,Logo," - "AppKey,URL,IP)" - " VALUES" - " ('%s','%s','%s'," - "'%s','%s','%s')", - Plg->Name,Plg->Description,Plg->Logo, - Plg->AppKey,Plg->URL,Plg->IP); - DB_QueryINSERT_new ("can not create plugin"); + DB_QueryINSERT ("can not create plugin", + "INSERT INTO plugins" + " (Name,Description,Logo," + "AppKey,URL,IP)" + " VALUES" + " ('%s','%s','%s'," + "'%s','%s','%s')", + Plg->Name,Plg->Description,Plg->Logo, + Plg->AppKey,Plg->URL,Plg->IP); /***** Write success message *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), diff --git a/swad_profile.c b/swad_profile.c index 8122001d9..e63f2bbc9 100644 --- a/swad_profile.c +++ b/swad_profile.c @@ -1040,17 +1040,17 @@ static void Prf_CreateUsrFigures (long UsrCod,const struct UsrFigures *UsrFigure (long) UsrFigures->FirstClickTimeUTC); // 0 ==> unknown first click time or user never logged /***** Create user's figures *****/ - DB_BuildQuery ("INSERT INTO usr_figures" - " (UsrCod,FirstClickTime,NumClicks,NumFileViews,NumForPst,NumMsgSnt)" - " VALUES" - " (%ld,%s,%ld,%ld,%ld,%ld)", - UsrCod, - SubQueryFirstClickTime, - UsrFigures->NumClicks, // -1L ==> unknown number of clicks - UsrFigures->NumFileViews, // -1L ==> unknown number of file views - UsrFigures->NumForPst, // -1L ==> unknown number of forum posts - UsrFigures->NumMsgSnt); // -1L ==> unknown number of messages sent - DB_QueryINSERT_new ("can not create user's figures"); + DB_QueryINSERT ("can not create user's figures", + "INSERT INTO usr_figures" + " (UsrCod,FirstClickTime,NumClicks,NumFileViews,NumForPst,NumMsgSnt)" + " VALUES" + " (%ld,%s,%ld,%ld,%ld,%ld)", + UsrCod, + SubQueryFirstClickTime, + UsrFigures->NumClicks, // -1L ==> unknown number of clicks + UsrFigures->NumFileViews, // -1L ==> unknown number of file views + UsrFigures->NumForPst, // -1L ==> unknown number of forum posts + UsrFigures->NumMsgSnt); // -1L ==> unknown number of messages sent } /*****************************************************************************/ @@ -1082,10 +1082,10 @@ void Prf_IncrementNumClicksUsr (long UsrCod) { /***** Increment number of clicks *****/ // If NumClicks < 0 ==> not yet calculated, so do nothing - DB_BuildQuery ("UPDATE IGNORE usr_figures SET NumClicks=NumClicks+1" - " WHERE UsrCod=%ld AND NumClicks>=0", - UsrCod); - DB_QueryINSERT_new ("can not increment user's clicks"); + DB_QueryINSERT ("can not increment user's clicks", + "UPDATE IGNORE usr_figures SET NumClicks=NumClicks+1" + " WHERE UsrCod=%ld AND NumClicks>=0", + UsrCod); } /*****************************************************************************/ @@ -1096,10 +1096,10 @@ void Prf_IncrementNumFileViewsUsr (long UsrCod) { /***** Increment number of file views *****/ // If NumFileViews < 0 ==> not yet calculated, so do nothing - DB_BuildQuery ("UPDATE IGNORE usr_figures SET NumFileViews=NumFileViews+1" - " WHERE UsrCod=%ld AND NumFileViews>=0", - UsrCod); - DB_QueryINSERT_new ("can not increment user's file views"); + DB_QueryINSERT ("can not increment user's file views", + "UPDATE IGNORE usr_figures SET NumFileViews=NumFileViews+1" + " WHERE UsrCod=%ld AND NumFileViews>=0", + UsrCod); } /*****************************************************************************/ @@ -1110,10 +1110,10 @@ void Prf_IncrementNumForPstUsr (long UsrCod) { /***** Increment number of forum posts *****/ // If NumForPst < 0 ==> not yet calculated, so do nothing - DB_BuildQuery ("UPDATE IGNORE usr_figures SET NumForPst=NumForPst+1" - " WHERE UsrCod=%ld AND NumForPst>=0", - UsrCod); - DB_QueryINSERT_new ("can not increment user's forum posts"); + DB_QueryINSERT ("can not increment user's forum posts", + "UPDATE IGNORE usr_figures SET NumForPst=NumForPst+1" + " WHERE UsrCod=%ld AND NumForPst>=0", + UsrCod); } /*****************************************************************************/ @@ -1124,10 +1124,10 @@ void Prf_IncrementNumMsgSntUsr (long UsrCod) { /***** Increment number of messages sent *****/ // If NumMsgSnt < 0 ==> not yet calculated, so do nothing - DB_BuildQuery ("UPDATE IGNORE usr_figures SET NumMsgSnt=NumMsgSnt+1" - " WHERE UsrCod=%ld AND NumMsgSnt>=0", - UsrCod); - DB_QueryINSERT_new ("can not increment user's messages sent"); + DB_QueryINSERT ("can not increment user's messages sent", + "UPDATE IGNORE usr_figures SET NumMsgSnt=NumMsgSnt+1" + " WHERE UsrCod=%ld AND NumMsgSnt>=0", + UsrCod); } /*****************************************************************************/ diff --git a/swad_project.c b/swad_project.c index 7eb465872..99d2d1350 100644 --- a/swad_project.c +++ b/swad_project.c @@ -3339,14 +3339,14 @@ static void Prj_CreateProject (struct Project *Prj) Prj->PrjCod = DB_QueryINSERTandReturnCode_new ("can not create new project"); /***** Insert creator as first tutor *****/ - DB_BuildQuery ("INSERT INTO prj_usr" - " (PrjCod,RoleInProject,UsrCod)" - " VALUES" - " (%ld,%u,%ld)", - Prj->PrjCod, - (unsigned) Prj_ROLE_TUT, - Gbl.Usrs.Me.UsrDat.UsrCod); - DB_QueryINSERT_new ("can not add tutor"); + DB_QueryINSERT ("can not add tutor", + "INSERT INTO prj_usr" + " (PrjCod,RoleInProject,UsrCod)" + " VALUES" + " (%ld,%u,%ld)", + Prj->PrjCod, + (unsigned) Prj_ROLE_TUT, + Gbl.Usrs.Me.UsrDat.UsrCod); /***** Flush cache *****/ Prj_FlushCacheMyRoleInProject (); diff --git a/swad_record.c b/swad_record.c index eb41dbf2c..16578ae46 100644 --- a/swad_record.c +++ b/swad_record.c @@ -577,15 +577,15 @@ void Rec_CreateRecordField (void) extern const char *Txt_Created_new_record_field_X; /***** Create the new field *****/ - DB_BuildQuery ("INSERT INTO crs_record_fields" - " (CrsCod,FieldName,NumLines,Visibility)" - " VALUES" - " (%ld,'%s',%u,%u)", - Gbl.CurrentCrs.Crs.CrsCod, - Gbl.CurrentCrs.Records.Field.Name, - Gbl.CurrentCrs.Records.Field.NumLines, - (unsigned) Gbl.CurrentCrs.Records.Field.Visibility); - DB_QueryINSERT_new ("can not create field of record"); + DB_QueryINSERT ("can not create field of record", + "INSERT INTO crs_record_fields" + " (CrsCod,FieldName,NumLines,Visibility)" + " VALUES" + " (%ld,'%s',%u,%u)", + Gbl.CurrentCrs.Crs.CrsCod, + Gbl.CurrentCrs.Records.Field.Name, + Gbl.CurrentCrs.Records.Field.NumLines, + (unsigned) Gbl.CurrentCrs.Records.Field.Visibility); /***** Write message of success *****/ snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt), @@ -2014,17 +2014,15 @@ void Rec_UpdateCrsRecord (long UsrCod) } } else if (Gbl.CurrentCrs.Records.LstFields.Lst[NumField].Text[0]) - { /***** Insert text field of record course *****/ - DB_BuildQuery ("INSERT INTO crs_records" - " (FieldCod,UsrCod,Txt)" - " VALUES" - " (%ld,%ld,'%s')", - Gbl.CurrentCrs.Records.LstFields.Lst[NumField].FieldCod, - UsrCod, - Gbl.CurrentCrs.Records.LstFields.Lst[NumField].Text); - DB_QueryINSERT_new ("can not create field of record"); - } + DB_QueryINSERT ("can not create field of record", + "INSERT INTO crs_records" + " (FieldCod,UsrCod,Txt)" + " VALUES" + " (%ld,%ld,'%s')", + Gbl.CurrentCrs.Records.LstFields.Lst[NumField].FieldCod, + UsrCod, + Gbl.CurrentCrs.Records.LstFields.Lst[NumField].Text); } } diff --git a/swad_report.c b/swad_report.c index 4df75b072..94e3b0d90 100644 --- a/swad_report.c +++ b/swad_report.c @@ -427,24 +427,24 @@ static void Rep_CreateNewReportFile (struct Rep_Report *Report) static void Rep_CreateNewReportEntryIntoDB (const struct Rep_Report *Report) { /***** Insert a new user's usage report into database *****/ - DB_BuildQuery ("INSERT INTO usr_report" - " (UsrCod,ReportTimeUTC," - "UniqueDirL,UniqueDirR,Filename,Permalink)" - " VALUES" - " (%ld,'%04d-%02d-%02d %02d:%02d:%02d'," - "'%c%c','%s','%s','%s')", - Gbl.Usrs.Me.UsrDat.UsrCod, - 1900 + Report->tm_CurrentTime.tm_year, // year - 1 + Report->tm_CurrentTime.tm_mon, // month - Report->tm_CurrentTime.tm_mday, // day of the month - Report->tm_CurrentTime.tm_hour, // hours - Report->tm_CurrentTime.tm_min, // minutes - Report->tm_CurrentTime.tm_sec, // seconds - Gbl.UniqueNameEncrypted[0], // 2 leftmost chars from a unique 43 chars base64url codified from a unique SHA-256 string - Gbl.UniqueNameEncrypted[1], - &Gbl.UniqueNameEncrypted[2], // 41 rightmost chars from a unique 43 chars base64url codified from a unique SHA-256 string - Report->FilenameReport,Report->Permalink); - DB_QueryINSERT_new ("can not create new user's usage report"); + DB_QueryINSERT ("can not create new user's usage report", + "INSERT INTO usr_report" + " (UsrCod,ReportTimeUTC," + "UniqueDirL,UniqueDirR,Filename,Permalink)" + " VALUES" + " (%ld,'%04d-%02d-%02d %02d:%02d:%02d'," + "'%c%c','%s','%s','%s')", + Gbl.Usrs.Me.UsrDat.UsrCod, + 1900 + Report->tm_CurrentTime.tm_year, // year + 1 + Report->tm_CurrentTime.tm_mon, // month + Report->tm_CurrentTime.tm_mday, // day of the month + Report->tm_CurrentTime.tm_hour, // hours + Report->tm_CurrentTime.tm_min, // minutes + Report->tm_CurrentTime.tm_sec, // seconds + Gbl.UniqueNameEncrypted[0], // 2 leftmost chars from a unique 43 chars base64url codified from a unique SHA-256 string + Gbl.UniqueNameEncrypted[1], + &Gbl.UniqueNameEncrypted[2], // 41 rightmost chars from a unique 43 chars base64url codified from a unique SHA-256 string + Report->FilenameReport,Report->Permalink); } /*****************************************************************************/ diff --git a/swad_session.c b/swad_session.c index 83716dd24..16aa56462 100644 --- a/swad_session.c +++ b/swad_session.c @@ -155,23 +155,23 @@ void Ses_InsertSessionInDB (void) if (Gbl.Search.WhatToSearch == Sch_SEARCH_UNKNOWN) Gbl.Search.WhatToSearch = Sch_WHAT_TO_SEARCH_DEFAULT; - DB_BuildQuery ("INSERT INTO sessions" - " (SessionId,UsrCod,Password,Role," - "CtyCod,InsCod,CtrCod,DegCod,CrsCod,LastTime,LastRefresh,WhatToSearch)" - " VALUES" - " ('%s',%ld,'%s',%u," - "%ld,%ld,%ld,%ld,%ld,NOW(),NOW(),%u)", - Gbl.Session.Id, - Gbl.Usrs.Me.UsrDat.UsrCod, - Gbl.Usrs.Me.UsrDat.Password, - (unsigned) Gbl.Usrs.Me.Role.Logged, - Gbl.CurrentCty.Cty.CtyCod, - Gbl.CurrentIns.Ins.InsCod, - Gbl.CurrentCtr.Ctr.CtrCod, - Gbl.CurrentDeg.Deg.DegCod, - Gbl.CurrentCrs.Crs.CrsCod, - Gbl.Search.WhatToSearch); - DB_QueryINSERT_new ("can not create session"); + DB_QueryINSERT ("can not create session", + "INSERT INTO sessions" + " (SessionId,UsrCod,Password,Role," + "CtyCod,InsCod,CtrCod,DegCod,CrsCod,LastTime,LastRefresh,WhatToSearch)" + " VALUES" + " ('%s',%ld,'%s',%u," + "%ld,%ld,%ld,%ld,%ld,NOW(),NOW(),%u)", + Gbl.Session.Id, + Gbl.Usrs.Me.UsrDat.UsrCod, + Gbl.Usrs.Me.UsrDat.Password, + (unsigned) Gbl.Usrs.Me.Role.Logged, + Gbl.CurrentCty.Cty.CtyCod, + Gbl.CurrentIns.Ins.InsCod, + Gbl.CurrentCtr.Ctr.CtrCod, + Gbl.CurrentDeg.Deg.DegCod, + Gbl.CurrentCrs.Crs.CrsCod, + Gbl.Search.WhatToSearch); } /*****************************************************************************/ @@ -343,16 +343,16 @@ void Ses_InsertHiddenParInDB (Act_Action_t NextAction, if (!Ses_CheckIfHiddenParIsAlreadyInDB (NextAction,ParamName)) { /***** Insert parameter in the database *****/ - DB_BuildQuery ("INSERT INTO hidden_params" - " (SessionId,Action,ParamName,ParamValue)" - " VALUES" - " ('%s',%ld,'%s','%s')", - Gbl.Session.Id, - Act_GetActCod (NextAction), - ParamName, - ParamValue ? ParamValue : - ""); - DB_QueryINSERT_new ("can not create hidden parameter"); + DB_QueryINSERT ("can not create hidden parameter", + "INSERT INTO hidden_params" + " (SessionId,Action,ParamName,ParamValue)" + " VALUES" + " ('%s',%ld,'%s','%s')", + Gbl.Session.Id, + Act_GetActCod (NextAction), + ParamName, + ParamValue ? ParamValue : + ""); Gbl.HiddenParamsInsertedIntoDB = true; } } diff --git a/swad_social.c b/swad_social.c index fe14c6813..34e72733a 100644 --- a/swad_social.c +++ b/swad_social.c @@ -777,16 +777,19 @@ static void Soc_BuildQueryToGetTimeline (char **Query, if (PubCod > 0) { - DB_BuildQuery ("INSERT INTO pub_codes SET PubCod=%ld",PubCod); - DB_QueryINSERT_new ("can not store publishing code"); + DB_QueryINSERT ("can not store publishing code", + "INSERT INTO pub_codes SET PubCod=%ld", + PubCod); RangePubsToGet.Top = PubCod; // Narrow the range for the next iteration /* Get social note code (row[1]) */ NotCod = Str_ConvertStrCodToLongCod (row[1]); - DB_BuildQuery ("INSERT INTO not_codes SET NotCod=%ld",NotCod); - DB_QueryINSERT_new ("can not store note code"); - DB_BuildQuery ("INSERT INTO current_timeline SET NotCod=%ld",NotCod); - DB_QueryINSERT_new ("can not store note code"); + DB_QueryINSERT ("can not store note code", + "INSERT INTO not_codes SET NotCod=%ld", + NotCod); + DB_QueryINSERT ("can not store note code", + "INSERT INTO current_timeline SET NotCod=%ld", + NotCod); } else // Nothing got ==> abort loop break; // Last publishing @@ -2998,18 +3001,18 @@ static long Soc_ReceiveComment (void) Soc_PublishSocialNoteInTimeline (&SocPub); // Set SocPub.PubCod /* Insert comment content in the database */ - DB_BuildQuery ("INSERT INTO social_comments" - " (PubCod,Content,ImageName,ImageTitle,ImageURL)" - " VALUES" - " (%ld,'%s','%s','%s','%s')", - SocPub.PubCod, - Content, - Image.Name, - (Image.Name[0] && // Save image title only if image attached - Image.Title) ? Image.Title : "", - (Image.Name[0] && // Save image URL only if image attached - Image.URL ) ? Image.URL : ""); - DB_QueryINSERT_new ("can not store comment content"); + DB_QueryINSERT ("can not store comment content", + "INSERT INTO social_comments" + " (PubCod,Content,ImageName,ImageTitle,ImageURL)" + " VALUES" + " (%ld,'%s','%s','%s','%s')", + SocPub.PubCod, + Content, + Image.Name, + (Image.Name[0] && // Save image title only if image attached + Image.Title) ? Image.Title : "", + (Image.Name[0] && // Save image URL only if image attached + Image.URL ) ? Image.URL : ""); /***** Store notifications about the new comment *****/ Ntf_StoreNotifyEventsToAllUsrs (Ntf_EVENT_TIMELINE_COMMENT,SocPub.PubCod); @@ -3168,13 +3171,13 @@ static long Soc_FavSocialNote (void) Gbl.Usrs.Me.UsrDat.UsrCod)) // I have not yet favourited the note { /***** Mark as favourite in database *****/ - DB_BuildQuery ("INSERT IGNORE INTO social_notes_fav" - " (NotCod,UsrCod,TimeFav)" - " VALUES" - " (%ld,%ld,NOW())", - SocNot.NotCod, - Gbl.Usrs.Me.UsrDat.UsrCod); - DB_QueryINSERT_new ("can not favourite social note"); + DB_QueryINSERT ("can not favourite social note", + "INSERT IGNORE INTO social_notes_fav" + " (NotCod,UsrCod,TimeFav)" + " VALUES" + " (%ld,%ld,NOW())", + SocNot.NotCod, + Gbl.Usrs.Me.UsrDat.UsrCod); /* Update number of times this social note is favourited */ SocNot.NumFavs = Soc_GetNumTimesANoteHasBeenFav (&SocNot); @@ -3256,13 +3259,13 @@ static long Soc_FavSocialComment (void) Gbl.Usrs.Me.UsrDat.UsrCod)) // I have not yet favourited the comment { /***** Mark as favourite in database *****/ - DB_BuildQuery ("INSERT IGNORE INTO social_comments_fav" - " (PubCod,UsrCod,TimeFav)" - " VALUES" - " (%ld,%ld,NOW())", - SocCom.PubCod, - Gbl.Usrs.Me.UsrDat.UsrCod); - DB_QueryINSERT_new ("can not favourite social comment"); + DB_QueryINSERT ("can not favourite social comment", + "INSERT IGNORE INTO social_comments_fav" + " (PubCod,UsrCod,TimeFav)" + " VALUES" + " (%ld,%ld,NOW())", + SocCom.PubCod, + Gbl.Usrs.Me.UsrDat.UsrCod); /* Update number of times this social comment is favourited */ SocCom.NumFavs = Soc_GetNumTimesACommHasBeenFav (&SocCom); @@ -4756,11 +4759,11 @@ static void Soc_ClearTimelineThisSession (void) static void Soc_AddNotesJustRetrievedToTimelineThisSession (void) { - DB_BuildQuery ("INSERT IGNORE INTO social_timelines" - " (SessionId,NotCod)" - " SELECT DISTINCTROW '%s',NotCod FROM not_codes", - Gbl.Session.Id); - DB_QueryINSERT_new ("can not insert social notes in timeline"); + DB_QueryINSERT ("can not insert social notes in timeline", + "INSERT IGNORE INTO social_timelines" + " (SessionId,NotCod)" + " SELECT DISTINCTROW '%s',NotCod FROM not_codes", + Gbl.Session.Id); } /*****************************************************************************/ diff --git a/swad_statistic.c b/swad_statistic.c index f479d41dc..03286dda8 100644 --- a/swad_statistic.c +++ b/swad_statistic.c @@ -313,24 +313,24 @@ void Sta_LogAccess (const char *Comments) LogCod = DB_QueryINSERTandReturnCode_new ("can not log access (full)"); /* Log access in recent log (log_recent) */ - DB_BuildQuery ("INSERT INTO log_recent " - "(LogCod,ActCod,CtyCod,InsCod,CtrCod,DegCod,CrsCod,UsrCod," - "Role,ClickTime,TimeToGenerate,TimeToSend,IP)" - " VALUES " - "(%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld," - "%u,NOW(),%ld,%ld,'%s')", - LogCod,ActCod, - Gbl.CurrentCty.Cty.CtyCod, - Gbl.CurrentIns.Ins.InsCod, - Gbl.CurrentCtr.Ctr.CtrCod, - Gbl.CurrentDeg.Deg.DegCod, - Gbl.CurrentCrs.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod, - (unsigned) RoleToStore, - Gbl.TimeGenerationInMicroseconds, - Gbl.TimeSendInMicroseconds, - Gbl.IP); - DB_QueryINSERT_new ("can not log access (recent)"); + DB_QueryINSERT ("can not log access (recent)", + "INSERT INTO log_recent " + "(LogCod,ActCod,CtyCod,InsCod,CtrCod,DegCod,CrsCod,UsrCod," + "Role,ClickTime,TimeToGenerate,TimeToSend,IP)" + " VALUES " + "(%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld," + "%u,NOW(),%ld,%ld,'%s')", + LogCod,ActCod, + Gbl.CurrentCty.Cty.CtyCod, + Gbl.CurrentIns.Ins.InsCod, + Gbl.CurrentCtr.Ctr.CtrCod, + Gbl.CurrentDeg.Deg.DegCod, + Gbl.CurrentCrs.Crs.CrsCod, + Gbl.Usrs.Me.UsrDat.UsrCod, + (unsigned) RoleToStore, + Gbl.TimeGenerationInMicroseconds, + Gbl.TimeSendInMicroseconds, + Gbl.IP); if (Comments) { @@ -375,27 +375,22 @@ void Sta_LogAccess (const char *Comments) } if (Gbl.WebService.IsWebService) - { /* Log web service plugin and function */ - DB_BuildQuery ("INSERT INTO log_ws" - " (LogCod,PlgCod,FunCod)" - " VALUES" - " (%ld,%ld,%u)", - LogCod,Gbl.WebService.PlgCod, - (unsigned) Gbl.WebService.Function); - - DB_QueryINSERT_new ("can not log access (comments)"); - } + DB_QueryINSERT ("can not log access (comments)", + "INSERT INTO log_ws" + " (LogCod,PlgCod,FunCod)" + " VALUES" + " (%ld,%ld,%u)", + LogCod,Gbl.WebService.PlgCod, + (unsigned) Gbl.WebService.Function); else if (Gbl.Banners.BanCodClicked > 0) - { /* Log banner clicked */ - DB_BuildQuery ("INSERT INTO log_banners" - " (LogCod,BanCod)" - " VALUES" - " (%ld,%ld)", - LogCod,Gbl.Banners.BanCodClicked); - DB_QueryINSERT_new ("can not log banner clicked"); - } + DB_QueryINSERT ("can not log banner clicked", + "INSERT INTO log_banners" + " (LogCod,BanCod)" + " VALUES" + " (%ld,%ld)", + LogCod,Gbl.Banners.BanCodClicked); /***** Increment my number of clicks *****/ if (Gbl.Usrs.Me.Logged) diff --git a/swad_survey.c b/swad_survey.c index e5992c150..87410371f 100644 --- a/swad_survey.c +++ b/swad_survey.c @@ -2390,15 +2390,13 @@ static void Svy_CreateGrps (long SvyCod) for (NumGrpSel = 0; NumGrpSel < Gbl.CurrentCrs.Grps.LstGrpsSel.NumGrps; NumGrpSel++) - { /* Create group */ - DB_BuildQuery ("INSERT INTO svy_grp" - " (SvyCod,GrpCod)" - " VALUES" - " (%ld,%ld)", - SvyCod,Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods[NumGrpSel]); - DB_QueryINSERT_new ("can not associate a group to a survey"); - } + DB_QueryINSERT ("can not associate a group to a survey", + "INSERT INTO svy_grp" + " (SvyCod,GrpCod)" + " VALUES" + " (%ld,%ld)", + SvyCod,Gbl.CurrentCrs.Grps.LstGrpsSel.GrpCods[NumGrpSel]); } /*****************************************************************************/ @@ -3062,15 +3060,13 @@ void Svy_ReceiveQst (void) else // If this answer does not exist... { if (SvyQst.AnsChoice[NumAns].Text[0]) // Answer is not empty - { /* Create answer into database */ - DB_BuildQuery ("INSERT INTO svy_answers" - " (QstCod,AnsInd,NumUsrs,Answer)" - " VALUES" - " (%ld,%u,0,'%s')", - SvyQst.QstCod,NumAns,SvyQst.AnsChoice[NumAns].Text); - DB_QueryINSERT_new ("can not create answer"); - } + DB_QueryINSERT ("can not create answer", + "INSERT INTO svy_answers" + " (QstCod,AnsInd,NumUsrs,Answer)" + " VALUES" + " (%ld,%u,0,'%s')", + SvyQst.QstCod,NumAns,SvyQst.AnsChoice[NumAns].Text); } /***** List the questions of this survey, including the new one just inserted into the database *****/ @@ -3733,12 +3729,12 @@ static void Svy_IncreaseAnswerInDB (long QstCod,unsigned AnsInd) static void Svy_RegisterIHaveAnsweredSvy (long SvyCod) { - DB_BuildQuery ("INSERT INTO svy_users" - " (SvyCod,UsrCod)" - " VALUES" - " (%ld,%ld)", - SvyCod,Gbl.Usrs.Me.UsrDat.UsrCod); - DB_QueryINSERT_new ("can not register that you have answered the survey"); + DB_QueryINSERT ("can not register that you have answered the survey", + "INSERT INTO svy_users" + " (SvyCod,UsrCod)" + " VALUES" + " (%ld,%ld)", + SvyCod,Gbl.Usrs.Me.UsrDat.UsrCod); } /*****************************************************************************/ diff --git a/swad_test.c b/swad_test.c index 8248088c0..ca61731b1 100644 --- a/swad_test.c +++ b/swad_test.c @@ -6615,12 +6615,12 @@ static void Tst_InsertTagsIntoDB (void) TagCod = Tst_CreateNewTag (Gbl.CurrentCrs.Crs.CrsCod,Gbl.Test.Tags.Txt[NumTag]); /***** Insert tag in tst_question_tags *****/ - DB_BuildQuery ("INSERT INTO tst_question_tags" - " (QstCod,TagCod,TagInd)" - " VALUES" - " (%ld,%ld,%u)", - Gbl.Test.QstCod,TagCod,TagIdx); - DB_QueryINSERT_new ("can not create tag"); + DB_QueryINSERT ("can not create tag", + "INSERT INTO tst_question_tags" + " (QstCod,TagCod,TagInd)" + " VALUES" + " (%ld,%ld,%u)", + Gbl.Test.QstCod,TagCod,TagIdx); TagIdx++; } @@ -6648,41 +6648,39 @@ static void Tst_InsertAnswersIntoDB (void) switch (Gbl.Test.AnswerType) { case Tst_ANS_INT: - DB_BuildQuery ("INSERT INTO tst_answers" - " (QstCod,AnsInd,Answer,Feedback," - "ImageName,ImageTitle,ImageURL,Correct)" - " VALUES" - " (%ld,0,%ld,'','','','','Y')", - Gbl.Test.QstCod, - Gbl.Test.Answer.Integer); - DB_QueryINSERT_new ("can not create answer"); + DB_QueryINSERT ("can not create answer", + "INSERT INTO tst_answers" + " (QstCod,AnsInd,Answer,Feedback," + "ImageName,ImageTitle,ImageURL,Correct)" + " VALUES" + " (%ld,0,%ld,'','','','','Y')", + Gbl.Test.QstCod, + Gbl.Test.Answer.Integer); break; case Tst_ANS_FLOAT: Str_SetDecimalPointToUS (); // To print the floating point as a dot for (i = 0; i < 2; i++) - { - DB_BuildQuery ("INSERT INTO tst_answers" - " (QstCod,AnsInd,Answer,Feedback," - "ImageName,ImageTitle,ImageURL,Correct)" - " VALUES" - " (%ld,%u,'%lg','','','','','Y')", - Gbl.Test.QstCod,i, - Gbl.Test.Answer.FloatingPoint[i]); - DB_QueryINSERT_new ("can not create answer"); - } + DB_QueryINSERT ("can not create answer", + "INSERT INTO tst_answers" + " (QstCod,AnsInd,Answer,Feedback," + "ImageName,ImageTitle,ImageURL,Correct)" + " VALUES" + " (%ld,%u,'%lg','','','','','Y')", + Gbl.Test.QstCod,i, + Gbl.Test.Answer.FloatingPoint[i]); Str_SetDecimalPointToLocal (); // Return to local system break; case Tst_ANS_TRUE_FALSE: - DB_BuildQuery ("INSERT INTO tst_answers" - " (QstCod,AnsInd,Answer,Feedback," - "ImageName,ImageTitle,ImageURL,Correct)" - " VALUES" - " (%ld,0,'%c','','','','','Y')", - Gbl.Test.QstCod, - Gbl.Test.Answer.TF); - DB_QueryINSERT_new ("can not create answer"); + DB_QueryINSERT ("can not create answer", + "INSERT INTO tst_answers" + " (QstCod,AnsInd,Answer,Feedback," + "ImageName,ImageTitle,ImageURL,Correct)" + " VALUES" + " (%ld,0,'%c','','','','','Y')", + Gbl.Test.QstCod, + Gbl.Test.Answer.TF); break; case Tst_ANS_UNIQUE_CHOICE: case Tst_ANS_MULTIPLE_CHOICE: @@ -6692,20 +6690,20 @@ static void Tst_InsertAnswersIntoDB (void) NumOpt++) if (Gbl.Test.Answer.Options[NumOpt].Text[0]) { - DB_BuildQuery ("INSERT INTO tst_answers" - " (QstCod,AnsInd,Answer,Feedback," - "ImageName,ImageTitle,ImageURL,Correct)" - " VALUES" - " (%ld,%u,'%s','%s','%s','%s','%s','%c')", - Gbl.Test.QstCod,NumOpt, - Gbl.Test.Answer.Options[NumOpt].Text, - Gbl.Test.Answer.Options[NumOpt].Feedback ? Gbl.Test.Answer.Options[NumOpt].Feedback : "", - Gbl.Test.Answer.Options[NumOpt].Image.Name, - Gbl.Test.Answer.Options[NumOpt].Image.Title ? Gbl.Test.Answer.Options[NumOpt].Image.Title : "", - Gbl.Test.Answer.Options[NumOpt].Image.URL ? Gbl.Test.Answer.Options[NumOpt].Image.URL : "", - Gbl.Test.Answer.Options[NumOpt].Correct ? 'Y' : - 'N'); - DB_QueryINSERT_new ("can not create answer"); + DB_QueryINSERT ("can not create answer", + "INSERT INTO tst_answers" + " (QstCod,AnsInd,Answer,Feedback," + "ImageName,ImageTitle,ImageURL,Correct)" + " VALUES" + " (%ld,%u,'%s','%s','%s','%s','%s','%c')", + Gbl.Test.QstCod,NumOpt, + Gbl.Test.Answer.Options[NumOpt].Text, + Gbl.Test.Answer.Options[NumOpt].Feedback ? Gbl.Test.Answer.Options[NumOpt].Feedback : "", + Gbl.Test.Answer.Options[NumOpt].Image.Name, + Gbl.Test.Answer.Options[NumOpt].Image.Title ? Gbl.Test.Answer.Options[NumOpt].Image.Title : "", + Gbl.Test.Answer.Options[NumOpt].Image.URL ? Gbl.Test.Answer.Options[NumOpt].Image.URL : "", + Gbl.Test.Answer.Options[NumOpt].Correct ? 'Y' : + 'N'); /* Update image status */ if (Gbl.Test.Answer.Options[NumOpt].Image.Name[0]) @@ -8503,17 +8501,17 @@ static void Tst_StoreOneTestResultQstInDB (long TstCod,long QstCod,unsigned NumQ /***** Insert question and user's answers into database *****/ Str_SetDecimalPointToUS (); // To print the floating point as a dot - DB_BuildQuery ("INSERT INTO tst_exam_questions" - " (TstCod,QstCod,QstInd,Score,Indexes,Answers)" - " VALUES" - " (%ld,%ld,%u,'%lf','%s','%s')", - TstCod,QstCod, - NumQst, // 0, 1, 2, 3... - Score, - Indexes, - Answers); + DB_QueryINSERT ("can not insert a question of a test result", + "INSERT INTO tst_exam_questions" + " (TstCod,QstCod,QstInd,Score,Indexes,Answers)" + " VALUES" + " (%ld,%ld,%u,'%lf','%s','%s')", + TstCod,QstCod, + NumQst, // 0, 1, 2, 3... + Score, + Indexes, + Answers); Str_SetDecimalPointToLocal (); // Return to local system - DB_QueryINSERT_new ("can not insert a question of a test result"); } /*****************************************************************************/ diff --git a/swad_timetable.c b/swad_timetable.c index b71fda1be..d64d23582 100644 --- a/swad_timetable.c +++ b/swad_timetable.c @@ -583,24 +583,22 @@ static void TT_WriteCrsTimeTableIntoDB (long CrsCod) Column++) if (TT_TimeTable[Weekday][Interval].Columns[Column].IntervalType == TT_FIRST_INTERVAL && TT_TimeTable[Weekday][Interval].Columns[Column].DurationIntervals) - { - DB_BuildQuery ("INSERT INTO timetable_crs" - " (CrsCod,GrpCod,Weekday,StartTime,Duration," - "ClassType,Place,GroupName)" - " VALUES" - " (%ld,%ld,%u,'%02u:%02u:00',SEC_TO_TIME(%u)," - "'%s','%s','%s')", - CrsCod, - TT_TimeTable[Weekday][Interval].Columns[Column].GrpCod, - Weekday, - Hour,Min, - TT_TimeTable[Weekday][Interval].Columns[Column].DurationIntervals * - Gbl.TimeTable.Config.SecondsPerInterval, - TT_ClassTypeDB[TT_TimeTable[Weekday][Interval].Columns[Column].ClassType], - TT_TimeTable[Weekday][Interval].Columns[Column].Place, - TT_TimeTable[Weekday][Interval].Columns[Column].Group); - DB_QueryINSERT_new ("can not create course timetable"); - } + DB_QueryINSERT ("can not create course timetable", + "INSERT INTO timetable_crs" + " (CrsCod,GrpCod,Weekday,StartTime,Duration," + "ClassType,Place,GroupName)" + " VALUES" + " (%ld,%ld,%u,'%02u:%02u:00',SEC_TO_TIME(%u)," + "'%s','%s','%s')", + CrsCod, + TT_TimeTable[Weekday][Interval].Columns[Column].GrpCod, + Weekday, + Hour,Min, + TT_TimeTable[Weekday][Interval].Columns[Column].DurationIntervals * + Gbl.TimeTable.Config.SecondsPerInterval, + TT_ClassTypeDB[TT_TimeTable[Weekday][Interval].Columns[Column].ClassType], + TT_TimeTable[Weekday][Interval].Columns[Column].Place, + TT_TimeTable[Weekday][Interval].Columns[Column].Group); } /*****************************************************************************/ @@ -633,19 +631,17 @@ static void TT_WriteTutTimeTableIntoDB (long UsrCod) Column++) if (TT_TimeTable[Weekday][Interval].Columns[Column].IntervalType == TT_FIRST_INTERVAL && TT_TimeTable[Weekday][Interval].Columns[Column].DurationIntervals) - { - DB_BuildQuery ("INSERT INTO timetable_tut" - " (UsrCod,Weekday,StartTime,Duration,Place)" - " VALUES" - " (%ld,%u,'%02u:%02u:00',SEC_TO_TIME(%u),'%s')", - UsrCod, - Weekday, - Hour,Min, - TT_TimeTable[Weekday][Interval].Columns[Column].DurationIntervals * - Gbl.TimeTable.Config.SecondsPerInterval, - TT_TimeTable[Weekday][Interval].Columns[Column].Place); - DB_QueryINSERT_new ("can not create office timetable"); - } + DB_QueryINSERT ("can not create office timetable", + "INSERT INTO timetable_tut" + " (UsrCod,Weekday,StartTime,Duration,Place)" + " VALUES" + " (%ld,%u,'%02u:%02u:00',SEC_TO_TIME(%u),'%s')", + UsrCod, + Weekday, + Hour,Min, + TT_TimeTable[Weekday][Interval].Columns[Column].DurationIntervals * + Gbl.TimeTable.Config.SecondsPerInterval, + TT_TimeTable[Weekday][Interval].Columns[Column].Place); } /*****************************************************************************/ diff --git a/swad_user.c b/swad_user.c index 4f04331f4..7184c125a 100644 --- a/swad_user.c +++ b/swad_user.c @@ -2585,12 +2585,12 @@ static void Usr_InsertMyBirthday (void) DB_QueryDELETE_new ("can not delete old birthdays"); /***** Insert new birthday *****/ - DB_BuildQuery ("INSERT INTO birthdays_today" - " (UsrCod,Today)" - " VALUES" - " (%ld,CURDATE())", - Gbl.Usrs.Me.UsrDat.UsrCod); - DB_QueryINSERT_new ("can not insert birthday"); + DB_QueryINSERT ("can not insert birthday", + "INSERT INTO birthdays_today" + " (UsrCod,Today)" + " VALUES" + " (%ld,CURDATE())", + Gbl.Usrs.Me.UsrDat.UsrCod); } /*****************************************************************************/ @@ -3413,16 +3413,16 @@ void Usr_UpdateMyLastData (void) static void Usr_InsertMyLastData (void) { /***** Insert my last accessed course, tab and time of click in database *****/ - DB_BuildQuery ("INSERT INTO usr_last" - " (UsrCod,WhatToSearch,LastCrs,LastTab,LastTime,LastAccNotif)" - " VALUES" - " (%ld,%u,%ld,%u,NOW(),FROM_UNIXTIME(%ld))", - Gbl.Usrs.Me.UsrDat.UsrCod, - (unsigned) Sch_SEARCH_ALL, - Gbl.CurrentCrs.Crs.CrsCod, - (unsigned) Gbl.Action.Tab, - (long) (time_t) 0); // The user never accessed to notifications - DB_QueryINSERT_new ("can not insert last user's data"); + DB_QueryINSERT ("can not insert last user's data", + "INSERT INTO usr_last" + " (UsrCod,WhatToSearch,LastCrs,LastTab,LastTime,LastAccNotif)" + " VALUES" + " (%ld,%u,%ld,%u,NOW(),FROM_UNIXTIME(%ld))", + Gbl.Usrs.Me.UsrDat.UsrCod, + (unsigned) Sch_SEARCH_ALL, + Gbl.CurrentCrs.Crs.CrsCod, + (unsigned) Gbl.Action.Tab, + (long) (time_t) 0); // The user never accessed to notifications } /*****************************************************************************/ diff --git a/swad_web_service.c b/swad_web_service.c index ad02ff3a5..8de8ec1ad 100644 --- a/swad_web_service.c +++ b/swad_web_service.c @@ -461,12 +461,12 @@ static int Svc_GenerateNewWSKey (long UsrCod, "Generated key already existed in database"); /***** Insert key into database *****/ - DB_BuildQuery ("INSERT INTO ws_keys" - " (WSKey,UsrCod,PlgCod,LastTime)" - " VALUES" - " ('%s',%ld,%ld,NOW())", - WSKey,UsrCod,Gbl.WebService.PlgCod); - DB_QueryINSERT_new ("can not insert new key"); + DB_QueryINSERT ("can not insert new key", + "INSERT INTO ws_keys" + " (WSKey,UsrCod,PlgCod,LastTime)" + " VALUES" + " ('%s',%ld,%ld,NOW())", + WSKey,UsrCod,Gbl.WebService.PlgCod); return SOAP_OK; } @@ -3434,39 +3434,39 @@ static int Svc_SendMessageToUsr (long OriginalMsgCod, NewMsgCod = DB_QueryINSERTandReturnCode_new ("can not create message"); /***** Insert message in sent messages *****/ - DB_BuildQuery ("INSERT INTO msg_snt" - " (MsgCod,CrsCod,UsrCod,Expanded,CreatTime)" - " VALUES" - " (%ld,-1,%ld,'N',NOW())", - NewMsgCod,SenderUsrCod); - DB_QueryINSERT_new ("can not create message"); + DB_QueryINSERT ("can not create message", + "INSERT INTO msg_snt" + " (MsgCod,CrsCod,UsrCod,Expanded,CreatTime)" + " VALUES" + " (%ld,-1,%ld,'N',NOW())", + NewMsgCod,SenderUsrCod); MsgAlreadyInserted = true; } /***** Insert message received in the database *****/ - DB_BuildQuery ("INSERT INTO msg_rcv" - " (MsgCod,UsrCod,Notified,Open,Replied,Expanded)" - " VALUES" - " (%ld,%ld,'%c','N','N','N')", - NewMsgCod,RecipientUsrCod, - NotifyByEmail ? 'Y' : - 'N'); - DB_QueryINSERT_new ("can not create received message"); + DB_QueryINSERT ("can not create received message", + "INSERT INTO msg_rcv" + " (MsgCod,UsrCod,Notified,Open,Replied,Expanded)" + " VALUES" + " (%ld,%ld,'%c','N','N','N')", + NewMsgCod,RecipientUsrCod, + NotifyByEmail ? 'Y' : + 'N'); /***** Create notification for this recipient. If this recipient wants to receive notifications by email, activate the sending of a notification *****/ - DB_BuildQuery ("INSERT INTO notif" - " (NotifyEvent,ToUsrCod,FromUsrCod,InsCod,DegCod,CrsCod,Cod,TimeNotif,Status)" - " VALUES" - " (%u,%ld,%ld,-1,-1,-1,%ld,NOW(),%u)", - (unsigned) Ntf_EVENT_MESSAGE, - RecipientUsrCod, - SenderUsrCod, - NewMsgCod, - (unsigned) (NotifyByEmail ? Ntf_STATUS_BIT_EMAIL : - 0)); - DB_QueryINSERT_new ("can not create new notification event"); + DB_QueryINSERT ("can not create new notification event", + "INSERT INTO notif" + " (NotifyEvent,ToUsrCod,FromUsrCod,InsCod,DegCod,CrsCod,Cod,TimeNotif,Status)" + " VALUES" + " (%u,%ld,%ld,-1,-1,-1,%ld,NOW(),%u)", + (unsigned) Ntf_EVENT_MESSAGE, + RecipientUsrCod, + SenderUsrCod, + NewMsgCod, + (unsigned) (NotifyByEmail ? Ntf_STATUS_BIT_EMAIL : + 0)); /***** If this recipient is the original sender of a message been replied... *****/ if (RecipientUsrCod == ReplyUsrCod) @@ -4111,13 +4111,6 @@ int swad__getTrivialQuestion (struct soap *soap, /***** Loop over recipients' nicknames building query *****/ DegreesStr[0] = '\0'; Ptr = degrees; -/* - if (Gbl.Usrs.Me.UsrDat.UsrCod == 19543) - { - DB_BuildQuery ("INSERT INTO debug (DebugTime,Txt) VALUES (NOW(),'degrees = %s')",degrees); - DB_QueryINSERT_new ("Error inserting in debug table"); - } -*/ while (*Ptr) { /* Find next string in text until comma (leading and trailing spaces are removed) */ @@ -4187,13 +4180,6 @@ int swad__getTrivialQuestion (struct soap *soap, if (NumRows == 1) // Question found { -/* - if (Gbl.Usrs.Me.UsrDat.UsrCod == 19543) - { - DB_BuildQuery ("INSERT INTO debug (DebugTime,Txt) VALUES (NOW(),'Una pregunta devuelta')"); - DB_QueryINSERT_new ("Error inserting in debug table"); - } -*/ /* Get next question */ row = mysql_fetch_row (mysql_res);