diff --git a/swad_changelog.h b/swad_changelog.h index eb8df0b27..ebbe4919d 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.8 (2018-10-31)" +#define Log_PLATFORM_VERSION "SWAD 18.11.9 (2018-10-31)" #define CSS_FILE "swad18.4.css" #define JS_FILE "swad17.17.1.js" /* + Version 18.11.9: Oct 31, 2018 Joining building and performing query into one function. (? lines) Version 18.11.8: Oct 31, 2018 Joining building and performing query into one function. (235810 lines) Version 18.11.7: Oct 31, 2018 Joining building and performing query into one function. (235741 lines) Version 18.11.6: Oct 31, 2018 Joining building and performing query into one function. (235687 lines) diff --git a/swad_indicator.c b/swad_indicator.c index 0d04133b8..1cef4ff04 100644 --- a/swad_indicator.c +++ b/swad_indicator.c @@ -1424,8 +1424,10 @@ int Ind_GetNumIndicatorsCrsFromDB (long CrsCod) int NumIndicatorsFromDB = -1; // -1 means not yet calculated /***** Get number of indicators of a course from database *****/ - DB_BuildQuery ("SELECT NumIndicators FROM courses WHERE CrsCod=%ld",CrsCod); - if (DB_QuerySELECT_new (&mysql_res,"can not get number of indicators")) + if (DB_QuerySELECT (&mysql_res,"can not get number of indicators", + "SELECT NumIndicators FROM courses" + " WHERE CrsCod=%ld", + CrsCod)) { /***** Get row *****/ row = mysql_fetch_row (mysql_res); @@ -1537,21 +1539,21 @@ static unsigned long Ind_GetNumFilesInDocumZonesOfCrsFromDB (long CrsCod) unsigned long NumFiles; /***** Get number of files in document zones of a course from database *****/ - DB_BuildQuery ("SELECT" - " (SELECT COALESCE(SUM(NumFiles),0)" - " FROM file_browser_size" - " WHERE FileBrowser=%u AND Cod=%ld) +" - " (SELECT COALESCE(SUM(file_browser_size.NumFiles),0)" - " FROM crs_grp_types,crs_grp,file_browser_size" - " WHERE crs_grp_types.CrsCod=%ld" - " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" - " AND file_browser_size.FileBrowser=%u" - " AND file_browser_size.Cod=crs_grp.GrpCod)", - (unsigned) Brw_FileBrowserForDB_files[Brw_ADMI_DOC_CRS], - CrsCod, - CrsCod, - (unsigned) Brw_FileBrowserForDB_files[Brw_ADMI_DOC_GRP]); - DB_QuerySELECT_new (&mysql_res,"can not get the number of files"); + DB_QuerySELECT (&mysql_res,"can not get the number of files", + "SELECT" + " (SELECT COALESCE(SUM(NumFiles),0)" + " FROM file_browser_size" + " WHERE FileBrowser=%u AND Cod=%ld) +" + " (SELECT COALESCE(SUM(file_browser_size.NumFiles),0)" + " FROM crs_grp_types,crs_grp,file_browser_size" + " WHERE crs_grp_types.CrsCod=%ld" + " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" + " AND file_browser_size.FileBrowser=%u" + " AND file_browser_size.Cod=crs_grp.GrpCod)", + (unsigned) Brw_FileBrowserForDB_files[Brw_ADMI_DOC_CRS], + CrsCod, + CrsCod, + (unsigned) Brw_FileBrowserForDB_files[Brw_ADMI_DOC_GRP]); /***** Get row *****/ row = mysql_fetch_row (mysql_res); @@ -1578,21 +1580,21 @@ static unsigned long Ind_GetNumFilesInShareZonesOfCrsFromDB (long CrsCod) unsigned long NumFiles; /***** Get number of files in document zones of a course from database *****/ - DB_BuildQuery ("SELECT" - " (SELECT COALESCE(SUM(NumFiles),0)" - " FROM file_browser_size" - " WHERE FileBrowser=%u AND Cod=%ld) +" - " (SELECT COALESCE(SUM(file_browser_size.NumFiles),0)" - " FROM crs_grp_types,crs_grp,file_browser_size" - " WHERE crs_grp_types.CrsCod=%ld" - " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" - " AND file_browser_size.FileBrowser=%u" - " AND file_browser_size.Cod=crs_grp.GrpCod)", - (unsigned) Brw_FileBrowserForDB_files[Brw_ADMI_SHR_CRS], - CrsCod, - CrsCod, - (unsigned) Brw_FileBrowserForDB_files[Brw_ADMI_SHR_GRP]); - DB_QuerySELECT_new (&mysql_res,"can not get the number of files"); + DB_QuerySELECT (&mysql_res,"can not get the number of files", + "SELECT" + " (SELECT COALESCE(SUM(NumFiles),0)" + " FROM file_browser_size" + " WHERE FileBrowser=%u AND Cod=%ld) +" + " (SELECT COALESCE(SUM(file_browser_size.NumFiles),0)" + " FROM crs_grp_types,crs_grp,file_browser_size" + " WHERE crs_grp_types.CrsCod=%ld" + " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" + " AND file_browser_size.FileBrowser=%u" + " AND file_browser_size.Cod=crs_grp.GrpCod)", + (unsigned) Brw_FileBrowserForDB_files[Brw_ADMI_SHR_CRS], + CrsCod, + CrsCod, + (unsigned) Brw_FileBrowserForDB_files[Brw_ADMI_SHR_GRP]); /***** Get row *****/ row = mysql_fetch_row (mysql_res); @@ -1619,12 +1621,12 @@ static unsigned long Ind_GetNumFilesInAssigZonesOfCrsFromDB (long CrsCod) unsigned long NumFiles; /***** Get number of files in document zones of a course from database *****/ - DB_BuildQuery ("SELECT COALESCE(SUM(NumFiles),0)" - " FROM file_browser_size" - " WHERE FileBrowser=%u AND Cod=%ld", - (unsigned) Brw_FileBrowserForDB_files[Brw_ADMI_ASG_USR], - CrsCod); - DB_QuerySELECT_new (&mysql_res,"can not get the number of files"); + DB_QuerySELECT (&mysql_res,"can not get the number of files", + "SELECT COALESCE(SUM(NumFiles),0)" + " FROM file_browser_size" + " WHERE FileBrowser=%u AND Cod=%ld", + (unsigned) Brw_FileBrowserForDB_files[Brw_ADMI_ASG_USR], + CrsCod); /***** Get row *****/ row = mysql_fetch_row (mysql_res); @@ -1651,12 +1653,12 @@ static unsigned long Ind_GetNumFilesInWorksZonesOfCrsFromDB (long CrsCod) unsigned long NumFiles; /***** Get number of files in document zones of a course from database *****/ - DB_BuildQuery ("SELECT COALESCE(SUM(NumFiles),0)" - " FROM file_browser_size" - " WHERE FileBrowser=%u AND Cod=%ld", - (unsigned) Brw_FileBrowserForDB_files[Brw_ADMI_WRK_USR], - CrsCod); - DB_QuerySELECT_new (&mysql_res,"can not get the number of files"); + DB_QuerySELECT (&mysql_res,"can not get the number of files", + "SELECT COALESCE(SUM(NumFiles),0)" + " FROM file_browser_size" + " WHERE FileBrowser=%u AND Cod=%ld", + (unsigned) Brw_FileBrowserForDB_files[Brw_ADMI_WRK_USR], + CrsCod); /***** Get row *****/ row = mysql_fetch_row (mysql_res); diff --git a/swad_info.c b/swad_info.c index 62f8746d5..e08afb923 100644 --- a/swad_info.c +++ b/swad_info.c @@ -539,7 +539,8 @@ bool Inf_GetIfIMustReadAnyCrsInfoInThisCrs (void) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRow,NumRows; + unsigned long NumRow; + unsigned long NumRows; Inf_InfoType_t InfoType; /***** Reset must-be-read to false for all info types *****/ @@ -549,14 +550,16 @@ bool Inf_GetIfIMustReadAnyCrsInfoInThisCrs (void) Gbl.CurrentCrs.Info.MustBeRead[InfoType] = false; /***** Get info types where students must read info *****/ - DB_BuildQuery ("SELECT InfoType FROM crs_info_src" - " WHERE CrsCod=%ld AND MustBeRead='Y'" - " AND InfoType NOT IN" - " (SELECT InfoType FROM crs_info_read" - " WHERE UsrCod=%ld AND CrsCod=%ld)", - Gbl.CurrentCrs.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod,Gbl.CurrentCrs.Crs.CrsCod); - NumRows = DB_QuerySELECT_new (&mysql_res,"can not get if you must read any course info"); + NumRows = DB_QuerySELECT (&mysql_res,"can not get if you must read" + " any course info", + "SELECT InfoType FROM crs_info_src" + " WHERE CrsCod=%ld AND MustBeRead='Y'" + " AND InfoType NOT IN" + " (SELECT InfoType FROM crs_info_read" + " WHERE UsrCod=%ld AND CrsCod=%ld)", + Gbl.CurrentCrs.Crs.CrsCod, + Gbl.Usrs.Me.UsrDat.UsrCod, + Gbl.CurrentCrs.Crs.CrsCod); /***** Set must-be-read to true for each rown in result *****/ for (NumRow = 0; @@ -1523,10 +1526,10 @@ Inf_InfoSrc_t Inf_GetInfoSrcFromDB (long CrsCod,Inf_InfoType_t InfoType) Inf_InfoSrc_t InfoSrc; /***** Get info source for a specific type of info from database *****/ - DB_BuildQuery ("SELECT InfoSrc FROM crs_info_src" - " WHERE CrsCod=%ld AND InfoType='%s'", - CrsCod,Inf_NamesInDBForInfoType[InfoType]); - if (DB_QuerySELECT_new (&mysql_res,"can not get info source")) + if (DB_QuerySELECT (&mysql_res,"can not get info source", + "SELECT InfoSrc FROM crs_info_src" + " WHERE CrsCod=%ld AND InfoType='%s'", + CrsCod,Inf_NamesInDBForInfoType[InfoType])) { /* Get row */ row = mysql_fetch_row (mysql_res); @@ -1560,10 +1563,10 @@ void Inf_GetAndCheckInfoSrcFromDB (long CrsCod, *MustBeRead = false; /***** Get info source for a specific type of info from database *****/ - DB_BuildQuery ("SELECT InfoSrc,MustBeRead FROM crs_info_src" - " WHERE CrsCod=%ld AND InfoType='%s'", - CrsCod,Inf_NamesInDBForInfoType[InfoType]); - NumRows = DB_QuerySELECT_new (&mysql_res,"can not get info source"); + NumRows = DB_QuerySELECT (&mysql_res,"can not get info source", + "SELECT InfoSrc,MustBeRead FROM crs_info_src" + " WHERE CrsCod=%ld AND InfoType='%s'", + CrsCod,Inf_NamesInDBForInfoType[InfoType]); /***** The result of the query must have one row or none *****/ if (NumRows == 1) @@ -1708,10 +1711,10 @@ static void Inf_GetInfoTxtFromDB (long CrsCod,Inf_InfoType_t InfoType, /***** Get info source for a specific type of course information (bibliography, FAQ, links or evaluation) from database *****/ - DB_BuildQuery ("SELECT InfoTxtHTML,InfoTxtMD FROM crs_info_txt" - " WHERE CrsCod=%ld AND InfoType='%s'", - CrsCod,Inf_NamesInDBForInfoType[InfoType]); - NumRows = DB_QuerySELECT_new (&mysql_res,"can not get info text"); + NumRows = DB_QuerySELECT (&mysql_res,"can not get info text", + "SELECT InfoTxtHTML,InfoTxtMD FROM crs_info_txt" + " WHERE CrsCod=%ld AND InfoType='%s'", + CrsCod,Inf_NamesInDBForInfoType[InfoType]); /***** The result of the query must have one row or none *****/ if (NumRows == 1) diff --git a/swad_institution.c b/swad_institution.c index fb6e3de2c..3797ab859 100644 --- a/swad_institution.c +++ b/swad_institution.c @@ -129,29 +129,35 @@ void Ins_SeeInsWithPendingCtrs (void) switch (Gbl.Usrs.Me.Role.Logged) { case Rol_INS_ADM: - DB_BuildQuery ("SELECT centres.InsCod,COUNT(*)" - " FROM centres,ins_admin,institutions" - " WHERE (centres.Status & %u)<>0" - " AND centres.InsCod=ins_admin.InsCod AND ins_admin.UsrCod=%ld" - " AND centres.InsCod=institutions.InsCod" - " GROUP BY centres.InsCod ORDER BY institutions.ShortName", - (unsigned) Ctr_STATUS_BIT_PENDING, - Gbl.Usrs.Me.UsrDat.UsrCod); + NumInss = + (unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions" + " with pending centres", + "SELECT centres.InsCod,COUNT(*)" + " FROM centres,ins_admin,institutions" + " WHERE (centres.Status & %u)<>0" + " AND centres.InsCod=ins_admin.InsCod AND ins_admin.UsrCod=%ld" + " AND centres.InsCod=institutions.InsCod" + " GROUP BY centres.InsCod ORDER BY institutions.ShortName", + (unsigned) Ctr_STATUS_BIT_PENDING, + Gbl.Usrs.Me.UsrDat.UsrCod); break; case Rol_SYS_ADM: - DB_BuildQuery ("SELECT centres.InsCod,COUNT(*)" - " FROM centres,institutions" - " WHERE (centres.Status & %u)<>0" - " AND centres.InsCod=institutions.InsCod" - " GROUP BY centres.InsCod ORDER BY institutions.ShortName", - (unsigned) Ctr_STATUS_BIT_PENDING); + NumInss = + (unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions" + " with pending centres", + "SELECT centres.InsCod,COUNT(*)" + " FROM centres,institutions" + " WHERE (centres.Status & %u)<>0" + " AND centres.InsCod=institutions.InsCod" + " GROUP BY centres.InsCod ORDER BY institutions.ShortName", + (unsigned) Ctr_STATUS_BIT_PENDING); break; default: // Forbidden for other users return; } /***** Get institutions *****/ - if ((NumInss = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get institutions with pending centres"))) + if (NumInss) { /***** Start box and table *****/ Box_StartBoxTable (NULL,Txt_Institutions_with_pending_centres,NULL, @@ -965,7 +971,7 @@ void Ins_GetListInstitutions (long CtyCod,Ins_GetExtraData_t GetExtraData) char OrderBySubQuery[256]; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; + unsigned long NumRows = 0; // Initialized to avoid warning unsigned NumIns; struct Instit *Ins; @@ -973,11 +979,12 @@ void Ins_GetListInstitutions (long CtyCod,Ins_GetExtraData_t GetExtraData) switch (GetExtraData) { case Ins_GET_BASIC_DATA: - DB_BuildQuery ("SELECT InsCod,CtyCod,Status,RequesterUsrCod,ShortName,FullName,WWW" - " FROM institutions" - " WHERE CtyCod=%ld" - " ORDER BY FullName", - CtyCod); + NumRows = DB_QuerySELECT (&mysql_res,"can not get institutions", + "SELECT InsCod,CtyCod,Status,RequesterUsrCod,ShortName,FullName,WWW" + " FROM institutions" + " WHERE CtyCod=%ld" + " ORDER BY FullName", + CtyCod); break; case Ins_GET_EXTRA_DATA: switch (Gbl.Inss.SelectedOrder) @@ -989,26 +996,26 @@ void Ins_GetListInstitutions (long CtyCod,Ins_GetExtraData_t GetExtraData) sprintf (OrderBySubQuery,"NumUsrs DESC,FullName"); break; } - DB_BuildQuery ("(SELECT institutions.InsCod,institutions.CtyCod," - "institutions.Status,institutions.RequesterUsrCod," - "institutions.ShortName,institutions.FullName," - "institutions.WWW,COUNT(*) AS NumUsrs" - " FROM institutions,usr_data" - " WHERE institutions.CtyCod=%ld" - " AND institutions.InsCod=usr_data.InsCod" - " GROUP BY institutions.InsCod)" - " UNION " - "(SELECT InsCod,CtyCod,Status,RequesterUsrCod,ShortName,FullName,WWW,0 AS NumUsrs" - " FROM institutions" - " WHERE CtyCod=%ld" - " AND InsCod NOT IN" - " (SELECT DISTINCT InsCod FROM usr_data))" - " ORDER BY %s", - CtyCod,CtyCod, - OrderBySubQuery); + NumRows = DB_QuerySELECT (&mysql_res,"can not get institutions", + "(SELECT institutions.InsCod,institutions.CtyCod," + "institutions.Status,institutions.RequesterUsrCod," + "institutions.ShortName,institutions.FullName," + "institutions.WWW,COUNT(*) AS NumUsrs" + " FROM institutions,usr_data" + " WHERE institutions.CtyCod=%ld" + " AND institutions.InsCod=usr_data.InsCod" + " GROUP BY institutions.InsCod)" + " UNION " + "(SELECT InsCod,CtyCod,Status,RequesterUsrCod,ShortName,FullName,WWW,0 AS NumUsrs" + " FROM institutions" + " WHERE CtyCod=%ld" + " AND InsCod NOT IN" + " (SELECT DISTINCT InsCod FROM usr_data))" + " ORDER BY %s", + CtyCod,CtyCod, + OrderBySubQuery); break; } - NumRows = DB_QuerySELECT_new (&mysql_res,"can not get institutions"); if (NumRows) // Institutions found... { @@ -1137,12 +1144,10 @@ bool Ins_GetDataOfInstitutionByCod (struct Instit *Ins, if (Ins->InsCod > 0) { /***** Get data of an institution from database *****/ - DB_BuildQuery ("SELECT CtyCod,Status,RequesterUsrCod,ShortName,FullName,WWW" - " FROM institutions WHERE InsCod=%ld", - Ins->InsCod); - - /***** Count number of rows in result *****/ - if (DB_QuerySELECT_new (&mysql_res,"can not get data of an institution")) // Institution found... + if (DB_QuerySELECT (&mysql_res,"can not get data of an institution", + "SELECT CtyCod,Status,RequesterUsrCod,ShortName,FullName,WWW" + " FROM institutions WHERE InsCod=%ld", + Ins->InsCod)) // Institution found... { /* Get row */ row = mysql_fetch_row (mysql_res); @@ -1229,9 +1234,11 @@ void Ins_GetShortNameOfInstitution (struct Instit *Ins) /***** 3. Slow: get short name of institution from database *****/ Gbl.Cache.InstitutionShrtName.InsCod = Ins->InsCod; - DB_BuildQuery ("SELECT ShortName FROM institutions WHERE InsCod=%ld", - Ins->InsCod); - if (DB_QuerySELECT_new (&mysql_res,"can not get the short name of an institution") == 1) + if (DB_QuerySELECT (&mysql_res,"can not get the short name" + " of an institution", + "SELECT ShortName FROM institutions" + " WHERE InsCod=%ld", + Ins->InsCod) == 1) { /* Get the short name of this institution */ row = mysql_fetch_row (mysql_res); @@ -1288,12 +1295,13 @@ static void Ins_GetFullNameAndCtyOfInstitution (struct Instit *Ins, /***** 3. Slow: get full name and country of institution from database *****/ Gbl.Cache.InstitutionFullNameAndCty.InsCod = Ins->InsCod; - DB_BuildQuery ("SELECT institutions.FullName,countries.Name_%s" - " FROM institutions,countries" - " WHERE institutions.InsCod=%ld" - " AND institutions.CtyCod=countries.CtyCod", - Txt_STR_LANG_ID[Gbl.Prefs.Language],Ins->InsCod); - if (DB_QuerySELECT_new (&mysql_res,"can not get the full name of an institution") == 1) + if (DB_QuerySELECT (&mysql_res,"can not get the full name" + " of an institution", + "SELECT institutions.FullName,countries.Name_%s" + " FROM institutions,countries" + " WHERE institutions.InsCod=%ld" + " AND institutions.CtyCod=countries.CtyCod", + Txt_STR_LANG_ID[Gbl.Prefs.Language],Ins->InsCod) == 1) { /* Get row */ row = mysql_fetch_row (mysql_res); @@ -1366,11 +1374,13 @@ void Ins_WriteSelectorOfInstitution (void) if (Gbl.CurrentCty.Cty.CtyCod > 0) { /***** Get institutions of selected country from database *****/ - DB_BuildQuery ("SELECT DISTINCT InsCod,ShortName FROM institutions" - " WHERE CtyCod=%ld" - " ORDER BY ShortName", - Gbl.CurrentCty.Cty.CtyCod); - NumInss = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get institutions"); + NumInss = + (unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions", + "SELECT DISTINCT InsCod,ShortName" + " FROM institutions" + " WHERE CtyCod=%ld" + " ORDER BY ShortName", + Gbl.CurrentCty.Cty.CtyCod); /***** List institutions *****/ for (NumIns = 0; @@ -2510,20 +2520,17 @@ unsigned Ins_GetNumInssWithUsrs (Rol_Role_t Role,const char *SubQuery) /*****************************************************************************/ /*************************** List institutions found *************************/ /*****************************************************************************/ -// Returns number of institutions found -unsigned Ins_ListInssFound (void) +void Ins_ListInssFound (MYSQL_RES **mysql_res,unsigned NumInss) { extern const char *Txt_institution; extern const char *Txt_institutions; - MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned NumInss; unsigned NumIns; struct Instit Ins; - /***** Query database *****/ - if ((NumInss = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get institutions"))) + /***** List the institutions (one row per institution) *****/ + if (NumInss) { /***** Start box and table *****/ /* Number of institutions found */ @@ -2543,7 +2550,7 @@ unsigned Ins_ListInssFound (void) NumIns++) { /* Get next institution */ - row = mysql_fetch_row (mysql_res); + row = mysql_fetch_row (*mysql_res); /* Get institution code (row[0]) */ Ins.InsCod = Str_ConvertStrCodToLongCod (row[0]); @@ -2560,7 +2567,5 @@ unsigned Ins_ListInssFound (void) } /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); - - return NumInss; + DB_FreeMySQLResult (mysql_res); } diff --git a/swad_institution.h b/swad_institution.h index 2596ae565..eaa7f2f7f 100644 --- a/swad_institution.h +++ b/swad_institution.h @@ -139,6 +139,6 @@ unsigned Ins_GetNumInssWithDegs (const char *SubQuery); unsigned Ins_GetNumInssWithCrss (const char *SubQuery); unsigned Ins_GetNumInssWithUsrs (Rol_Role_t Role,const char *SubQuery); -unsigned Ins_ListInssFound (void); +void Ins_ListInssFound (MYSQL_RES **mysql_res,unsigned NumInss); #endif diff --git a/swad_link.c b/swad_link.c index db2a41bca..3b53dfb76 100644 --- a/swad_link.c +++ b/swad_link.c @@ -263,9 +263,9 @@ void Lnk_GetListLinks (void) if (Gbl.DB.DatabaseIsOpen) { /***** Get institutional links from database *****/ - DB_BuildQuery ("SELECT LnkCod,ShortName,FullName,WWW" - " FROM links ORDER BY ShortName"); - NumRows = DB_QuerySELECT_new (&mysql_res,"can not get institutional links"); + NumRows = DB_QuerySELECT (&mysql_res,"can not get institutional links", + "SELECT LnkCod,ShortName,FullName,WWW" + " FROM links ORDER BY ShortName"); if (NumRows) // Places found... { @@ -327,10 +327,11 @@ void Lnk_GetDataOfLinkByCod (struct Link *Lnk) if (Lnk->LnkCod > 0) { /***** Get data of an institutional link from database *****/ - DB_BuildQuery ("SELECT ShortName,FullName,WWW FROM links" - " WHERE LnkCod=%ld", - Lnk->LnkCod); - NumRows = DB_QuerySELECT_new (&mysql_res,"can not get data of an institutional link"); + NumRows = DB_QuerySELECT (&mysql_res,"can not get data" + " of an institutional link", + "SELECT ShortName,FullName,WWW FROM links" + " WHERE LnkCod=%ld", + Lnk->LnkCod); if (NumRows) // Link found... { diff --git a/swad_mail.c b/swad_mail.c index 9fc6284e9..d3b17696c 100644 --- a/swad_mail.c +++ b/swad_mail.c @@ -253,17 +253,25 @@ static void Mai_GetListMailDomainsAllowedForNotif (void) sprintf (OrderBySubQuery,"N DESC,Info,Domain"); break; } - DB_BuildQuery ("(SELECT mail_domains.MaiCod,mail_domains.Domain AS Domain,mail_domains.Info AS Info,T1.N AS N" - " FROM mail_domains,T1" - " WHERE mail_domains.Domain=T1.Domain COLLATE 'latin1_bin')" - " UNION " - "(SELECT MaiCod,Domain,Info,0 AS N" - " FROM mail_domains" - " WHERE Domain NOT IN (SELECT Domain COLLATE 'latin1_bin' FROM T2))" - " ORDER BY %s", // COLLATE necessary to avoid error in comparisons - OrderBySubQuery); + NumRows = DB_QuerySELECT (&mysql_res,"can not get mail domains", + "(SELECT mail_domains.MaiCod," + "mail_domains.Domain AS Domain," + "mail_domains.Info AS Info," + "T1.N AS N" + " FROM mail_domains,T1" + " WHERE mail_domains.Domain=T1.Domain COLLATE 'latin1_bin')" + " UNION " + "(SELECT MaiCod," + "Domain," + "Info," + "0 AS N" + " FROM mail_domains" + " WHERE Domain NOT IN" + " (SELECT Domain COLLATE 'latin1_bin' FROM T2))" + " ORDER BY %s", // COLLATE necessary to avoid error in comparisons + OrderBySubQuery); - if ((NumRows = DB_QuerySELECT_new (&mysql_res,"can not get mail domains"))) // Mail domains found... + if (NumRows) // Mail domains found... { Gbl.Mails.Num = (unsigned) NumRows; @@ -398,9 +406,11 @@ void Mai_GetDataOfMailDomainByCod (struct Mail *Mai) if (Mai->MaiCod > 0) { /***** Get data of a mail domain from database *****/ - DB_BuildQuery ("SELECT Domain,Info FROM mail_domains WHERE MaiCod=%ld", - Mai->MaiCod); - NumRows = DB_QuerySELECT_new (&mysql_res,"can not get data of a mail domain"); + NumRows = DB_QuerySELECT (&mysql_res,"can not get data" + " of a mail domain", + "SELECT Domain,Info FROM mail_domains" + " WHERE MaiCod=%ld", + Mai->MaiCod); if (NumRows) // Mail found... { @@ -1060,10 +1070,11 @@ bool Mai_GetEmailFromUsrCod (struct UsrData *UsrDat) bool Found; /***** Get current (last updated) user's nickname from database *****/ - DB_BuildQuery ("SELECT E_mail,Confirmed FROM usr_emails" - " WHERE UsrCod=%ld ORDER BY CreatTime DESC LIMIT 1", - UsrDat->UsrCod); - NumRows = DB_QuerySELECT_new (&mysql_res,"can not get email address"); + NumRows = DB_QuerySELECT (&mysql_res,"can not get email address", + "SELECT E_mail,Confirmed FROM usr_emails" + " WHERE UsrCod=%ld" + " ORDER BY CreatTime DESC LIMIT 1", + UsrDat->UsrCod); if (NumRows == 0) { @@ -1104,11 +1115,12 @@ long Mai_GetUsrCodFromEmail (const char Email[Cns_MAX_BYTES_EMAIL_ADDRESS + 1]) { /***** Get user's code from database *****/ /* Check if user code from table usr_emails is also in table usr_data */ - DB_BuildQuery ("SELECT usr_emails.UsrCod FROM usr_emails,usr_data" - " WHERE usr_emails.E_mail='%s'" - " AND usr_emails.UsrCod=usr_data.UsrCod", - Email); - NumUsrs = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get user's code"); + NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get user's code", + "SELECT usr_emails.UsrCod" + " FROM usr_emails,usr_data" + " WHERE usr_emails.E_mail='%s'" + " AND usr_emails.UsrCod=usr_data.UsrCod", + Email); if (NumUsrs == 0) /* User not found for this email ==> set user's code to void */ UsrCod = -1L; @@ -1232,11 +1244,14 @@ static void Mai_ShowFormChangeUsrEmail (const struct UsrData *UsrDat,bool ItsMe, Ale_ShowAlert (Ale_WARNING,Txt_Please_confirm_your_email_address); /***** Get my emails *****/ - DB_BuildQuery ("SELECT E_mail,Confirmed FROM usr_emails" - " WHERE UsrCod=%ld" - " ORDER BY CreatTime DESC", - UsrDat->UsrCod); - NumEmails = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get old email addresses of a user"); + NumEmails = (unsigned) DB_QuerySELECT (&mysql_res,"can not get" + " old email addresses" + " of a user", + "SELECT E_mail,Confirmed" + " FROM usr_emails" + " WHERE UsrCod=%ld" + " ORDER BY CreatTime DESC", + UsrDat->UsrCod); /***** Start table *****/ Tbl_StartTableWide (2); @@ -1798,10 +1813,10 @@ void Mai_ConfirmEmail (void) Par_GetParToText ("key",MailKey,Mai_LENGTH_EMAIL_CONFIRM_KEY); /***** Get user's code and email from key *****/ - DB_BuildQuery ("SELECT UsrCod,E_mail FROM pending_emails" - " WHERE MailKey='%s'", - MailKey); - if (DB_QuerySELECT_new (&mysql_res,"can not get user's code and email from key")) + if (DB_QuerySELECT (&mysql_res,"can not get user's code and email from key", + "SELECT UsrCod,E_mail FROM pending_emails" + " WHERE MailKey='%s'", + MailKey)) { row = mysql_fetch_row (mysql_res); @@ -1826,10 +1841,10 @@ void Mai_ConfirmEmail (void) /***** Check user's code and email and get if email is already confirmed *****/ - DB_BuildQuery ("SELECT Confirmed FROM usr_emails" - " WHERE UsrCod=%ld AND E_mail='%s'", - UsrCod,Email); - if (DB_QuerySELECT_new (&mysql_res,"can not get user's code and email")) + if (DB_QuerySELECT (&mysql_res,"can not check if email is confirmed", + "SELECT Confirmed FROM usr_emails" + " WHERE UsrCod=%ld AND E_mail='%s'", + UsrCod,Email)) { Confirmed = (row[0][0] == 'Y'); diff --git a/swad_mark.c b/swad_mark.c index b49e1cb6e..d576d0dd2 100644 --- a/swad_mark.c +++ b/swad_mark.c @@ -195,17 +195,20 @@ static void Mrk_GetNumRowsHeaderAndFooter (struct MarksProperties *Marks) /* There should be a single file in database. If, due to an error, there is more than one file, get the number of rows of the more recent file. */ - DB_BuildQuery ("SELECT marks_properties.%s,marks_properties.%s" - " FROM files,marks_properties" - " WHERE files.FileBrowser=%u AND files.Cod=%ld AND files.Path='%s'" - " AND files.FilCod=marks_properties.FilCod" - " ORDER BY files.FilCod DESC LIMIT 1", // On duplicate entries, get the more recent - Mrk_HeadOrFootStr[Brw_HEADER], - Mrk_HeadOrFootStr[Brw_FOOTER], - (unsigned) Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type], - Cod, - Gbl.FileBrowser.Priv.FullPathInTree); - NumRows = DB_QuerySELECT_new (&mysql_res,"can not get the number of rows in header and footer"); + NumRows = DB_QuerySELECT (&mysql_res,"can not get the number of rows" + " in header and footer", + "SELECT marks_properties.%s,marks_properties.%s" + " FROM files,marks_properties" + " WHERE files.FileBrowser=%u" + " AND files.Cod=%ld" + " AND files.Path='%s'" + " AND files.FilCod=marks_properties.FilCod" + " ORDER BY files.FilCod DESC LIMIT 1", // On duplicate entries, get the more recent + Mrk_HeadOrFootStr[Brw_HEADER], + Mrk_HeadOrFootStr[Brw_FOOTER], + (unsigned) Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type], + Cod, + Gbl.FileBrowser.Priv.FullPathInTree); /***** The result of the query must have only one row *****/ if (NumRows == 1) @@ -764,13 +767,14 @@ void Mrk_GetNotifMyMarks (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1], ID_GetListIDsFromUsrCod (&UsrDat); /***** Get subject of message from database *****/ - DB_BuildQuery ("SELECT files.FileBrowser,files.Cod,files.Path," - "marks_properties.Header,marks_properties.Footer" - " FROM files,marks_properties" - " WHERE files.FilCod=%ld" - " AND files.FilCod=marks_properties.FilCod", - MrkCod); - if (DB_QuerySELECT_new (&mysql_res,"can not get the number of rows in header and footer") == 1) // Result should have a unique row + if (DB_QuerySELECT (&mysql_res,"can not get the number of rows" + " in header and footer", + "SELECT files.FileBrowser,files.Cod,files.Path," + "marks_properties.Header,marks_properties.Footer" + " FROM files,marks_properties" + " WHERE files.FilCod=%ld" + " AND files.FilCod=marks_properties.FilCod", + MrkCod) == 1) // Result should have a unique row { /***** Get data of this file of marks *****/ row = mysql_fetch_row (mysql_res); diff --git a/swad_search.c b/swad_search.c index 478965fce..0c80ec1d4 100644 --- a/swad_search.c +++ b/swad_search.c @@ -659,6 +659,8 @@ static unsigned Sch_SearchInstitutionsInDB (const char *RangeQuery) { extern const char *Txt_STR_LANG_ID[1 + Txt_NUM_LANGUAGES]; char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1]; + MYSQL_RES *mysql_res; + unsigned NumInss; /***** Check scope *****/ if (Gbl.Scope.Current != Sco_SCOPE_CTR && @@ -670,15 +672,17 @@ static unsigned Sch_SearchInstitutionsInDB (const char *RangeQuery) if (Sch_BuildSearchQuery (SearchQuery,"institutions.FullName",NULL,NULL)) { /***** Query database and list institutions found *****/ - DB_BuildQuery ("SELECT institutions.InsCod" - " FROM institutions,countries" - " WHERE %s" - " AND institutions.CtyCod=countries.CtyCod" - "%s" - " ORDER BY institutions.FullName,countries.Name_%s", - SearchQuery,RangeQuery, - Txt_STR_LANG_ID[Gbl.Prefs.Language]); - return Ins_ListInssFound (); + NumInss = (unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions", + "SELECT institutions.InsCod" + " FROM institutions,countries" + " WHERE %s" + " AND institutions.CtyCod=countries.CtyCod" + "%s" + " ORDER BY institutions.FullName,countries.Name_%s", + SearchQuery,RangeQuery, + Txt_STR_LANG_ID[Gbl.Prefs.Language]); + Ins_ListInssFound (&mysql_res,NumInss); + return NumInss; } return 0;