Version 18.11.9

This commit is contained in:
Antonio Cañas Vargas 2018-10-31 16:16:57 +01:00
parent 0ef767800c
commit 2aae0de0f1
9 changed files with 240 additions and 205 deletions

View File

@ -355,10 +355,11 @@ En OpenSWAD:
ps2pdf source.ps destination.pdf 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 CSS_FILE "swad18.4.css"
#define JS_FILE "swad17.17.1.js" #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.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.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) Version 18.11.6: Oct 31, 2018 Joining building and performing query into one function. (235687 lines)

View File

@ -1424,8 +1424,10 @@ int Ind_GetNumIndicatorsCrsFromDB (long CrsCod)
int NumIndicatorsFromDB = -1; // -1 means not yet calculated int NumIndicatorsFromDB = -1; // -1 means not yet calculated
/***** Get number of indicators of a course from database *****/ /***** Get number of indicators of a course from database *****/
DB_BuildQuery ("SELECT NumIndicators FROM courses WHERE CrsCod=%ld",CrsCod); if (DB_QuerySELECT (&mysql_res,"can not get number of indicators",
if (DB_QuerySELECT_new (&mysql_res,"can not get number of indicators")) "SELECT NumIndicators FROM courses"
" WHERE CrsCod=%ld",
CrsCod))
{ {
/***** Get row *****/ /***** Get row *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1537,21 +1539,21 @@ static unsigned long Ind_GetNumFilesInDocumZonesOfCrsFromDB (long CrsCod)
unsigned long NumFiles; unsigned long NumFiles;
/***** Get number of files in document zones of a course from database *****/ /***** Get number of files in document zones of a course from database *****/
DB_BuildQuery ("SELECT" DB_QuerySELECT (&mysql_res,"can not get the number of files",
" (SELECT COALESCE(SUM(NumFiles),0)" "SELECT"
" FROM file_browser_size" " (SELECT COALESCE(SUM(NumFiles),0)"
" WHERE FileBrowser=%u AND Cod=%ld) +" " FROM file_browser_size"
" (SELECT COALESCE(SUM(file_browser_size.NumFiles),0)" " WHERE FileBrowser=%u AND Cod=%ld) +"
" FROM crs_grp_types,crs_grp,file_browser_size" " (SELECT COALESCE(SUM(file_browser_size.NumFiles),0)"
" WHERE crs_grp_types.CrsCod=%ld" " FROM crs_grp_types,crs_grp,file_browser_size"
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" " WHERE crs_grp_types.CrsCod=%ld"
" AND file_browser_size.FileBrowser=%u" " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
" AND file_browser_size.Cod=crs_grp.GrpCod)", " AND file_browser_size.FileBrowser=%u"
(unsigned) Brw_FileBrowserForDB_files[Brw_ADMI_DOC_CRS], " AND file_browser_size.Cod=crs_grp.GrpCod)",
CrsCod, (unsigned) Brw_FileBrowserForDB_files[Brw_ADMI_DOC_CRS],
CrsCod, CrsCod,
(unsigned) Brw_FileBrowserForDB_files[Brw_ADMI_DOC_GRP]); CrsCod,
DB_QuerySELECT_new (&mysql_res,"can not get the number of files"); (unsigned) Brw_FileBrowserForDB_files[Brw_ADMI_DOC_GRP]);
/***** Get row *****/ /***** Get row *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1578,21 +1580,21 @@ static unsigned long Ind_GetNumFilesInShareZonesOfCrsFromDB (long CrsCod)
unsigned long NumFiles; unsigned long NumFiles;
/***** Get number of files in document zones of a course from database *****/ /***** Get number of files in document zones of a course from database *****/
DB_BuildQuery ("SELECT" DB_QuerySELECT (&mysql_res,"can not get the number of files",
" (SELECT COALESCE(SUM(NumFiles),0)" "SELECT"
" FROM file_browser_size" " (SELECT COALESCE(SUM(NumFiles),0)"
" WHERE FileBrowser=%u AND Cod=%ld) +" " FROM file_browser_size"
" (SELECT COALESCE(SUM(file_browser_size.NumFiles),0)" " WHERE FileBrowser=%u AND Cod=%ld) +"
" FROM crs_grp_types,crs_grp,file_browser_size" " (SELECT COALESCE(SUM(file_browser_size.NumFiles),0)"
" WHERE crs_grp_types.CrsCod=%ld" " FROM crs_grp_types,crs_grp,file_browser_size"
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" " WHERE crs_grp_types.CrsCod=%ld"
" AND file_browser_size.FileBrowser=%u" " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
" AND file_browser_size.Cod=crs_grp.GrpCod)", " AND file_browser_size.FileBrowser=%u"
(unsigned) Brw_FileBrowserForDB_files[Brw_ADMI_SHR_CRS], " AND file_browser_size.Cod=crs_grp.GrpCod)",
CrsCod, (unsigned) Brw_FileBrowserForDB_files[Brw_ADMI_SHR_CRS],
CrsCod, CrsCod,
(unsigned) Brw_FileBrowserForDB_files[Brw_ADMI_SHR_GRP]); CrsCod,
DB_QuerySELECT_new (&mysql_res,"can not get the number of files"); (unsigned) Brw_FileBrowserForDB_files[Brw_ADMI_SHR_GRP]);
/***** Get row *****/ /***** Get row *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1619,12 +1621,12 @@ static unsigned long Ind_GetNumFilesInAssigZonesOfCrsFromDB (long CrsCod)
unsigned long NumFiles; unsigned long NumFiles;
/***** Get number of files in document zones of a course from database *****/ /***** Get number of files in document zones of a course from database *****/
DB_BuildQuery ("SELECT COALESCE(SUM(NumFiles),0)" DB_QuerySELECT (&mysql_res,"can not get the number of files",
" FROM file_browser_size" "SELECT COALESCE(SUM(NumFiles),0)"
" WHERE FileBrowser=%u AND Cod=%ld", " FROM file_browser_size"
(unsigned) Brw_FileBrowserForDB_files[Brw_ADMI_ASG_USR], " WHERE FileBrowser=%u AND Cod=%ld",
CrsCod); (unsigned) Brw_FileBrowserForDB_files[Brw_ADMI_ASG_USR],
DB_QuerySELECT_new (&mysql_res,"can not get the number of files"); CrsCod);
/***** Get row *****/ /***** Get row *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1651,12 +1653,12 @@ static unsigned long Ind_GetNumFilesInWorksZonesOfCrsFromDB (long CrsCod)
unsigned long NumFiles; unsigned long NumFiles;
/***** Get number of files in document zones of a course from database *****/ /***** Get number of files in document zones of a course from database *****/
DB_BuildQuery ("SELECT COALESCE(SUM(NumFiles),0)" DB_QuerySELECT (&mysql_res,"can not get the number of files",
" FROM file_browser_size" "SELECT COALESCE(SUM(NumFiles),0)"
" WHERE FileBrowser=%u AND Cod=%ld", " FROM file_browser_size"
(unsigned) Brw_FileBrowserForDB_files[Brw_ADMI_WRK_USR], " WHERE FileBrowser=%u AND Cod=%ld",
CrsCod); (unsigned) Brw_FileBrowserForDB_files[Brw_ADMI_WRK_USR],
DB_QuerySELECT_new (&mysql_res,"can not get the number of files"); CrsCod);
/***** Get row *****/ /***** Get row *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);

View File

@ -539,7 +539,8 @@ bool Inf_GetIfIMustReadAnyCrsInfoInThisCrs (void)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRow,NumRows; unsigned long NumRow;
unsigned long NumRows;
Inf_InfoType_t InfoType; Inf_InfoType_t InfoType;
/***** Reset must-be-read to false for all info types *****/ /***** Reset must-be-read to false for all info types *****/
@ -549,14 +550,16 @@ bool Inf_GetIfIMustReadAnyCrsInfoInThisCrs (void)
Gbl.CurrentCrs.Info.MustBeRead[InfoType] = false; Gbl.CurrentCrs.Info.MustBeRead[InfoType] = false;
/***** Get info types where students must read info *****/ /***** Get info types where students must read info *****/
DB_BuildQuery ("SELECT InfoType FROM crs_info_src" NumRows = DB_QuerySELECT (&mysql_res,"can not get if you must read"
" WHERE CrsCod=%ld AND MustBeRead='Y'" " any course info",
" AND InfoType NOT IN" "SELECT InfoType FROM crs_info_src"
" (SELECT InfoType FROM crs_info_read" " WHERE CrsCod=%ld AND MustBeRead='Y'"
" WHERE UsrCod=%ld AND CrsCod=%ld)", " AND InfoType NOT IN"
Gbl.CurrentCrs.Crs.CrsCod, " (SELECT InfoType FROM crs_info_read"
Gbl.Usrs.Me.UsrDat.UsrCod,Gbl.CurrentCrs.Crs.CrsCod); " WHERE UsrCod=%ld AND CrsCod=%ld)",
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get if you must read any course info"); Gbl.CurrentCrs.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.CurrentCrs.Crs.CrsCod);
/***** Set must-be-read to true for each rown in result *****/ /***** Set must-be-read to true for each rown in result *****/
for (NumRow = 0; for (NumRow = 0;
@ -1523,10 +1526,10 @@ Inf_InfoSrc_t Inf_GetInfoSrcFromDB (long CrsCod,Inf_InfoType_t InfoType)
Inf_InfoSrc_t InfoSrc; Inf_InfoSrc_t InfoSrc;
/***** Get info source for a specific type of info from database *****/ /***** Get info source for a specific type of info from database *****/
DB_BuildQuery ("SELECT InfoSrc FROM crs_info_src" if (DB_QuerySELECT (&mysql_res,"can not get info source",
" WHERE CrsCod=%ld AND InfoType='%s'", "SELECT InfoSrc FROM crs_info_src"
CrsCod,Inf_NamesInDBForInfoType[InfoType]); " WHERE CrsCod=%ld AND InfoType='%s'",
if (DB_QuerySELECT_new (&mysql_res,"can not get info source")) CrsCod,Inf_NamesInDBForInfoType[InfoType]))
{ {
/* Get row */ /* Get row */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1560,10 +1563,10 @@ void Inf_GetAndCheckInfoSrcFromDB (long CrsCod,
*MustBeRead = false; *MustBeRead = false;
/***** Get info source for a specific type of info from database *****/ /***** Get info source for a specific type of info from database *****/
DB_BuildQuery ("SELECT InfoSrc,MustBeRead FROM crs_info_src" NumRows = DB_QuerySELECT (&mysql_res,"can not get info source",
" WHERE CrsCod=%ld AND InfoType='%s'", "SELECT InfoSrc,MustBeRead FROM crs_info_src"
CrsCod,Inf_NamesInDBForInfoType[InfoType]); " WHERE CrsCod=%ld AND InfoType='%s'",
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get info source"); CrsCod,Inf_NamesInDBForInfoType[InfoType]);
/***** The result of the query must have one row or none *****/ /***** The result of the query must have one row or none *****/
if (NumRows == 1) 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 /***** Get info source for a specific type of course information
(bibliography, FAQ, links or evaluation) from database *****/ (bibliography, FAQ, links or evaluation) from database *****/
DB_BuildQuery ("SELECT InfoTxtHTML,InfoTxtMD FROM crs_info_txt" NumRows = DB_QuerySELECT (&mysql_res,"can not get info text",
" WHERE CrsCod=%ld AND InfoType='%s'", "SELECT InfoTxtHTML,InfoTxtMD FROM crs_info_txt"
CrsCod,Inf_NamesInDBForInfoType[InfoType]); " WHERE CrsCod=%ld AND InfoType='%s'",
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get info text"); CrsCod,Inf_NamesInDBForInfoType[InfoType]);
/***** The result of the query must have one row or none *****/ /***** The result of the query must have one row or none *****/
if (NumRows == 1) if (NumRows == 1)

View File

@ -129,29 +129,35 @@ void Ins_SeeInsWithPendingCtrs (void)
switch (Gbl.Usrs.Me.Role.Logged) switch (Gbl.Usrs.Me.Role.Logged)
{ {
case Rol_INS_ADM: case Rol_INS_ADM:
DB_BuildQuery ("SELECT centres.InsCod,COUNT(*)" NumInss =
" FROM centres,ins_admin,institutions" (unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions"
" WHERE (centres.Status & %u)<>0" " with pending centres",
" AND centres.InsCod=ins_admin.InsCod AND ins_admin.UsrCod=%ld" "SELECT centres.InsCod,COUNT(*)"
" AND centres.InsCod=institutions.InsCod" " FROM centres,ins_admin,institutions"
" GROUP BY centres.InsCod ORDER BY institutions.ShortName", " WHERE (centres.Status & %u)<>0"
(unsigned) Ctr_STATUS_BIT_PENDING, " AND centres.InsCod=ins_admin.InsCod AND ins_admin.UsrCod=%ld"
Gbl.Usrs.Me.UsrDat.UsrCod); " AND centres.InsCod=institutions.InsCod"
" GROUP BY centres.InsCod ORDER BY institutions.ShortName",
(unsigned) Ctr_STATUS_BIT_PENDING,
Gbl.Usrs.Me.UsrDat.UsrCod);
break; break;
case Rol_SYS_ADM: case Rol_SYS_ADM:
DB_BuildQuery ("SELECT centres.InsCod,COUNT(*)" NumInss =
" FROM centres,institutions" (unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions"
" WHERE (centres.Status & %u)<>0" " with pending centres",
" AND centres.InsCod=institutions.InsCod" "SELECT centres.InsCod,COUNT(*)"
" GROUP BY centres.InsCod ORDER BY institutions.ShortName", " FROM centres,institutions"
(unsigned) Ctr_STATUS_BIT_PENDING); " WHERE (centres.Status & %u)<>0"
" AND centres.InsCod=institutions.InsCod"
" GROUP BY centres.InsCod ORDER BY institutions.ShortName",
(unsigned) Ctr_STATUS_BIT_PENDING);
break; break;
default: // Forbidden for other users default: // Forbidden for other users
return; return;
} }
/***** Get institutions *****/ /***** Get institutions *****/
if ((NumInss = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get institutions with pending centres"))) if (NumInss)
{ {
/***** Start box and table *****/ /***** Start box and table *****/
Box_StartBoxTable (NULL,Txt_Institutions_with_pending_centres,NULL, 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]; char OrderBySubQuery[256];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows; unsigned long NumRows = 0; // Initialized to avoid warning
unsigned NumIns; unsigned NumIns;
struct Instit *Ins; struct Instit *Ins;
@ -973,11 +979,12 @@ void Ins_GetListInstitutions (long CtyCod,Ins_GetExtraData_t GetExtraData)
switch (GetExtraData) switch (GetExtraData)
{ {
case Ins_GET_BASIC_DATA: case Ins_GET_BASIC_DATA:
DB_BuildQuery ("SELECT InsCod,CtyCod,Status,RequesterUsrCod,ShortName,FullName,WWW" NumRows = DB_QuerySELECT (&mysql_res,"can not get institutions",
" FROM institutions" "SELECT InsCod,CtyCod,Status,RequesterUsrCod,ShortName,FullName,WWW"
" WHERE CtyCod=%ld" " FROM institutions"
" ORDER BY FullName", " WHERE CtyCod=%ld"
CtyCod); " ORDER BY FullName",
CtyCod);
break; break;
case Ins_GET_EXTRA_DATA: case Ins_GET_EXTRA_DATA:
switch (Gbl.Inss.SelectedOrder) switch (Gbl.Inss.SelectedOrder)
@ -989,26 +996,26 @@ void Ins_GetListInstitutions (long CtyCod,Ins_GetExtraData_t GetExtraData)
sprintf (OrderBySubQuery,"NumUsrs DESC,FullName"); sprintf (OrderBySubQuery,"NumUsrs DESC,FullName");
break; break;
} }
DB_BuildQuery ("(SELECT institutions.InsCod,institutions.CtyCod," NumRows = DB_QuerySELECT (&mysql_res,"can not get institutions",
"institutions.Status,institutions.RequesterUsrCod," "(SELECT institutions.InsCod,institutions.CtyCod,"
"institutions.ShortName,institutions.FullName," "institutions.Status,institutions.RequesterUsrCod,"
"institutions.WWW,COUNT(*) AS NumUsrs" "institutions.ShortName,institutions.FullName,"
" FROM institutions,usr_data" "institutions.WWW,COUNT(*) AS NumUsrs"
" WHERE institutions.CtyCod=%ld" " FROM institutions,usr_data"
" AND institutions.InsCod=usr_data.InsCod" " WHERE institutions.CtyCod=%ld"
" GROUP BY institutions.InsCod)" " AND institutions.InsCod=usr_data.InsCod"
" UNION " " GROUP BY institutions.InsCod)"
"(SELECT InsCod,CtyCod,Status,RequesterUsrCod,ShortName,FullName,WWW,0 AS NumUsrs" " UNION "
" FROM institutions" "(SELECT InsCod,CtyCod,Status,RequesterUsrCod,ShortName,FullName,WWW,0 AS NumUsrs"
" WHERE CtyCod=%ld" " FROM institutions"
" AND InsCod NOT IN" " WHERE CtyCod=%ld"
" (SELECT DISTINCT InsCod FROM usr_data))" " AND InsCod NOT IN"
" ORDER BY %s", " (SELECT DISTINCT InsCod FROM usr_data))"
CtyCod,CtyCod, " ORDER BY %s",
OrderBySubQuery); CtyCod,CtyCod,
OrderBySubQuery);
break; break;
} }
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get institutions");
if (NumRows) // Institutions found... if (NumRows) // Institutions found...
{ {
@ -1137,12 +1144,10 @@ bool Ins_GetDataOfInstitutionByCod (struct Instit *Ins,
if (Ins->InsCod > 0) if (Ins->InsCod > 0)
{ {
/***** Get data of an institution from database *****/ /***** Get data of an institution from database *****/
DB_BuildQuery ("SELECT CtyCod,Status,RequesterUsrCod,ShortName,FullName,WWW" if (DB_QuerySELECT (&mysql_res,"can not get data of an institution",
" FROM institutions WHERE InsCod=%ld", "SELECT CtyCod,Status,RequesterUsrCod,ShortName,FullName,WWW"
Ins->InsCod); " FROM institutions WHERE InsCod=%ld",
Ins->InsCod)) // Institution found...
/***** Count number of rows in result *****/
if (DB_QuerySELECT_new (&mysql_res,"can not get data of an institution")) // Institution found...
{ {
/* Get row */ /* Get row */
row = mysql_fetch_row (mysql_res); 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 *****/ /***** 3. Slow: get short name of institution from database *****/
Gbl.Cache.InstitutionShrtName.InsCod = Ins->InsCod; Gbl.Cache.InstitutionShrtName.InsCod = Ins->InsCod;
DB_BuildQuery ("SELECT ShortName FROM institutions WHERE InsCod=%ld", if (DB_QuerySELECT (&mysql_res,"can not get the short name"
Ins->InsCod); " of an institution",
if (DB_QuerySELECT_new (&mysql_res,"can not get the short name of an institution") == 1) "SELECT ShortName FROM institutions"
" WHERE InsCod=%ld",
Ins->InsCod) == 1)
{ {
/* Get the short name of this institution */ /* Get the short name of this institution */
row = mysql_fetch_row (mysql_res); 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 *****/ /***** 3. Slow: get full name and country of institution from database *****/
Gbl.Cache.InstitutionFullNameAndCty.InsCod = Ins->InsCod; Gbl.Cache.InstitutionFullNameAndCty.InsCod = Ins->InsCod;
DB_BuildQuery ("SELECT institutions.FullName,countries.Name_%s" if (DB_QuerySELECT (&mysql_res,"can not get the full name"
" FROM institutions,countries" " of an institution",
" WHERE institutions.InsCod=%ld" "SELECT institutions.FullName,countries.Name_%s"
" AND institutions.CtyCod=countries.CtyCod", " FROM institutions,countries"
Txt_STR_LANG_ID[Gbl.Prefs.Language],Ins->InsCod); " WHERE institutions.InsCod=%ld"
if (DB_QuerySELECT_new (&mysql_res,"can not get the full name of an institution") == 1) " AND institutions.CtyCod=countries.CtyCod",
Txt_STR_LANG_ID[Gbl.Prefs.Language],Ins->InsCod) == 1)
{ {
/* Get row */ /* Get row */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1366,11 +1374,13 @@ void Ins_WriteSelectorOfInstitution (void)
if (Gbl.CurrentCty.Cty.CtyCod > 0) if (Gbl.CurrentCty.Cty.CtyCod > 0)
{ {
/***** Get institutions of selected country from database *****/ /***** Get institutions of selected country from database *****/
DB_BuildQuery ("SELECT DISTINCT InsCod,ShortName FROM institutions" NumInss =
" WHERE CtyCod=%ld" (unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions",
" ORDER BY ShortName", "SELECT DISTINCT InsCod,ShortName"
Gbl.CurrentCty.Cty.CtyCod); " FROM institutions"
NumInss = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get institutions"); " WHERE CtyCod=%ld"
" ORDER BY ShortName",
Gbl.CurrentCty.Cty.CtyCod);
/***** List institutions *****/ /***** List institutions *****/
for (NumIns = 0; for (NumIns = 0;
@ -2510,20 +2520,17 @@ unsigned Ins_GetNumInssWithUsrs (Rol_Role_t Role,const char *SubQuery)
/*****************************************************************************/ /*****************************************************************************/
/*************************** List institutions found *************************/ /*************************** 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_institution;
extern const char *Txt_institutions; extern const char *Txt_institutions;
MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned NumInss;
unsigned NumIns; unsigned NumIns;
struct Instit Ins; struct Instit Ins;
/***** Query database *****/ /***** List the institutions (one row per institution) *****/
if ((NumInss = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get institutions"))) if (NumInss)
{ {
/***** Start box and table *****/ /***** Start box and table *****/
/* Number of institutions found */ /* Number of institutions found */
@ -2543,7 +2550,7 @@ unsigned Ins_ListInssFound (void)
NumIns++) NumIns++)
{ {
/* Get next institution */ /* Get next institution */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (*mysql_res);
/* Get institution code (row[0]) */ /* Get institution code (row[0]) */
Ins.InsCod = Str_ConvertStrCodToLongCod (row[0]); Ins.InsCod = Str_ConvertStrCodToLongCod (row[0]);
@ -2560,7 +2567,5 @@ unsigned Ins_ListInssFound (void)
} }
/***** Free structure that stores the query result *****/ /***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res); DB_FreeMySQLResult (mysql_res);
return NumInss;
} }

View File

@ -139,6 +139,6 @@ unsigned Ins_GetNumInssWithDegs (const char *SubQuery);
unsigned Ins_GetNumInssWithCrss (const char *SubQuery); unsigned Ins_GetNumInssWithCrss (const char *SubQuery);
unsigned Ins_GetNumInssWithUsrs (Rol_Role_t Role,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 #endif

View File

@ -263,9 +263,9 @@ void Lnk_GetListLinks (void)
if (Gbl.DB.DatabaseIsOpen) if (Gbl.DB.DatabaseIsOpen)
{ {
/***** Get institutional links from database *****/ /***** Get institutional links from database *****/
DB_BuildQuery ("SELECT LnkCod,ShortName,FullName,WWW" NumRows = DB_QuerySELECT (&mysql_res,"can not get institutional links",
" FROM links ORDER BY ShortName"); "SELECT LnkCod,ShortName,FullName,WWW"
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get institutional links"); " FROM links ORDER BY ShortName");
if (NumRows) // Places found... if (NumRows) // Places found...
{ {
@ -327,10 +327,11 @@ void Lnk_GetDataOfLinkByCod (struct Link *Lnk)
if (Lnk->LnkCod > 0) if (Lnk->LnkCod > 0)
{ {
/***** Get data of an institutional link from database *****/ /***** Get data of an institutional link from database *****/
DB_BuildQuery ("SELECT ShortName,FullName,WWW FROM links" NumRows = DB_QuerySELECT (&mysql_res,"can not get data"
" WHERE LnkCod=%ld", " of an institutional link",
Lnk->LnkCod); "SELECT ShortName,FullName,WWW FROM links"
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get data of an institutional link"); " WHERE LnkCod=%ld",
Lnk->LnkCod);
if (NumRows) // Link found... if (NumRows) // Link found...
{ {

View File

@ -253,17 +253,25 @@ static void Mai_GetListMailDomainsAllowedForNotif (void)
sprintf (OrderBySubQuery,"N DESC,Info,Domain"); sprintf (OrderBySubQuery,"N DESC,Info,Domain");
break; break;
} }
DB_BuildQuery ("(SELECT mail_domains.MaiCod,mail_domains.Domain AS Domain,mail_domains.Info AS Info,T1.N AS N" NumRows = DB_QuerySELECT (&mysql_res,"can not get mail domains",
" FROM mail_domains,T1" "(SELECT mail_domains.MaiCod,"
" WHERE mail_domains.Domain=T1.Domain COLLATE 'latin1_bin')" "mail_domains.Domain AS Domain,"
" UNION " "mail_domains.Info AS Info,"
"(SELECT MaiCod,Domain,Info,0 AS N" "T1.N AS N"
" FROM mail_domains" " FROM mail_domains,T1"
" WHERE Domain NOT IN (SELECT Domain COLLATE 'latin1_bin' FROM T2))" " WHERE mail_domains.Domain=T1.Domain COLLATE 'latin1_bin')"
" ORDER BY %s", // COLLATE necessary to avoid error in comparisons " UNION "
OrderBySubQuery); "(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; Gbl.Mails.Num = (unsigned) NumRows;
@ -398,9 +406,11 @@ void Mai_GetDataOfMailDomainByCod (struct Mail *Mai)
if (Mai->MaiCod > 0) if (Mai->MaiCod > 0)
{ {
/***** Get data of a mail domain from database *****/ /***** Get data of a mail domain from database *****/
DB_BuildQuery ("SELECT Domain,Info FROM mail_domains WHERE MaiCod=%ld", NumRows = DB_QuerySELECT (&mysql_res,"can not get data"
Mai->MaiCod); " of a mail domain",
NumRows = DB_QuerySELECT_new (&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... if (NumRows) // Mail found...
{ {
@ -1060,10 +1070,11 @@ bool Mai_GetEmailFromUsrCod (struct UsrData *UsrDat)
bool Found; bool Found;
/***** Get current (last updated) user's nickname from database *****/ /***** Get current (last updated) user's nickname from database *****/
DB_BuildQuery ("SELECT E_mail,Confirmed FROM usr_emails" NumRows = DB_QuerySELECT (&mysql_res,"can not get email address",
" WHERE UsrCod=%ld ORDER BY CreatTime DESC LIMIT 1", "SELECT E_mail,Confirmed FROM usr_emails"
UsrDat->UsrCod); " WHERE UsrCod=%ld"
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get email address"); " ORDER BY CreatTime DESC LIMIT 1",
UsrDat->UsrCod);
if (NumRows == 0) 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 *****/ /***** Get user's code from database *****/
/* Check if user code from table usr_emails is also in table usr_data */ /* 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" NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get user's code",
" WHERE usr_emails.E_mail='%s'" "SELECT usr_emails.UsrCod"
" AND usr_emails.UsrCod=usr_data.UsrCod", " FROM usr_emails,usr_data"
Email); " WHERE usr_emails.E_mail='%s'"
NumUsrs = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get user's code"); " AND usr_emails.UsrCod=usr_data.UsrCod",
Email);
if (NumUsrs == 0) if (NumUsrs == 0)
/* User not found for this email ==> set user's code to void */ /* User not found for this email ==> set user's code to void */
UsrCod = -1L; 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); Ale_ShowAlert (Ale_WARNING,Txt_Please_confirm_your_email_address);
/***** Get my emails *****/ /***** Get my emails *****/
DB_BuildQuery ("SELECT E_mail,Confirmed FROM usr_emails" NumEmails = (unsigned) DB_QuerySELECT (&mysql_res,"can not get"
" WHERE UsrCod=%ld" " old email addresses"
" ORDER BY CreatTime DESC", " of a user",
UsrDat->UsrCod); "SELECT E_mail,Confirmed"
NumEmails = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get old email addresses of a user"); " FROM usr_emails"
" WHERE UsrCod=%ld"
" ORDER BY CreatTime DESC",
UsrDat->UsrCod);
/***** Start table *****/ /***** Start table *****/
Tbl_StartTableWide (2); Tbl_StartTableWide (2);
@ -1798,10 +1813,10 @@ void Mai_ConfirmEmail (void)
Par_GetParToText ("key",MailKey,Mai_LENGTH_EMAIL_CONFIRM_KEY); Par_GetParToText ("key",MailKey,Mai_LENGTH_EMAIL_CONFIRM_KEY);
/***** Get user's code and email from key *****/ /***** Get user's code and email from key *****/
DB_BuildQuery ("SELECT UsrCod,E_mail FROM pending_emails" if (DB_QuerySELECT (&mysql_res,"can not get user's code and email from key",
" WHERE MailKey='%s'", "SELECT UsrCod,E_mail FROM pending_emails"
MailKey); " WHERE MailKey='%s'",
if (DB_QuerySELECT_new (&mysql_res,"can not get user's code and email from key")) MailKey))
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1826,10 +1841,10 @@ void Mai_ConfirmEmail (void)
/***** Check user's code and email /***** Check user's code and email
and get if email is already confirmed *****/ and get if email is already confirmed *****/
DB_BuildQuery ("SELECT Confirmed FROM usr_emails" if (DB_QuerySELECT (&mysql_res,"can not check if email is confirmed",
" WHERE UsrCod=%ld AND E_mail='%s'", "SELECT Confirmed FROM usr_emails"
UsrCod,Email); " WHERE UsrCod=%ld AND E_mail='%s'",
if (DB_QuerySELECT_new (&mysql_res,"can not get user's code and email")) UsrCod,Email))
{ {
Confirmed = (row[0][0] == 'Y'); Confirmed = (row[0][0] == 'Y');

View File

@ -195,17 +195,20 @@ static void Mrk_GetNumRowsHeaderAndFooter (struct MarksProperties *Marks)
/* There should be a single file in database. /* There should be a single file in database.
If, due to an error, there is more than one file, If, due to an error, there is more than one file,
get the number of rows of the more recent file. */ get the number of rows of the more recent file. */
DB_BuildQuery ("SELECT marks_properties.%s,marks_properties.%s" NumRows = DB_QuerySELECT (&mysql_res,"can not get the number of rows"
" FROM files,marks_properties" " in header and footer",
" WHERE files.FileBrowser=%u AND files.Cod=%ld AND files.Path='%s'" "SELECT marks_properties.%s,marks_properties.%s"
" AND files.FilCod=marks_properties.FilCod" " FROM files,marks_properties"
" ORDER BY files.FilCod DESC LIMIT 1", // On duplicate entries, get the more recent " WHERE files.FileBrowser=%u"
Mrk_HeadOrFootStr[Brw_HEADER], " AND files.Cod=%ld"
Mrk_HeadOrFootStr[Brw_FOOTER], " AND files.Path='%s'"
(unsigned) Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type], " AND files.FilCod=marks_properties.FilCod"
Cod, " ORDER BY files.FilCod DESC LIMIT 1", // On duplicate entries, get the more recent
Gbl.FileBrowser.Priv.FullPathInTree); Mrk_HeadOrFootStr[Brw_HEADER],
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get the number of rows in header and footer"); 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 *****/ /***** The result of the query must have only one row *****/
if (NumRows == 1) if (NumRows == 1)
@ -764,13 +767,14 @@ void Mrk_GetNotifMyMarks (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
ID_GetListIDsFromUsrCod (&UsrDat); ID_GetListIDsFromUsrCod (&UsrDat);
/***** Get subject of message from database *****/ /***** Get subject of message from database *****/
DB_BuildQuery ("SELECT files.FileBrowser,files.Cod,files.Path," if (DB_QuerySELECT (&mysql_res,"can not get the number of rows"
"marks_properties.Header,marks_properties.Footer" " in header and footer",
" FROM files,marks_properties" "SELECT files.FileBrowser,files.Cod,files.Path,"
" WHERE files.FilCod=%ld" "marks_properties.Header,marks_properties.Footer"
" AND files.FilCod=marks_properties.FilCod", " FROM files,marks_properties"
MrkCod); " WHERE files.FilCod=%ld"
if (DB_QuerySELECT_new (&mysql_res,"can not get the number of rows in header and footer") == 1) // Result should have a unique row " AND files.FilCod=marks_properties.FilCod",
MrkCod) == 1) // Result should have a unique row
{ {
/***** Get data of this file of marks *****/ /***** Get data of this file of marks *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);

View File

@ -659,6 +659,8 @@ static unsigned Sch_SearchInstitutionsInDB (const char *RangeQuery)
{ {
extern const char *Txt_STR_LANG_ID[1 + Txt_NUM_LANGUAGES]; extern const char *Txt_STR_LANG_ID[1 + Txt_NUM_LANGUAGES];
char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1]; char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1];
MYSQL_RES *mysql_res;
unsigned NumInss;
/***** Check scope *****/ /***** Check scope *****/
if (Gbl.Scope.Current != Sco_SCOPE_CTR && 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)) if (Sch_BuildSearchQuery (SearchQuery,"institutions.FullName",NULL,NULL))
{ {
/***** Query database and list institutions found *****/ /***** Query database and list institutions found *****/
DB_BuildQuery ("SELECT institutions.InsCod" NumInss = (unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions",
" FROM institutions,countries" "SELECT institutions.InsCod"
" WHERE %s" " FROM institutions,countries"
" AND institutions.CtyCod=countries.CtyCod" " WHERE %s"
"%s" " AND institutions.CtyCod=countries.CtyCod"
" ORDER BY institutions.FullName,countries.Name_%s", "%s"
SearchQuery,RangeQuery, " ORDER BY institutions.FullName,countries.Name_%s",
Txt_STR_LANG_ID[Gbl.Prefs.Language]); SearchQuery,RangeQuery,
return Ins_ListInssFound (); Txt_STR_LANG_ID[Gbl.Prefs.Language]);
Ins_ListInssFound (&mysql_res,NumInss);
return NumInss;
} }
return 0; return 0;