Version 18.11.27

This commit is contained in:
Antonio Cañas Vargas 2018-11-03 20:52:00 +01:00
parent 408fc80f28
commit 066fac7750
22 changed files with 1670 additions and 1214 deletions

View File

@ -842,10 +842,10 @@ static void ID_RemoveUsrID (const struct UsrData *UsrDat,bool ItsMe)
static bool ID_CheckIfConfirmed (long UsrCod,const char *UsrID) static bool ID_CheckIfConfirmed (long UsrCod,const char *UsrID)
{ {
/***** Get if ID is confirmed from database *****/ /***** Get if ID is confirmed from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM usr_IDs" return (DB_QueryCOUNT ("can not check if ID is confirmed",
" WHERE UsrCod=%ld AND UsrID='%s' AND Confirmed='Y'", "SELECT COUNT(*) FROM usr_IDs"
UsrCod,UsrID); " WHERE UsrCod=%ld AND UsrID='%s' AND Confirmed='Y'",
return (DB_QueryCOUNT_new ("can not check if ID is confirmed") != 0); UsrCod,UsrID) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -355,10 +355,12 @@ En OpenSWAD:
ps2pdf source.ps destination.pdf ps2pdf source.ps destination.pdf
*/ */
#define Log_PLATFORM_VERSION "SWAD 18.11.26 (2018-11-03)" #define Log_PLATFORM_VERSION "SWAD 18.11.27 (2018-11-03)"
#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.27: Nov 03, 2018 Joining building and performing query into one function.
Some queries that used UNIX_TIMESTAMP(...)>0 optimized using ...>FROM_UNIXTIME(0). (237185 lines)
Version 18.11.26: Nov 03, 2018 Joining building and performing query into one function. (236738 lines) Version 18.11.26: Nov 03, 2018 Joining building and performing query into one function. (236738 lines)
Version 18.11.25: Nov 03, 2018 Joining building and performing query into one function. (236705 lines) Version 18.11.25: Nov 03, 2018 Joining building and performing query into one function. (236705 lines)
Version 18.11.24: Nov 03, 2018 Joining building and performing query into one function. (236636 lines) Version 18.11.24: Nov 03, 2018 Joining building and performing query into one function. (236636 lines)

View File

@ -148,7 +148,7 @@ void Dup_ListDuplicateUsrs (void)
/***** Make query *****/ /***** Make query *****/
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get possibly" NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get possibly"
" duplicate users", " duplicate users",
"SELECT UsrCod,COUNT(*) AS N,MIN(UNIX_TIMESTAMP(InformTime)) AS T" "SELECT UsrCod,COUNT(*) AS N,UNIX_TIMESTAMP(MIN(InformTime)) AS T"
" FROM usr_duplicated" " FROM usr_duplicated"
" GROUP BY UsrCod" " GROUP BY UsrCod"
" ORDER BY N DESC,T DESC"); " ORDER BY N DESC,T DESC");

View File

@ -2382,10 +2382,12 @@ static unsigned For_GetNumOfUnreadPostsInThr (long ThrCod,unsigned NumPostsInThr
static unsigned For_GetNumOfPostsInThrNewerThan (long ThrCod,const char *Time) static unsigned For_GetNumOfPostsInThrNewerThan (long ThrCod,const char *Time)
{ {
/***** Get the number of posts in thread with a modify time > a specified time from database *****/ /***** Get the number of posts in thread with a modify time > a specified time from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM forum_post" return
" WHERE ThrCod=%ld AND ModifTime>'%s'", (unsigned) DB_QueryCOUNT ("can not check if there are new posts"
ThrCod,Time); " in a thread of a forum",
return (unsigned) DB_QueryCOUNT_new ("can not check if there are new posts in a thread of a forum"); "SELECT COUNT(*) FROM forum_post"
" WHERE ThrCod=%ld AND ModifTime>'%s'",
ThrCod,Time);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2862,6 +2864,8 @@ unsigned For_GetNumTotalForumsOfType (For_ForumType_t ForumType,
unsigned For_GetNumTotalThrsInForumsOfType (For_ForumType_t ForumType, unsigned For_GetNumTotalThrsInForumsOfType (For_ForumType_t ForumType,
long CtyCod,long InsCod,long CtrCod,long DegCod,long CrsCod) long CtyCod,long InsCod,long CtrCod,long DegCod,long CrsCod)
{ {
unsigned NumThrs;
/***** Get total number of threads in forums of this type from database *****/ /***** Get total number of threads in forums of this type from database *****/
switch (ForumType) switch (ForumType)
{ {
@ -2870,151 +2874,210 @@ unsigned For_GetNumTotalThrsInForumsOfType (For_ForumType_t ForumType,
case For_FORUM__SWAD__USRS: case For_FORUM__SWAD__USRS:
case For_FORUM__SWAD__TCHS: case For_FORUM__SWAD__TCHS:
// Total number of threads in forums of this type // Total number of threads in forums of this type
DB_BuildQuery ("SELECT COUNT(*)" NumThrs =
" FROM forum_thread" (unsigned) DB_QueryCOUNT ("can not get the number of threads"
" WHERE ForumType=%u", " in forums of a type",
(unsigned) ForumType); "SELECT COUNT(*)"
" FROM forum_thread"
" WHERE ForumType=%u",
(unsigned) ForumType);
break; break;
case For_FORUM_INSTIT_USRS: case For_FORUM_INSTIT_USRS:
case For_FORUM_INSTIT_TCHS: case For_FORUM_INSTIT_TCHS:
if (InsCod > 0) // InsCod > 0 ==> Number of threads in institution forums for an institution if (InsCod > 0) // InsCod > 0 ==> Number of threads in institution forums for an institution
DB_BuildQuery ("SELECT COUNT(*)" NumThrs =
" FROM forum_thread" (unsigned) DB_QueryCOUNT ("can not get the number of threads"
" WHERE ForumType=%u" " in forums of a type",
" AND Location=%ld", "SELECT COUNT(*)"
(unsigned) ForumType,InsCod); " FROM forum_thread"
" WHERE ForumType=%u"
" AND Location=%ld",
(unsigned) ForumType,InsCod);
else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of threads in institution forums for a country else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of threads in institution forums for a country
DB_BuildQuery ("SELECT COUNT(*)" NumThrs =
" FROM forum_thread,institutions" (unsigned) DB_QueryCOUNT ("can not get the number of threads"
" WHERE forum_thread.ForumType=%u" " in forums of a type",
" AND forum_thread.Location=institutions.InsCod" "SELECT COUNT(*)"
" AND institutions.CtyCod=%ld", " FROM forum_thread,institutions"
(unsigned) ForumType,CtyCod); " WHERE forum_thread.ForumType=%u"
" AND forum_thread.Location=institutions.InsCod"
" AND institutions.CtyCod=%ld",
(unsigned) ForumType,CtyCod);
else // InsCod <= 0 ==> Number of threads in institution forums for the whole platform else // InsCod <= 0 ==> Number of threads in institution forums for the whole platform
DB_BuildQuery ("SELECT COUNT(*)" NumThrs =
" FROM forum_thread" (unsigned) DB_QueryCOUNT ("can not get the number of threads"
" WHERE ForumType=%u", " in forums of a type",
(unsigned) ForumType); "SELECT COUNT(*)"
" FROM forum_thread"
" WHERE ForumType=%u",
(unsigned) ForumType);
break; break;
case For_FORUM_CENTRE_USRS: case For_FORUM_CENTRE_USRS:
case For_FORUM_CENTRE_TCHS: case For_FORUM_CENTRE_TCHS:
if (CtrCod > 0) // CtrCod > 0 ==> 0 <= Number of threads in centre forums for a centre <= 1 if (CtrCod > 0) // CtrCod > 0 ==> 0 <= Number of threads in centre forums for a centre <= 1
DB_BuildQuery ("SELECT COUNT(*)" NumThrs =
" FROM forum_thread" (unsigned) DB_QueryCOUNT ("can not get the number of threads"
" WHERE ForumType=%u" " in forums of a type",
" AND Location=%ld", "SELECT COUNT(*)"
(unsigned) ForumType,CtrCod); " FROM forum_thread"
" WHERE ForumType=%u"
" AND Location=%ld",
(unsigned) ForumType,CtrCod);
else if (InsCod > 0) // CtrCod <= 0 && InsCod > 0 ==> Number of threads in centre forums for an institution else if (InsCod > 0) // CtrCod <= 0 && InsCod > 0 ==> Number of threads in centre forums for an institution
DB_BuildQuery ("SELECT COUNT(*)" NumThrs =
" FROM forum_thread,centres" (unsigned) DB_QueryCOUNT ("can not get the number of threads"
" WHERE forum_thread.ForumType=%u" " in forums of a type",
" AND forum_thread.Location=centres.CtrCod" "SELECT COUNT(*)"
" AND centres.InsCod=%ld", " FROM forum_thread,centres"
(unsigned) ForumType,InsCod); " WHERE forum_thread.ForumType=%u"
" AND forum_thread.Location=centres.CtrCod"
" AND centres.InsCod=%ld",
(unsigned) ForumType,InsCod);
else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of threads in centre forums for a country else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of threads in centre forums for a country
DB_BuildQuery ("SELECT COUNT(*)" NumThrs =
" FROM forum_thread,centres,institutions" (unsigned) DB_QueryCOUNT ("can not get the number of threads"
" WHERE forum_thread.ForumType=%u" " in forums of a type",
" AND forum_thread.Location=centres.CtrCod" "SELECT COUNT(*)"
" AND centres.InsCod=institutions.InsCod" " FROM forum_thread,centres,institutions"
" AND institutions.CtyCod=%ld", " WHERE forum_thread.ForumType=%u"
(unsigned) ForumType,CtyCod); " AND forum_thread.Location=centres.CtrCod"
" AND centres.InsCod=institutions.InsCod"
" AND institutions.CtyCod=%ld",
(unsigned) ForumType,CtyCod);
else // InsCod <= 0 ==> Number of threads in centre forums for the whole platform else // InsCod <= 0 ==> Number of threads in centre forums for the whole platform
DB_BuildQuery ("SELECT COUNT(*)" NumThrs =
" FROM forum_thread" (unsigned) DB_QueryCOUNT ("can not get the number of threads"
" WHERE ForumType=%u", " in forums of a type",
(unsigned) ForumType); "SELECT COUNT(*)"
" FROM forum_thread"
" WHERE ForumType=%u",
(unsigned) ForumType);
break; break;
case For_FORUM_DEGREE_USRS: case For_FORUM_DEGREE_USRS:
case For_FORUM_DEGREE_TCHS: case For_FORUM_DEGREE_TCHS:
if (DegCod > 0) // DegCod > 0 ==> Number of threads in degree forums for a degree if (DegCod > 0) // DegCod > 0 ==> Number of threads in degree forums for a degree
DB_BuildQuery ("SELECT COUNT(*)" NumThrs =
" FROM forum_thread" (unsigned) DB_QueryCOUNT ("can not get the number of threads"
" WHERE ForumType=%u" " in forums of a type",
" AND Location=%ld", "SELECT COUNT(*)"
(unsigned) ForumType,DegCod); " FROM forum_thread"
" WHERE ForumType=%u"
" AND Location=%ld",
(unsigned) ForumType,DegCod);
else if (CtrCod > 0) // DegCod <= 0 && CtrCod > 0 ==> Number of threads in degree forums for a centre else if (CtrCod > 0) // DegCod <= 0 && CtrCod > 0 ==> Number of threads in degree forums for a centre
DB_BuildQuery ("SELECT COUNT(*)" NumThrs =
" FROM forum_thread,degrees" (unsigned) DB_QueryCOUNT ("can not get the number of threads"
" WHERE forum_thread.ForumType=%u" " in forums of a type",
" AND forum_thread.Location=degrees.DegCod" "SELECT COUNT(*)"
" AND degrees.CtrCod=%ld", " FROM forum_thread,degrees"
(unsigned) ForumType,CtrCod); " WHERE forum_thread.ForumType=%u"
" AND forum_thread.Location=degrees.DegCod"
" AND degrees.CtrCod=%ld",
(unsigned) ForumType,CtrCod);
else if (InsCod > 0) // CtrCod <= 0 && InsCod > 0 ==> Number of threads in degree forums for an institution else if (InsCod > 0) // CtrCod <= 0 && InsCod > 0 ==> Number of threads in degree forums for an institution
DB_BuildQuery ("SELECT COUNT(*)" NumThrs =
" FROM forum_thread,degrees,centres" (unsigned) DB_QueryCOUNT ("can not get the number of threads"
" WHERE forum_thread.ForumType=%u" " in forums of a type",
" AND forum_thread.Location=degrees.DegCod" "SELECT COUNT(*)"
" AND degrees.CtrCod=centres.CtrCod" " FROM forum_thread,degrees,centres"
" AND centres.InsCod=%ld", " WHERE forum_thread.ForumType=%u"
(unsigned) ForumType,InsCod); " AND forum_thread.Location=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
" AND centres.InsCod=%ld",
(unsigned) ForumType,InsCod);
else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of threads in degree forums for a country else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of threads in degree forums for a country
DB_BuildQuery ("SELECT COUNT(*)" NumThrs =
" FROM forum_thread,degrees,centres,institutions" (unsigned) DB_QueryCOUNT ("can not get the number of threads"
" WHERE forum_thread.ForumType=%u" " in forums of a type",
" AND forum_thread.Location=degrees.DegCod" "SELECT COUNT(*)"
" AND degrees.CtrCod=centres.CtrCod" " FROM forum_thread,degrees,centres,institutions"
" AND centres.InsCod=institutions.InsCod" " WHERE forum_thread.ForumType=%u"
" AND institutions.CtyCod=%ld", " AND forum_thread.Location=degrees.DegCod"
(unsigned) ForumType,CtyCod); " AND degrees.CtrCod=centres.CtrCod"
" AND centres.InsCod=institutions.InsCod"
" AND institutions.CtyCod=%ld",
(unsigned) ForumType,CtyCod);
else // InsCod <= 0 ==> Number of threads in degree forums for the whole platform else // InsCod <= 0 ==> Number of threads in degree forums for the whole platform
DB_BuildQuery ("SELECT COUNT(*)" NumThrs =
" FROM forum_thread" (unsigned) DB_QueryCOUNT ("can not get the number of threads"
" WHERE ForumType=%u", " in forums of a type",
(unsigned) ForumType); "SELECT COUNT(*)"
" FROM forum_thread"
" WHERE ForumType=%u",
(unsigned) ForumType);
break; break;
case For_FORUM_COURSE_USRS: case For_FORUM_COURSE_USRS:
case For_FORUM_COURSE_TCHS: case For_FORUM_COURSE_TCHS:
if (CrsCod > 0) // CrsCod > 0 ==> 0 <= Number of threads in course forums for a course if (CrsCod > 0) // CrsCod > 0 ==> 0 <= Number of threads in course forums for a course
DB_BuildQuery ("SELECT COUNT(*)" NumThrs =
" FROM forum_thread" (unsigned) DB_QueryCOUNT ("can not get the number of threads"
" WHERE ForumType=%u" " in forums of a type",
" AND Location=%ld", "SELECT COUNT(*)"
(unsigned) ForumType,CrsCod); " FROM forum_thread"
" WHERE ForumType=%u"
" AND Location=%ld",
(unsigned) ForumType,CrsCod);
else if (DegCod > 0) // CrsCod <= 0 && DegCod > 0 ==> Number of threads in course forums for a degree else if (DegCod > 0) // CrsCod <= 0 && DegCod > 0 ==> Number of threads in course forums for a degree
DB_BuildQuery ("SELECT COUNT(*)" NumThrs =
" FROM forum_thread,courses" (unsigned) DB_QueryCOUNT ("can not get the number of threads"
" WHERE forum_thread.ForumType=%u" " in forums of a type",
" AND forum_thread.Location=courses.CrsCod" "SELECT COUNT(*)"
" AND courses.DegCod=%ld", " FROM forum_thread,courses"
(unsigned) ForumType,DegCod); " WHERE forum_thread.ForumType=%u"
" AND forum_thread.Location=courses.CrsCod"
" AND courses.DegCod=%ld",
(unsigned) ForumType,DegCod);
else if (CtrCod > 0) // DegCod <= 0 && CtrCod > 0 ==> Number of threads in course forums for a centre else if (CtrCod > 0) // DegCod <= 0 && CtrCod > 0 ==> Number of threads in course forums for a centre
DB_BuildQuery ("SELECT COUNT(*)" NumThrs =
" FROM forum_thread,courses,degrees" (unsigned) DB_QueryCOUNT ("can not get the number of threads"
" WHERE forum_thread.ForumType=%u" " in forums of a type",
" AND forum_thread.Location=courses.CrsCod" "SELECT COUNT(*)"
" AND courses.DegCod=degrees.DegCod" " FROM forum_thread,courses,degrees"
" AND degrees.CtrCod=%ld", " WHERE forum_thread.ForumType=%u"
(unsigned) ForumType,CtrCod); " AND forum_thread.Location=courses.CrsCod"
" AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=%ld",
(unsigned) ForumType,CtrCod);
else if (InsCod > 0) // CtrCod <= 0 && InsCod > 0 ==> Number of threads in course forums for an institution else if (InsCod > 0) // CtrCod <= 0 && InsCod > 0 ==> Number of threads in course forums for an institution
DB_BuildQuery ("SELECT COUNT(*)" NumThrs =
" FROM forum_thread,courses,degrees,centres" (unsigned) DB_QueryCOUNT ("can not get the number of threads"
" WHERE forum_thread.ForumType=%u" " in forums of a type",
" AND forum_thread.Location=courses.CrsCod" "SELECT COUNT(*)"
" AND courses.DegCod=degrees.DegCod" " FROM forum_thread,courses,degrees,centres"
" AND degrees.CtrCod=centres.CtrCod" " WHERE forum_thread.ForumType=%u"
" AND centres.InsCod=%ld", " AND forum_thread.Location=courses.CrsCod"
(unsigned) ForumType,InsCod); " AND courses.DegCod=degrees.DegCod"
" AND degrees.CtrCod=centres.CtrCod"
" AND centres.InsCod=%ld",
(unsigned) ForumType,InsCod);
else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of threads in course forums for a country else if (CtyCod > 0) // InsCod <= 0 && CtyCod > 0 ==> Number of threads in course forums for a country
DB_BuildQuery ("SELECT COUNT(*)" NumThrs =
" FROM forum_thread,courses,degrees,centres,institutions" (unsigned) DB_QueryCOUNT ("can not get the number of threads"
" WHERE forum_thread.ForumType=%u" " in forums of a type",
" AND forum_thread.Location=courses.CrsCod" "SELECT COUNT(*)"
" AND courses.DegCod=degrees.DegCod" " FROM forum_thread,courses,degrees,centres,institutions"
" AND degrees.CtrCod=centres.CtrCod" " WHERE forum_thread.ForumType=%u"
" AND centres.InsCod=institutions.InsCod" " AND forum_thread.Location=courses.CrsCod"
" AND institutions.CtyCod=%ld", " AND courses.DegCod=degrees.DegCod"
(unsigned) ForumType,CtyCod); " AND degrees.CtrCod=centres.CtrCod"
" AND centres.InsCod=institutions.InsCod"
" AND institutions.CtyCod=%ld",
(unsigned) ForumType,CtyCod);
else // InsCod <= 0 ==> Number of threads in course forums for the whole platform else // InsCod <= 0 ==> Number of threads in course forums for the whole platform
DB_BuildQuery ("SELECT COUNT(*)" NumThrs =
" FROM forum_thread" (unsigned) DB_QueryCOUNT ("can not get the number of threads"
" WHERE ForumType=%u", " in forums of a type",
(unsigned) ForumType); "SELECT COUNT(*)"
" FROM forum_thread"
" WHERE ForumType=%u",
(unsigned) ForumType);
break; break;
default: default:
return 0; NumThrs = 0;
break;
} }
return (unsigned) DB_QueryCOUNT_new ("can not get the number of threads in forums of a type");
return NumThrs;
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3030,9 +3093,11 @@ static unsigned For_GetNumThrsInForum (struct Forum *Forum)
sprintf (SubQuery," AND Location=%ld",Forum->Location); sprintf (SubQuery," AND Location=%ld",Forum->Location);
else else
SubQuery[0] = '\0'; SubQuery[0] = '\0';
DB_BuildQuery ("SELECT COUNT(*) FROM forum_thread WHERE ForumType=%u%s", return
(unsigned) Forum->Type,SubQuery); (unsigned) DB_QueryCOUNT ("can not get number of threads in a forum",
return (unsigned) DB_QueryCOUNT_new ("can not get number of threads in a forum"); "SELECT COUNT(*) FROM forum_thread"
" WHERE ForumType=%u%s",
(unsigned) Forum->Type,SubQuery);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3291,11 +3356,12 @@ static unsigned For_GetNumPstsInForum (struct Forum *Forum)
sprintf (SubQuery," AND forum_thread.Location=%ld",Forum->Location); sprintf (SubQuery," AND forum_thread.Location=%ld",Forum->Location);
else else
SubQuery[0] = '\0'; SubQuery[0] = '\0';
DB_BuildQuery ("SELECT COUNT(*) FROM forum_thread,forum_post " return
" WHERE forum_thread.ForumType=%u%s" (unsigned) DB_QueryCOUNT ("can not get the number of posts in a forum",
" AND forum_thread.ThrCod=forum_post.ThrCod", "SELECT COUNT(*) FROM forum_thread,forum_post "
(unsigned) Forum->Type,SubQuery); " WHERE forum_thread.ForumType=%u%s"
return (unsigned) DB_QueryCOUNT_new ("can not get the number of posts in a forum"); " AND forum_thread.ThrCod=forum_post.ThrCod",
(unsigned) Forum->Type,SubQuery);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -4409,10 +4475,10 @@ static bool For_CheckIfThrBelongsToForum (long ThrCod,struct Forum *Forum)
sprintf (SubQuery," AND forum_thread.Location=%ld",Forum->Location); sprintf (SubQuery," AND forum_thread.Location=%ld",Forum->Location);
else else
SubQuery[0] = '\0'; SubQuery[0] = '\0';
DB_BuildQuery ("SELECT COUNT(*) FROM forum_thread" return (DB_QueryCOUNT ("can not get if a thread belong to current forum",
" WHERE ThrCod=%ld AND ForumType=%u%s", "SELECT COUNT(*) FROM forum_thread"
ThrCod,(unsigned) Forum->Type,SubQuery); " WHERE ThrCod=%ld AND ForumType=%u%s",
return (DB_QueryCOUNT_new ("can not get if a thread belong to current forum") != 0); ThrCod,(unsigned) Forum->Type,SubQuery) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -1715,12 +1715,12 @@ static bool Gam_CheckIfSimilarGameExists (struct Game *Game)
extern const char *Sco_ScopeDB[Sco_NUM_SCOPES]; extern const char *Sco_ScopeDB[Sco_NUM_SCOPES];
/***** Get number of games with a field value from database *****/ /***** Get number of games with a field value from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM games" return (DB_QueryCOUNT ("can not get similar games",
" WHERE Scope='%s' AND Cod=%ld" "SELECT COUNT(*) FROM games"
" AND Title='%s' AND GamCod<>%ld", " WHERE Scope='%s' AND Cod=%ld"
Sco_ScopeDB[Game->Scope],Game->Cod, " AND Title='%s' AND GamCod<>%ld",
Game->Title,Game->GamCod); Sco_ScopeDB[Game->Scope],Game->Cod,
return (DB_QueryCOUNT_new ("can not get similar games") != 0); Game->Title,Game->GamCod) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2254,8 +2254,9 @@ static void Gam_UpdateGame (struct Game *Game,const char *Txt)
static bool Gam_CheckIfGamIsAssociatedToGrps (long GamCod) static bool Gam_CheckIfGamIsAssociatedToGrps (long GamCod)
{ {
/***** Get if a game is associated to a group from database *****/ /***** Get if a game is associated to a group from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM gam_grp WHERE GamCod=%ld",GamCod); return (DB_QueryCOUNT ("can not check if a game is associated to groups",
return (DB_QueryCOUNT_new ("can not check if a game is associated to groups") != 0); "SELECT COUNT(*) FROM gam_grp WHERE GamCod=%ld",
GamCod) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2265,10 +2266,10 @@ static bool Gam_CheckIfGamIsAssociatedToGrps (long GamCod)
bool Gam_CheckIfGamIsAssociatedToGrp (long GamCod,long GrpCod) bool Gam_CheckIfGamIsAssociatedToGrp (long GamCod,long GrpCod)
{ {
/***** Get if a game is associated to a group from database *****/ /***** Get if a game is associated to a group from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM gam_grp" return (DB_QueryCOUNT ("can not check if a game is associated to a group",
" WHERE GamCod=%ld AND GrpCod=%ld", "SELECT COUNT(*) FROM gam_grp"
GamCod,GrpCod); " WHERE GamCod=%ld AND GrpCod=%ld",
return (DB_QueryCOUNT_new ("can not check if a game is associated to a group") != 0); GamCod,GrpCod) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2457,14 +2458,14 @@ void Gam_RemoveGames (Sco_Scope_t Scope,long Cod)
static bool Gam_CheckIfICanDoThisGameBasedOnGrps (long GamCod) static bool Gam_CheckIfICanDoThisGameBasedOnGrps (long GamCod)
{ {
/***** Get if I can do a game from database *****/ /***** Get if I can do a game from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM games" return (DB_QueryCOUNT ("can not check if I can do a game",
" WHERE GamCod=%ld" "SELECT COUNT(*) FROM games"
" AND (GamCod NOT IN (SELECT GamCod FROM gam_grp) OR" " WHERE GamCod=%ld"
" GamCod IN (SELECT gam_grp.GamCod FROM gam_grp,crs_grp_usr" " AND (GamCod NOT IN (SELECT GamCod FROM gam_grp) OR"
" WHERE crs_grp_usr.UsrCod=%ld" " GamCod IN (SELECT gam_grp.GamCod FROM gam_grp,crs_grp_usr"
" AND gam_grp.GrpCod=crs_grp_usr.GrpCod))", " WHERE crs_grp_usr.UsrCod=%ld"
GamCod,Gbl.Usrs.Me.UsrDat.UsrCod); " AND gam_grp.GrpCod=crs_grp_usr.GrpCod))",
return (DB_QueryCOUNT_new ("can not check if I can do a game") != 0); GamCod,Gbl.Usrs.Me.UsrDat.UsrCod) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2474,8 +2475,11 @@ static bool Gam_CheckIfICanDoThisGameBasedOnGrps (long GamCod)
static unsigned Gam_GetNumQstsGame (long GamCod) static unsigned Gam_GetNumQstsGame (long GamCod)
{ {
/***** Get data of questions from database *****/ /***** Get data of questions from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM gam_questions WHERE GamCod=%ld",GamCod); return
return (unsigned) DB_QueryCOUNT_new ("can not get number of questions of a game"); (unsigned) DB_QueryCOUNT ("can not get number of questions of a game",
"SELECT COUNT(*) FROM gam_questions"
" WHERE GamCod=%ld",
GamCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3788,10 +3792,10 @@ static void Gam_RegisterIHaveAnsweredGame (long GamCod)
static bool Gam_CheckIfIHaveAnsweredGame (long GamCod) static bool Gam_CheckIfIHaveAnsweredGame (long GamCod)
{ {
/***** Get number of games with a field value from database *****/ /***** Get number of games with a field value from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM gam_users" return (DB_QueryCOUNT ("can not check if you have answered a game",
" WHERE GamCod=%ld AND UsrCod=%ld", "SELECT COUNT(*) FROM gam_users"
GamCod,Gbl.Usrs.Me.UsrDat.UsrCod); " WHERE GamCod=%ld AND UsrCod=%ld",
return (DB_QueryCOUNT_new ("can not check if you have answered a game") != 0); GamCod,Gbl.Usrs.Me.UsrDat.UsrCod) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3801,8 +3805,12 @@ static bool Gam_CheckIfIHaveAnsweredGame (long GamCod)
static unsigned Gam_GetNumUsrsWhoHaveAnsweredGame (long GamCod) static unsigned Gam_GetNumUsrsWhoHaveAnsweredGame (long GamCod)
{ {
/***** Get number of games with a field value from database *****/ /***** Get number of games with a field value from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM gam_users WHERE GamCod=%ld",GamCod); return
return (unsigned) DB_QueryCOUNT_new ("can not get number of users who have answered a game"); (unsigned) DB_QueryCOUNT ("can not get number of users"
" who have answered a game",
"SELECT COUNT(*) FROM gam_users"
" WHERE GamCod=%ld",
GamCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -2955,11 +2955,12 @@ void Grp_FreeListGrpTypesAndGrps (void)
unsigned Grp_CountNumGrpsInCurrentCrs (void) unsigned Grp_CountNumGrpsInCurrentCrs (void)
{ {
/***** Get number of group in current course from database *****/ /***** Get number of group in current course from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM crs_grp_types,crs_grp" return
" WHERE crs_grp_types.CrsCod=%ld" (unsigned) DB_QueryCOUNT ("can not get number of groups in this course",
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod", "SELECT COUNT(*) FROM crs_grp_types,crs_grp"
Gbl.CurrentCrs.Crs.CrsCod); " WHERE crs_grp_types.CrsCod=%ld"
return (unsigned) DB_QueryCOUNT_new ("can not get number of groups in this course"); " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod",
Gbl.CurrentCrs.Crs.CrsCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2969,9 +2970,11 @@ unsigned Grp_CountNumGrpsInCurrentCrs (void)
static unsigned Grp_CountNumGrpsInThisCrsOfType (long GrpTypCod) static unsigned Grp_CountNumGrpsInThisCrsOfType (long GrpTypCod)
{ {
/***** Get number of groups of a type from database *****/ /***** Get number of groups of a type from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM crs_grp WHERE GrpTypCod=%ld", return
GrpTypCod); (unsigned) DB_QueryCOUNT ("can not get number of groups of a type",
return (unsigned) DB_QueryCOUNT_new ("can not get number of groups of a type"); "SELECT COUNT(*) FROM crs_grp"
" WHERE GrpTypCod=%ld",
GrpTypCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3170,8 +3173,9 @@ static long Grp_GetTypeOfGroupOfAGroup (long GrpCod)
bool Grp_CheckIfGroupExists (long GrpCod) bool Grp_CheckIfGroupExists (long GrpCod)
{ {
/***** Get if a group exists from database *****/ /***** Get if a group exists from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM crs_grp WHERE GrpCod=%ld",GrpCod); return (DB_QueryCOUNT ("can not check if a group exists",
return (DB_QueryCOUNT_new ("can not check if a group exists") != 0); "SELECT COUNT(*) FROM crs_grp WHERE GrpCod=%ld",
GrpCod) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3181,12 +3185,12 @@ bool Grp_CheckIfGroupExists (long GrpCod)
bool Grp_CheckIfGroupBelongsToCourse (long GrpCod,long CrsCod) bool Grp_CheckIfGroupBelongsToCourse (long GrpCod,long CrsCod)
{ {
/***** Get if a group exists from database *****/ /***** Get if a group exists from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM crs_grp,crs_grp_types" return (DB_QueryCOUNT ("can not check if a group belongs to a course",
" WHERE crs_grp.GrpCod=%ld" "SELECT COUNT(*) FROM crs_grp,crs_grp_types"
" AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod" " WHERE crs_grp.GrpCod=%ld"
" AND crs_grp_types.CrsCod=%ld", " AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod"
GrpCod,CrsCod); " AND crs_grp_types.CrsCod=%ld",
return (DB_QueryCOUNT_new ("can not check if a group belongs to a course") != 0); GrpCod,CrsCod) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3196,16 +3200,17 @@ bool Grp_CheckIfGroupBelongsToCourse (long GrpCod,long CrsCod)
unsigned Grp_CountNumUsrsInGrp (Rol_Role_t Role,long GrpCod) unsigned Grp_CountNumUsrsInGrp (Rol_Role_t Role,long GrpCod)
{ {
/***** Get number of students in a group from database *****/ /***** Get number of students in a group from database *****/
DB_BuildQuery ("SELECT COUNT(*)" return
" FROM crs_grp_usr,crs_grp,crs_grp_types,crs_usr" (unsigned) DB_QueryCOUNT ("can not get number of users in a group",
" WHERE crs_grp_usr.GrpCod=%ld" "SELECT COUNT(*)"
" AND crs_grp_usr.GrpCod=crs_grp.GrpCod" " FROM crs_grp_usr,crs_grp,crs_grp_types,crs_usr"
" AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod" " WHERE crs_grp_usr.GrpCod=%ld"
" AND crs_grp_types.CrsCod=crs_usr.CrsCod" " AND crs_grp_usr.GrpCod=crs_grp.GrpCod"
" AND crs_grp_usr.UsrCod=crs_usr.UsrCod" " AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod"
" AND crs_usr.Role=%u", " AND crs_grp_types.CrsCod=crs_usr.CrsCod"
GrpCod,(unsigned) Role); " AND crs_grp_usr.UsrCod=crs_usr.UsrCod"
return (unsigned) DB_QueryCOUNT_new ("can not get number of users in a group"); " AND crs_usr.Role=%u",
GrpCod,(unsigned) Role);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3288,12 +3293,12 @@ bool Grp_GetIfIBelongToGrp (long GrpCod)
return Gbl.Cache.IBelongToGrp.IBelong; return Gbl.Cache.IBelongToGrp.IBelong;
/***** 3. Slow check: Get if I belong to a group from database *****/ /***** 3. Slow check: Get if I belong to a group from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM crs_grp_usr"
" WHERE GrpCod=%ld AND UsrCod=%ld",
GrpCod,Gbl.Usrs.Me.UsrDat.UsrCod);
Gbl.Cache.IBelongToGrp.GrpCod = GrpCod; Gbl.Cache.IBelongToGrp.GrpCod = GrpCod;
Gbl.Cache.IBelongToGrp.IBelong = (DB_QueryCOUNT_new ("can not check" Gbl.Cache.IBelongToGrp.IBelong =
" if you belong to a group") != 0); (DB_QueryCOUNT ("can not check if you belong to a group",
"SELECT COUNT(*) FROM crs_grp_usr"
" WHERE GrpCod=%ld AND UsrCod=%ld",
GrpCod,Gbl.Usrs.Me.UsrDat.UsrCod) != 0);
return Gbl.Cache.IBelongToGrp.IBelong; return Gbl.Cache.IBelongToGrp.IBelong;
} }
@ -3358,21 +3363,21 @@ bool Grp_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (const struct UsrData *UsrDat)
/***** 9. Slow check: Get if user shares any group in this course with me from database *****/ /***** 9. Slow check: Get if user shares any group in this course with me from database *****/
/* Check if user shares any group with me */ /* Check if user shares any group with me */
Gbl.Cache.UsrSharesAnyOfMyGrpsInCurrentCrs.UsrCod = UsrDat->UsrCod; Gbl.Cache.UsrSharesAnyOfMyGrpsInCurrentCrs.UsrCod = UsrDat->UsrCod;
DB_BuildQuery ("SELECT COUNT(*) FROM crs_grp_usr" Gbl.Cache.UsrSharesAnyOfMyGrpsInCurrentCrs.Shares =
" WHERE UsrCod=%ld" (DB_QueryCOUNT ("can not check if a user shares any group"
" AND GrpCod IN" " in the current course with you",
" (SELECT crs_grp_usr.GrpCod" "SELECT COUNT(*) FROM crs_grp_usr"
" FROM crs_grp_usr,crs_grp,crs_grp_types" " WHERE UsrCod=%ld"
" WHERE crs_grp_usr.UsrCod=%ld" " AND GrpCod IN"
" AND crs_grp_usr.GrpCod=crs_grp.GrpCod" " (SELECT crs_grp_usr.GrpCod"
" AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod" " FROM crs_grp_usr,crs_grp,crs_grp_types"
" AND crs_grp_types.CrsCod=%ld)", " WHERE crs_grp_usr.UsrCod=%ld"
UsrDat->UsrCod, " AND crs_grp_usr.GrpCod=crs_grp.GrpCod"
Gbl.Usrs.Me.UsrDat.UsrCod, " AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod"
Gbl.CurrentCrs.Crs.CrsCod); " AND crs_grp_types.CrsCod=%ld)",
Gbl.Cache.UsrSharesAnyOfMyGrpsInCurrentCrs.Shares = (DB_QueryCOUNT_new ("can not check" UsrDat->UsrCod,
" if a user shares any group" Gbl.Usrs.Me.UsrDat.UsrCod,
" in the current course with you") != 0); Gbl.CurrentCrs.Crs.CrsCod) != 0);
return Gbl.Cache.UsrSharesAnyOfMyGrpsInCurrentCrs.Shares; return Gbl.Cache.UsrSharesAnyOfMyGrpsInCurrentCrs.Shares;
} }
@ -3388,36 +3393,37 @@ unsigned Grp_NumGrpTypesMandatIDontBelongAsStd (void)
/***** Get the number of types of groups with mandatory enrolment /***** Get the number of types of groups with mandatory enrolment
which I don't belong to as student, from database *****/ which I don't belong to as student, from database *****/
DB_BuildQuery ("SELECT COUNT(DISTINCT GrpTypCod) FROM" NumGrpTypes =
" (SELECT crs_grp_types.GrpTypCod AS GrpTypCod," (unsigned) DB_QueryCOUNT ("can not get the number of types of group"
"COUNT(*) AS NumStudents," " of mandatory registration"
"crs_grp.MaxStudents as MaxStudents" " to which you don't belong to",
" FROM crs_grp_types,crs_grp,crs_grp_usr,crs_usr" "SELECT COUNT(DISTINCT GrpTypCod) FROM"
" WHERE crs_grp_types.CrsCod=%ld" " (SELECT crs_grp_types.GrpTypCod AS GrpTypCod,"
" AND crs_grp_types.Mandatory='Y'" "COUNT(*) AS NumStudents,"
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" "crs_grp.MaxStudents as MaxStudents"
" AND crs_grp.Open='Y'" " FROM crs_grp_types,crs_grp,crs_grp_usr,crs_usr"
" AND crs_grp_types.CrsCod=crs_usr.CrsCod" " WHERE crs_grp_types.CrsCod=%ld"
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod" " AND crs_grp_types.Mandatory='Y'"
" AND crs_grp_usr.UsrCod=crs_usr.UsrCod" " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
" AND crs_usr.Role=%u" " AND crs_grp.Open='Y'"
" GROUP BY crs_grp.GrpCod" " AND crs_grp_types.CrsCod=crs_usr.CrsCod"
" HAVING NumStudents<MaxStudents) AS grp_types_open_not_full" " AND crs_grp.GrpCod=crs_grp_usr.GrpCod"
" WHERE GrpTypCod NOT IN" " AND crs_grp_usr.UsrCod=crs_usr.UsrCod"
" (SELECT DISTINCT crs_grp_types.GrpTypCod" " AND crs_usr.Role=%u"
" FROM crs_grp_types,crs_grp,crs_grp_usr" " GROUP BY crs_grp.GrpCod"
" WHERE crs_grp_types.CrsCod=%ld" " HAVING NumStudents<MaxStudents) AS grp_types_open_not_full"
" AND crs_grp_types.Mandatory='Y'" " WHERE GrpTypCod NOT IN"
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" " (SELECT DISTINCT crs_grp_types.GrpTypCod"
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod" " FROM crs_grp_types,crs_grp,crs_grp_usr"
" AND crs_grp_usr.UsrCod=%ld)", " WHERE crs_grp_types.CrsCod=%ld"
Gbl.CurrentCrs.Crs.CrsCod, " AND crs_grp_types.Mandatory='Y'"
(unsigned) Rol_STD, " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
Gbl.CurrentCrs.Crs.CrsCod, " AND crs_grp.GrpCod=crs_grp_usr.GrpCod"
Gbl.Usrs.Me.UsrDat.UsrCod); " AND crs_grp_usr.UsrCod=%ld)",
NumGrpTypes = DB_QueryCOUNT_new ("can not get the number of types of group" Gbl.CurrentCrs.Crs.CrsCod,
" of mandatory registration" (unsigned) Rol_STD,
" to which you don't belong to"); Gbl.CurrentCrs.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
return NumGrpTypes; return NumGrpTypes;
} }
@ -3432,47 +3438,48 @@ static bool Grp_GetIfGrpIsAvailable (long GrpTypCod)
/***** Get the number of types of group (0 or 1) of a type /***** Get the number of types of group (0 or 1) of a type
with one or more open groups with vacants, from database *****/ with one or more open groups with vacants, from database *****/
DB_BuildQuery ("SELECT COUNT(GrpTypCod) FROM " NumGrpTypes =
"(" (unsigned) DB_QueryCOUNT ("can not check if a type of group has available groups",
// Groups with students "SELECT COUNT(GrpTypCod) FROM "
"SELECT crs_grp_types.GrpTypCod AS GrpTypCod," "("
"COUNT(*) AS NumStudents," // Groups with students
"crs_grp.MaxStudents as MaxStudents" "SELECT crs_grp_types.GrpTypCod AS GrpTypCod,"
" FROM crs_grp_types,crs_grp,crs_grp_usr,crs_usr" "COUNT(*) AS NumStudents,"
" WHERE crs_grp_types.GrpTypCod=%ld" "crs_grp.MaxStudents as MaxStudents"
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" " FROM crs_grp_types,crs_grp,crs_grp_usr,crs_usr"
" AND crs_grp.Open='Y'" " WHERE crs_grp_types.GrpTypCod=%ld"
" AND crs_grp_types.CrsCod=crs_usr.CrsCod" " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod" " AND crs_grp.Open='Y'"
" AND crs_grp_usr.UsrCod=crs_usr.UsrCod" " AND crs_grp_types.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u" " AND crs_grp.GrpCod=crs_grp_usr.GrpCod"
" GROUP BY crs_grp.GrpCod" " AND crs_grp_usr.UsrCod=crs_usr.UsrCod"
" HAVING NumStudents<MaxStudents" " AND crs_usr.Role=%u"
" GROUP BY crs_grp.GrpCod"
" HAVING NumStudents<MaxStudents"
" UNION " " UNION "
// Groups without students // Groups without students
"SELECT crs_grp_types.GrpTypCod AS GrpTypCod," "SELECT crs_grp_types.GrpTypCod AS GrpTypCod,"
"0 AS NumStudents," "0 AS NumStudents,"
"crs_grp.MaxStudents as MaxStudents" "crs_grp.MaxStudents as MaxStudents"
" FROM crs_grp_types,crs_grp" " FROM crs_grp_types,crs_grp"
" WHERE crs_grp_types.GrpTypCod=%ld" " WHERE crs_grp_types.GrpTypCod=%ld"
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
" AND crs_grp.Open='Y'" " AND crs_grp.Open='Y'"
" AND crs_grp.MaxStudents > 0" " AND crs_grp.MaxStudents > 0"
" AND crs_grp.GrpCod NOT IN" " AND crs_grp.GrpCod NOT IN"
" (SELECT crs_grp_usr.GrpCod" " (SELECT crs_grp_usr.GrpCod"
" FROM crs_grp_types,crs_usr,crs_grp_usr" " FROM crs_grp_types,crs_usr,crs_grp_usr"
" WHERE crs_grp_types.GrpTypCod=%ld" " WHERE crs_grp_types.GrpTypCod=%ld"
" AND crs_grp_types.CrsCod=crs_usr.CrsCod" " AND crs_grp_types.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u" " AND crs_usr.Role=%u"
" AND crs_usr.UsrCod=crs_grp_usr.UsrCod)" " AND crs_usr.UsrCod=crs_grp_usr.UsrCod)"
") AS available_grp_types", ") AS available_grp_types",
GrpTypCod,(unsigned) Rol_STD, GrpTypCod,(unsigned) Rol_STD,
GrpTypCod, GrpTypCod,
GrpTypCod,(unsigned) Rol_STD); GrpTypCod,(unsigned) Rol_STD);
NumGrpTypes = DB_QueryCOUNT_new ("can not check if a type of group has available groups");
return (NumGrpTypes != 0); return (NumGrpTypes != 0);
} }
@ -3798,11 +3805,12 @@ void Grp_RecFormNewGrp (void)
static bool Grp_CheckIfGroupTypeNameExists (const char *GrpTypName,long GrpTypCod) static bool Grp_CheckIfGroupTypeNameExists (const char *GrpTypName,long GrpTypCod)
{ {
/***** Get number of group types with a name from database *****/ /***** Get number of group types with a name from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM crs_grp_types" return (DB_QueryCOUNT ("can not check if the name of type of group"
" WHERE CrsCod=%ld AND GrpTypName='%s'" " already existed",
" AND GrpTypCod<>%ld", "SELECT COUNT(*) FROM crs_grp_types"
Gbl.CurrentCrs.Crs.CrsCod,GrpTypName,GrpTypCod); " WHERE CrsCod=%ld AND GrpTypName='%s'"
return (DB_QueryCOUNT_new ("can not check if the name of type of group already existed") != 0); " AND GrpTypCod<>%ld",
Gbl.CurrentCrs.Crs.CrsCod,GrpTypName,GrpTypCod) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3812,10 +3820,12 @@ static bool Grp_CheckIfGroupTypeNameExists (const char *GrpTypName,long GrpTypCo
static bool Grp_CheckIfGroupNameExists (long GrpTypCod,const char *GrpName,long GrpCod) static bool Grp_CheckIfGroupNameExists (long GrpTypCod,const char *GrpName,long GrpCod)
{ {
/***** Get number of groups with a type and a name from database *****/ /***** Get number of groups with a type and a name from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM crs_grp" return (DB_QueryCOUNT ("can not check if the name of group already existed",
" WHERE GrpTypCod=%ld AND GrpName='%s' AND GrpCod<>%ld", "SELECT COUNT(*) FROM crs_grp"
GrpTypCod,GrpName,GrpCod); " WHERE GrpTypCod=%ld"
return (DB_QueryCOUNT_new ("can not check if the name of group already existed") != 0); " AND GrpName='%s'"
" AND GrpCod<>%ld",
GrpTypCod,GrpName,GrpCod) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -523,12 +523,12 @@ static void Inf_PutCheckboxConfirmIHaveReadInfo (void)
static bool Inf_CheckIfIHaveReadInfo (void) static bool Inf_CheckIfIHaveReadInfo (void)
{ {
/***** Get if info source is already stored in database *****/ /***** Get if info source is already stored in database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM crs_info_read" return (DB_QueryCOUNT ("can not get if I have read course info",
" WHERE UsrCod=%ld AND CrsCod=%ld AND InfoType='%s'", "SELECT COUNT(*) FROM crs_info_read"
Gbl.Usrs.Me.UsrDat.UsrCod, " WHERE UsrCod=%ld AND CrsCod=%ld AND InfoType='%s'",
Gbl.CurrentCrs.Crs.CrsCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]); Gbl.CurrentCrs.Crs.CrsCod,
return (DB_QueryCOUNT_new ("can not get if I have read course info") != 0); Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1477,11 +1477,12 @@ Inf_InfoSrc_t Inf_GetInfoSrcFromForm (void)
void Inf_SetInfoSrcIntoDB (Inf_InfoSrc_t InfoSrc) void Inf_SetInfoSrcIntoDB (Inf_InfoSrc_t InfoSrc)
{ {
/***** Get if info source is already stored in database *****/ /***** Get if info source is already stored in database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM crs_info_src" if (DB_QueryCOUNT ("can not get if info source is already stored in database",
" WHERE CrsCod=%ld AND InfoType='%s'", "SELECT COUNT(*) FROM crs_info_src"
Gbl.CurrentCrs.Crs.CrsCod, " WHERE CrsCod=%ld AND InfoType='%s'",
Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]); Gbl.CurrentCrs.Crs.CrsCod,
if (DB_QueryCOUNT_new ("can not get if info source is already stored in database")) // Info is already stored in database, so update it Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]))
// Info is already stored in database, so update it
{ // Update info source { // Update info source
if (InfoSrc == Inf_INFO_SRC_NONE) if (InfoSrc == Inf_INFO_SRC_NONE)
DB_QueryUPDATE ("can not update info source", DB_QueryUPDATE ("can not update info source",

View File

@ -1872,10 +1872,11 @@ static void Ins_RenameInstitution (struct Instit *Ins,Cns_ShrtOrFullName_t ShrtO
static bool Ins_CheckIfInsNameExistsInCty (const char *FieldName,const char *Name,long InsCod,long CtyCod) static bool Ins_CheckIfInsNameExistsInCty (const char *FieldName,const char *Name,long InsCod,long CtyCod)
{ {
/***** Get number of institutions in current country with a name from database *****/ /***** Get number of institutions in current country with a name from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM institutions" return (DB_QueryCOUNT ("can not check if the name of an institution"
" WHERE CtyCod=%ld AND %s='%s' AND InsCod<>%ld", " already existed",
CtyCod,FieldName,Name,InsCod); "SELECT COUNT(*) FROM institutions"
return (DB_QueryCOUNT_new ("can not check if the name of an institution already existed") != 0); " WHERE CtyCod=%ld AND %s='%s' AND InsCod<>%ld",
CtyCod,FieldName,Name,InsCod) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2441,8 +2442,9 @@ static void Ins_CreateInstitution (unsigned Status)
unsigned Ins_GetNumInssTotal (void) unsigned Ins_GetNumInssTotal (void)
{ {
/***** Get total number of degrees from database *****/ /***** Get total number of degrees from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM institutions"); return
return (unsigned) DB_QueryCOUNT_new ("can not get the total number of institutions"); (unsigned) DB_QueryCOUNT ("can not get the total number of institutions",
"SELECT COUNT(*) FROM institutions");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2452,8 +2454,12 @@ unsigned Ins_GetNumInssTotal (void)
unsigned Ins_GetNumInssInCty (long CtyCod) unsigned Ins_GetNumInssInCty (long CtyCod)
{ {
/***** Get number of degrees of a place from database *****/ /***** Get number of degrees of a place from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM institutions WHERE CtyCod=%ld",CtyCod); return
return (unsigned) DB_QueryCOUNT_new ("can not get the number of institutions in a country"); (unsigned) DB_QueryCOUNT ("can not get the number of institutions"
" in a country",
"SELECT COUNT(*) FROM institutions"
" WHERE CtyCod=%ld",
CtyCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2463,11 +2469,12 @@ unsigned Ins_GetNumInssInCty (long CtyCod)
unsigned Ins_GetNumInssWithCtrs (const char *SubQuery) unsigned Ins_GetNumInssWithCtrs (const char *SubQuery)
{ {
/***** Get number of institutions with centres from database *****/ /***** Get number of institutions with centres from database *****/
DB_BuildQuery ("SELECT COUNT(DISTINCT institutions.InsCod)" return
" FROM institutions,centres" (unsigned) DB_QueryCOUNT ("can not get number of institutions with centres",
" WHERE %sinstitutions.InsCod=centres.InsCod", "SELECT COUNT(DISTINCT institutions.InsCod)"
SubQuery); " FROM institutions,centres"
return (unsigned) DB_QueryCOUNT_new ("can not get number of institutions with centres"); " WHERE %sinstitutions.InsCod=centres.InsCod",
SubQuery);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2477,12 +2484,13 @@ unsigned Ins_GetNumInssWithCtrs (const char *SubQuery)
unsigned Ins_GetNumInssWithDegs (const char *SubQuery) unsigned Ins_GetNumInssWithDegs (const char *SubQuery)
{ {
/***** Get number of institutions with degrees from database *****/ /***** Get number of institutions with degrees from database *****/
DB_BuildQuery ("SELECT COUNT(DISTINCT institutions.InsCod)" return
" FROM institutions,centres,degrees" (unsigned) DB_QueryCOUNT ("can not get number of institutions with degrees",
" WHERE %sinstitutions.InsCod=centres.InsCod" "SELECT COUNT(DISTINCT institutions.InsCod)"
" AND centres.CtrCod=degrees.CtrCod", " FROM institutions,centres,degrees"
SubQuery); " WHERE %sinstitutions.InsCod=centres.InsCod"
return (unsigned) DB_QueryCOUNT_new ("can not get number of institutions with degrees"); " AND centres.CtrCod=degrees.CtrCod",
SubQuery);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2492,13 +2500,14 @@ unsigned Ins_GetNumInssWithDegs (const char *SubQuery)
unsigned Ins_GetNumInssWithCrss (const char *SubQuery) unsigned Ins_GetNumInssWithCrss (const char *SubQuery)
{ {
/***** Get number of institutions with courses from database *****/ /***** Get number of institutions with courses from database *****/
DB_BuildQuery ("SELECT COUNT(DISTINCT institutions.InsCod)" return
" FROM institutions,centres,degrees,courses" (unsigned) DB_QueryCOUNT ("can not get number of institutions with courses",
" WHERE %sinstitutions.InsCod=centres.InsCod" "SELECT COUNT(DISTINCT institutions.InsCod)"
" AND centres.CtrCod=degrees.CtrCod" " FROM institutions,centres,degrees,courses"
" AND degrees.DegCod=courses.DegCod", " WHERE %sinstitutions.InsCod=centres.InsCod"
SubQuery); " AND centres.CtrCod=degrees.CtrCod"
return (unsigned) DB_QueryCOUNT_new ("can not get number of institutions with courses"); " AND degrees.DegCod=courses.DegCod",
SubQuery);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2508,15 +2517,16 @@ 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)
{ {
/***** Get number of institutions with users from database *****/ /***** Get number of institutions with users from database *****/
DB_BuildQuery ("SELECT COUNT(DISTINCT institutions.InsCod)" return
" FROM institutions,centres,degrees,courses,crs_usr" (unsigned) DB_QueryCOUNT ("can not get number of institutions with users",
" WHERE %sinstitutions.InsCod=centres.InsCod" "SELECT COUNT(DISTINCT institutions.InsCod)"
" AND centres.CtrCod=degrees.CtrCod" " FROM institutions,centres,degrees,courses,crs_usr"
" AND degrees.DegCod=courses.DegCod" " WHERE %sinstitutions.InsCod=centres.InsCod"
" AND courses.CrsCod=crs_usr.CrsCod" " AND centres.CtrCod=degrees.CtrCod"
" AND crs_usr.Role=%u", " AND degrees.DegCod=courses.DegCod"
SubQuery,(unsigned) Role); " AND courses.CrsCod=crs_usr.CrsCod"
return (unsigned) DB_QueryCOUNT_new ("can not get number of institutions with users"); " AND crs_usr.Role=%u",
SubQuery,(unsigned) Role);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -630,9 +630,11 @@ static void Lnk_RenameLink (Cns_ShrtOrFullName_t ShrtOrFullName)
static bool Lnk_CheckIfLinkNameExists (const char *FieldName,const char *Name,long LnkCod) static bool Lnk_CheckIfLinkNameExists (const char *FieldName,const char *Name,long LnkCod)
{ {
/***** Get number of links with a name from database *****/ /***** Get number of links with a name from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM links WHERE %s='%s' AND LnkCod<>%ld", return (DB_QueryCOUNT ("can not check if the name of an institutional link"
FieldName,Name,LnkCod); " already existed",
return (DB_QueryCOUNT_new ("can not check if the name of an institutional link already existed") != 0); "SELECT COUNT(*) FROM links"
" WHERE %s='%s' AND LnkCod<>%ld",
FieldName,Name,LnkCod) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -361,9 +361,11 @@ static void Mai_GetMailDomain (const char *Email,char MailDomain[Cns_MAX_BYTES_E
static bool Mai_CheckIfMailDomainIsAllowedForNotif (const char MailDomain[Cns_MAX_BYTES_EMAIL_ADDRESS + 1]) static bool Mai_CheckIfMailDomainIsAllowedForNotif (const char MailDomain[Cns_MAX_BYTES_EMAIL_ADDRESS + 1])
{ {
/***** Get number of mail_domains with a name from database *****/ /***** Get number of mail_domains with a name from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM mail_domains WHERE Domain='%s'", return (DB_QueryCOUNT ("can not check if a mail domain"
MailDomain); " is allowed for notifications",
return (DB_QueryCOUNT_new ("can not check if a mail domain is allowed for notifications") != 0); "SELECT COUNT(*) FROM mail_domains"
" WHERE Domain='%s'",
MailDomain) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -694,10 +696,11 @@ static void Mai_RenameMailDomain (Cns_ShrtOrFullName_t ShrtOrFullName)
static bool Mai_CheckIfMailDomainNameExists (const char *FieldName,const char *Name,long MaiCod) static bool Mai_CheckIfMailDomainNameExists (const char *FieldName,const char *Name,long MaiCod)
{ {
/***** Get number of mail_domains with a name from database *****/ /***** Get number of mail_domains with a name from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM mail_domains" return (DB_QueryCOUNT ("can not check if the name"
" WHERE %s='%s' AND MaiCod<>%ld", " of a mail domain already existed",
FieldName,Name,MaiCod); "SELECT COUNT(*) FROM mail_domains"
return (DB_QueryCOUNT_new ("can not check if the name of a mail domain already existed") != 0); " WHERE %s='%s' AND MaiCod<>%ld",
FieldName,Name,MaiCod) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1631,11 +1634,11 @@ static void Mai_NewUsrEmail (struct UsrData *UsrDat,bool ItsMe)
bool Mai_UpdateEmailInDB (const struct UsrData *UsrDat,const char NewEmail[Cns_MAX_BYTES_EMAIL_ADDRESS + 1]) bool Mai_UpdateEmailInDB (const struct UsrData *UsrDat,const char NewEmail[Cns_MAX_BYTES_EMAIL_ADDRESS + 1])
{ {
/***** Check if the new email matches any of the confirmed emails of other users *****/ /***** Check if the new email matches any of the confirmed emails of other users *****/
DB_BuildQuery ("SELECT COUNT(*) FROM usr_emails" if (DB_QueryCOUNT ("can not check if email already existed",
" WHERE E_mail='%s' AND Confirmed='Y'" "SELECT COUNT(*) FROM usr_emails"
" AND UsrCod<>%ld", " WHERE E_mail='%s' AND Confirmed='Y'"
NewEmail,UsrDat->UsrCod); " AND UsrCod<>%ld",
if (DB_QueryCOUNT_new ("can not check if email already existed")) // An email of another user is the same that my email NewEmail,UsrDat->UsrCod)) // An email of another user is the same that my email
return false; // Don't update return false; // Don't update
/***** Delete email (not confirmed) for other users *****/ /***** Delete email (not confirmed) for other users *****/

View File

@ -1561,9 +1561,12 @@ void Msg_MoveUnusedMsgsContentToDeleted (void)
static bool Msg_CheckIfSentMsgIsDeleted (long MsgCod) static bool Msg_CheckIfSentMsgIsDeleted (long MsgCod)
{ {
/***** Get if the message code is in table of sent messages not deleted *****/ /***** Get if the message code is in table of sent messages not deleted *****/
DB_BuildQuery ("SELECT COUNT(*) FROM msg_snt" return (DB_QueryCOUNT ("can not check if a sent message is deleted",
" WHERE MsgCod=%ld",MsgCod); "SELECT COUNT(*) FROM msg_snt"
return (DB_QueryCOUNT_new ("can not check if a sent message is deleted") == 0); // The message has been deleted by its author when it is not present in table of sent messages undeleted " WHERE MsgCod=%ld",
MsgCod) == 0); // The message has been deleted
// by its author when it is not present
// in table of sent messages undeleted
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1573,9 +1576,13 @@ static bool Msg_CheckIfSentMsgIsDeleted (long MsgCod)
static bool Msg_CheckIfReceivedMsgIsDeletedForAllItsRecipients (long MsgCod) static bool Msg_CheckIfReceivedMsgIsDeletedForAllItsRecipients (long MsgCod)
{ {
/***** Get if the message code is in table of received messages not deleted *****/ /***** Get if the message code is in table of received messages not deleted *****/
DB_BuildQuery ("SELECT COUNT(*) FROM msg_rcv" return (DB_QueryCOUNT ("can not check if a received message"
" WHERE MsgCod=%ld",MsgCod); " is deleted by all recipients",
return (DB_QueryCOUNT_new ("can not check if a received message is deleted by all recipients") == 0); // The message has been deleted by all its recipients when it is not present in table of received messages undeleted "SELECT COUNT(*) FROM msg_rcv"
" WHERE MsgCod=%ld",
MsgCod) == 0); // The message has been deleted
// by all its recipients when it is not present
// in table of received messages undeleted
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1585,6 +1592,7 @@ static bool Msg_CheckIfReceivedMsgIsDeletedForAllItsRecipients (long MsgCod)
static unsigned Msg_GetNumUnreadMsgs (long FilterCrsCod,const char *FilterFromToSubquery) static unsigned Msg_GetNumUnreadMsgs (long FilterCrsCod,const char *FilterFromToSubquery)
{ {
char SubQuery[Msg_MAX_BYTES_MESSAGES_QUERY + 1]; char SubQuery[Msg_MAX_BYTES_MESSAGES_QUERY + 1];
unsigned NumMsgs;
/***** Get number of unread messages from database *****/ /***** Get number of unread messages from database *****/
if (FilterCrsCod >= 0) // If origin course selected if (FilterCrsCod >= 0) // If origin course selected
@ -1622,15 +1630,20 @@ static unsigned Msg_GetNumUnreadMsgs (long FilterCrsCod,const char *FilterFromTo
} }
if (Gbl.Msg.FilterContent[0]) if (Gbl.Msg.FilterContent[0])
DB_BuildQuery ("SELECT COUNT(*) FROM msg_content" NumMsgs =
" WHERE MsgCod IN (%s)" (unsigned) DB_QueryCOUNT ("can not get number of unread messages",
" AND MATCH (Subject,Content) AGAINST ('%s')", "SELECT COUNT(*) FROM msg_content"
SubQuery, " WHERE MsgCod IN (%s)"
Gbl.Msg.FilterContent); " AND MATCH (Subject,Content) AGAINST ('%s')",
SubQuery,
Gbl.Msg.FilterContent);
else else
DB_BuildQuery ("SELECT COUNT(*) FROM (%s) AS T", NumMsgs =
SubQuery); (unsigned) DB_QueryCOUNT ("can not get number of unread messages",
return (unsigned) DB_QueryCOUNT_new ("can not get number of unread messages"); "SELECT COUNT(*) FROM (%s) AS T",
SubQuery);
return NumMsgs;
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1844,9 +1857,10 @@ static void Msg_ShowSentOrReceivedMessages (void)
static unsigned long Msg_GetNumUsrsBannedByMe (void) static unsigned long Msg_GetNumUsrsBannedByMe (void)
{ {
/***** Get number of users I have banned *****/ /***** Get number of users I have banned *****/
DB_BuildQuery ("SELECT COUNT(*) FROM msg_banned WHERE ToUsrCod=%ld", return DB_QueryCOUNT ("can not get number of users you have banned",
Gbl.Usrs.Me.UsrDat.UsrCod); "SELECT COUNT(*) FROM msg_banned"
return DB_QueryCOUNT_new ("can not get number of users you have banned"); " WHERE ToUsrCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2044,11 +2058,14 @@ static unsigned long Msg_GetSentOrReceivedMsgs (long UsrCod,
unsigned Msg_GetNumMsgsSentByTchsCrs (long CrsCod) unsigned Msg_GetNumMsgsSentByTchsCrs (long CrsCod)
{ {
/***** Get the number of unique messages sent by any teacher from this course *****/ /***** Get the number of unique messages sent by any teacher from this course *****/
DB_BuildQuery ("SELECT COUNT(*) FROM msg_snt,crs_usr" return
" WHERE msg_snt.CrsCod=%ld AND crs_usr.CrsCod=%ld AND crs_usr.Role=%u" (unsigned) DB_QueryCOUNT ("can not get the number of messages"
" AND msg_snt.UsrCod=crs_usr.UsrCod", " sent by teachers",
CrsCod,CrsCod,(unsigned) Rol_TCH); "SELECT COUNT(*) FROM msg_snt,crs_usr"
return (unsigned) DB_QueryCOUNT_new ("can not get the number of messages sent by teachers"); " WHERE msg_snt.CrsCod=%ld"
" AND crs_usr.CrsCod=%ld AND crs_usr.Role=%u"
" AND msg_snt.UsrCod=crs_usr.UsrCod",
CrsCod,CrsCod,(unsigned) Rol_TCH);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2058,13 +2075,13 @@ unsigned Msg_GetNumMsgsSentByTchsCrs (long CrsCod)
unsigned long Msg_GetNumMsgsSentByUsr (long UsrCod) unsigned long Msg_GetNumMsgsSentByUsr (long UsrCod)
{ {
/***** Get the number of unique messages sent by any teacher from this course *****/ /***** Get the number of unique messages sent by any teacher from this course *****/
DB_BuildQuery ("SELECT" return DB_QueryCOUNT ("can not get the number of messages sent by a user",
" (SELECT COUNT(*) FROM msg_snt WHERE UsrCod=%ld)" "SELECT"
" +" " (SELECT COUNT(*) FROM msg_snt WHERE UsrCod=%ld)"
" (SELECT COUNT(*) FROM msg_snt_deleted WHERE UsrCod=%ld)", " +"
UsrCod, " (SELECT COUNT(*) FROM msg_snt_deleted WHERE UsrCod=%ld)",
UsrCod); UsrCod,
return DB_QueryCOUNT_new ("can not get the number of messages sent by a user"); UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2075,6 +2092,7 @@ unsigned long Msg_GetNumMsgsSentByUsr (long UsrCod)
unsigned Msg_GetNumMsgsSent (Sco_Scope_t Scope,Msg_Status_t MsgStatus) unsigned Msg_GetNumMsgsSent (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
{ {
const char *Table = "msg_snt"; const char *Table = "msg_snt";
unsigned NumMsgs = 0; // Initialized to avoid warning
/***** Get the number of messages sent from this location /***** Get the number of messages sent from this location
(all the platform, current degree or current course) from database *****/ (all the platform, current degree or current course) from database *****/
@ -2091,63 +2109,76 @@ unsigned Msg_GetNumMsgsSent (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
switch (Scope) switch (Scope)
{ {
case Sco_SCOPE_SYS: case Sco_SCOPE_SYS:
DB_BuildQuery ("SELECT COUNT(*) FROM %s", NumMsgs =
Table); (unsigned) DB_QueryCOUNT ("can not get number of sent messages",
"SELECT COUNT(*) FROM %s",
Table);
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
DB_BuildQuery ("SELECT COUNT(*)" NumMsgs =
" FROM institutions,centres,degrees,courses,%s" (unsigned) DB_QueryCOUNT ("can not get number of sent messages",
" WHERE institutions.CtyCod=%ld" "SELECT COUNT(*)"
" AND institutions.InsCod=centres.InsCod" " FROM institutions,centres,degrees,courses,%s"
" AND centres.CtrCod=degrees.CtrCod" " WHERE institutions.CtyCod=%ld"
" AND degrees.DegCod=courses.DegCod" " AND institutions.InsCod=centres.InsCod"
" AND courses.CrsCod=%s.CrsCod", " AND centres.CtrCod=degrees.CtrCod"
Table, " AND degrees.DegCod=courses.DegCod"
Gbl.CurrentCty.Cty.CtyCod, " AND courses.CrsCod=%s.CrsCod",
Table); Table,
Gbl.CurrentCty.Cty.CtyCod,
Table);
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT COUNT(*)" NumMsgs =
" FROM centres,degrees,courses,%s" (unsigned) DB_QueryCOUNT ("can not get number of sent messages",
" WHERE centres.InsCod=%ld" "SELECT COUNT(*)"
" AND centres.CtrCod=degrees.CtrCod" " FROM centres,degrees,courses,%s"
" AND degrees.DegCod=courses.DegCod" " WHERE centres.InsCod=%ld"
" AND courses.CrsCod=%s.CrsCod", " AND centres.CtrCod=degrees.CtrCod"
Table, " AND degrees.DegCod=courses.DegCod"
Gbl.CurrentIns.Ins.InsCod, " AND courses.CrsCod=%s.CrsCod",
Table); Table,
Gbl.CurrentIns.Ins.InsCod,
Table);
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
DB_BuildQuery ("SELECT COUNT(*)" NumMsgs =
" FROM degrees,courses,%s" (unsigned) DB_QueryCOUNT ("can not get number of sent messages",
" WHERE degrees.CtrCod=%ld" "SELECT COUNT(*)"
" AND degrees.DegCod=courses.DegCod" " FROM degrees,courses,%s"
" AND courses.CrsCod=%s.CrsCod", " WHERE degrees.CtrCod=%ld"
Table, " AND degrees.DegCod=courses.DegCod"
Gbl.CurrentCtr.Ctr.CtrCod, " AND courses.CrsCod=%s.CrsCod",
Table); Table,
Gbl.CurrentCtr.Ctr.CtrCod,
Table);
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
DB_BuildQuery ("SELECT COUNT(*)" NumMsgs =
" FROM courses,%s" (unsigned) DB_QueryCOUNT ("can not get number of sent messages",
" WHERE courses.DegCod=%ld" "SELECT COUNT(*)"
" AND courses.CrsCod=%s.CrsCod", " FROM courses,%s"
Table, " WHERE courses.DegCod=%ld"
Gbl.CurrentDeg.Deg.DegCod, " AND courses.CrsCod=%s.CrsCod",
Table); Table,
Gbl.CurrentDeg.Deg.DegCod,
Table);
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT COUNT(*)" NumMsgs =
" FROM %s" (unsigned) DB_QueryCOUNT ("can not get number of sent messages",
" WHERE CrsCod=%ld", "SELECT COUNT(*)"
Table, " FROM %s"
Gbl.CurrentCrs.Crs.CrsCod); " WHERE CrsCod=%ld",
Table,
Gbl.CurrentCrs.Crs.CrsCod);
break; break;
default: default:
Lay_WrongScopeExit (); Lay_WrongScopeExit ();
break; break;
} }
return (unsigned) DB_QueryCOUNT_new ("can not get number of sent messages");
return NumMsgs;
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2158,6 +2189,7 @@ unsigned Msg_GetNumMsgsSent (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus) unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
{ {
char *Table; char *Table;
unsigned NumMsgs = 0; // Initialized to avoid warning
/***** Get the number of unique messages sent from this location /***** Get the number of unique messages sent from this location
(all the platform, current degree or current course) from database *****/ (all the platform, current degree or current course) from database *****/
@ -2170,63 +2202,81 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
switch (Scope) switch (Scope)
{ {
case Sco_SCOPE_SYS: case Sco_SCOPE_SYS:
DB_BuildQuery ("SELECT COUNT(*) FROM %s", NumMsgs =
Table); (unsigned) DB_QueryCOUNT ("can not get number"
" of received messages",
"SELECT COUNT(*) FROM %s",
Table);
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
DB_BuildQuery ("SELECT COUNT(*)" NumMsgs =
" FROM institutions,centres,degrees,courses,%s,msg_snt" (unsigned) DB_QueryCOUNT ("can not get number"
" WHERE institutions.CtyCod=%ld" " of received messages",
" AND institutions.InsCod=centres.InsCod" "SELECT COUNT(*)"
" AND centres.CtrCod=degrees.CtrCod" " FROM institutions,centres,degrees,courses,%s,msg_snt"
" AND degrees.DegCod=courses.DegCod" " WHERE institutions.CtyCod=%ld"
" AND courses.CrsCod=msg_snt.CrsCod" " AND institutions.InsCod=centres.InsCod"
" AND msg_snt.MsgCod=%s.MsgCod", " AND centres.CtrCod=degrees.CtrCod"
Table, " AND degrees.DegCod=courses.DegCod"
Gbl.CurrentCty.Cty.CtyCod, " AND courses.CrsCod=msg_snt.CrsCod"
Table); " AND msg_snt.MsgCod=%s.MsgCod",
Table,
Gbl.CurrentCty.Cty.CtyCod,
Table);
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT COUNT(*)" NumMsgs =
" FROM centres,degrees,courses,%s,msg_snt" (unsigned) DB_QueryCOUNT ("can not get number"
" WHERE centres.InsCod=%ld" " of received messages",
" AND centres.CtrCod=degrees.CtrCod" "SELECT COUNT(*)"
" AND degrees.DegCod=courses.DegCod" " FROM centres,degrees,courses,%s,msg_snt"
" AND courses.CrsCod=msg_snt.CrsCod" " WHERE centres.InsCod=%ld"
" AND msg_snt.MsgCod=%s.MsgCod", " AND centres.CtrCod=degrees.CtrCod"
Table, " AND degrees.DegCod=courses.DegCod"
Gbl.CurrentIns.Ins.InsCod, " AND courses.CrsCod=msg_snt.CrsCod"
Table); " AND msg_snt.MsgCod=%s.MsgCod",
Table,
Gbl.CurrentIns.Ins.InsCod,
Table);
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
DB_BuildQuery ("SELECT COUNT(*)" NumMsgs =
" FROM degrees,courses,%s,msg_snt" (unsigned) DB_QueryCOUNT ("can not get number"
" WHERE degrees.CtrCod=%ld" " of received messages",
" AND degrees.DegCod=courses.DegCod" "SELECT COUNT(*)"
" AND courses.CrsCod=msg_snt.CrsCod" " FROM degrees,courses,%s,msg_snt"
" AND msg_snt.MsgCod=%s.MsgCod", " WHERE degrees.CtrCod=%ld"
Table, " AND degrees.DegCod=courses.DegCod"
Gbl.CurrentCtr.Ctr.CtrCod, " AND courses.CrsCod=msg_snt.CrsCod"
Table); " AND msg_snt.MsgCod=%s.MsgCod",
Table,
Gbl.CurrentCtr.Ctr.CtrCod,
Table);
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
DB_BuildQuery ("SELECT COUNT(*)" NumMsgs =
" FROM courses,%s,msg_snt" (unsigned) DB_QueryCOUNT ("can not get number"
" WHERE courses.DegCod=%ld" " of received messages",
" AND courses.CrsCod=msg_snt.CrsCod" "SELECT COUNT(*)"
" AND msg_snt.MsgCod=%s.MsgCod", " FROM courses,%s,msg_snt"
Table, " WHERE courses.DegCod=%ld"
Gbl.CurrentDeg.Deg.DegCod, " AND courses.CrsCod=msg_snt.CrsCod"
Table); " AND msg_snt.MsgCod=%s.MsgCod",
Table,
Gbl.CurrentDeg.Deg.DegCod,
Table);
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT COUNT(*)" NumMsgs =
" FROM msg_snt,%s" (unsigned) DB_QueryCOUNT ("can not get number"
" WHERE msg_snt.CrsCod=%ld" " of received messages",
" AND msg_snt.MsgCod=%s.MsgCod", "SELECT COUNT(*)"
Table, " FROM msg_snt,%s"
Gbl.CurrentCrs.Crs.CrsCod, " WHERE msg_snt.CrsCod=%ld"
Table); " AND msg_snt.MsgCod=%s.MsgCod",
Table,
Gbl.CurrentCrs.Crs.CrsCod,
Table);
break; break;
default: default:
Lay_WrongScopeExit (); Lay_WrongScopeExit ();
@ -2237,114 +2287,132 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
switch (Scope) switch (Scope)
{ {
case Sco_SCOPE_SYS: case Sco_SCOPE_SYS:
DB_BuildQuery ("SELECT " NumMsgs =
"(SELECT COUNT(*)" (unsigned) DB_QueryCOUNT ("can not get number"
" FROM msg_rcv" " of received messages",
" WHERE Notified='Y')" "SELECT "
" + " "(SELECT COUNT(*)"
"(SELECT COUNT(*)" " FROM msg_rcv"
" FROM msg_rcv_deleted" " WHERE Notified='Y')"
" WHERE Notified='Y')"); " + "
"(SELECT COUNT(*)"
" FROM msg_rcv_deleted"
" WHERE Notified='Y')");
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
DB_BuildQuery ("SELECT " NumMsgs =
"(SELECT COUNT(*)" (unsigned) DB_QueryCOUNT ("can not get number"
" FROM institutions,centres,degrees,courses,msg_snt,msg_rcv" " of received messages",
" WHERE institutions.CtyCod=%ld" "SELECT "
" AND institutions.InsCod=centres.InsCod" "(SELECT COUNT(*)"
" AND centres.CtrCod=degrees.CtrCod" " FROM institutions,centres,degrees,courses,msg_snt,msg_rcv"
" AND degrees.DegCod=courses.DegCod" " WHERE institutions.CtyCod=%ld"
" AND courses.CrsCod=msg_snt.CrsCod" " AND institutions.InsCod=centres.InsCod"
" AND msg_snt.MsgCod=msg_rcv.MsgCod" " AND centres.CtrCod=degrees.CtrCod"
" AND msg_rcv.Notified='Y')" " AND degrees.DegCod=courses.DegCod"
" + " " AND courses.CrsCod=msg_snt.CrsCod"
"(SELECT COUNT(*)" " AND msg_snt.MsgCod=msg_rcv.MsgCod"
" FROM institutions,centres,degrees,courses,msg_snt,msg_rcv_deleted" " AND msg_rcv.Notified='Y')"
" WHERE institutions.CtyCod=%ld" " + "
" AND institutions.InsCod=centres.InsCod" "(SELECT COUNT(*)"
" AND centres.CtrCod=degrees.CtrCod" " FROM institutions,centres,degrees,courses,msg_snt,msg_rcv_deleted"
" AND degrees.DegCod=courses.DegCod" " WHERE institutions.CtyCod=%ld"
" AND courses.CrsCod=msg_snt.CrsCod" " AND institutions.InsCod=centres.InsCod"
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod" " AND centres.CtrCod=degrees.CtrCod"
" AND msg_rcv_deleted.Notified='Y')", " AND degrees.DegCod=courses.DegCod"
Gbl.CurrentCty.Cty.CtyCod, " AND courses.CrsCod=msg_snt.CrsCod"
Gbl.CurrentCty.Cty.CtyCod); " AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
" AND msg_rcv_deleted.Notified='Y')",
Gbl.CurrentCty.Cty.CtyCod,
Gbl.CurrentCty.Cty.CtyCod);
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT " NumMsgs =
"(SELECT COUNT(*)" (unsigned) DB_QueryCOUNT ("can not get number"
" FROM centres,degrees,courses,msg_snt,msg_rcv" " of received messages",
" WHERE centres.InsCod=%ld" "SELECT "
" AND centres.CtrCod=degrees.CtrCod" "(SELECT COUNT(*)"
" AND degrees.DegCod=courses.DegCod" " FROM centres,degrees,courses,msg_snt,msg_rcv"
" AND courses.CrsCod=msg_snt.CrsCod" " WHERE centres.InsCod=%ld"
" AND msg_snt.MsgCod=msg_rcv.MsgCod" " AND centres.CtrCod=degrees.CtrCod"
" AND msg_rcv.Notified='Y')" " AND degrees.DegCod=courses.DegCod"
" + " " AND courses.CrsCod=msg_snt.CrsCod"
"(SELECT COUNT(*)" " AND msg_snt.MsgCod=msg_rcv.MsgCod"
" FROM centres,degrees,courses,msg_snt,msg_rcv_deleted" " AND msg_rcv.Notified='Y')"
" WHERE centres.InsCod=%ld" " + "
" AND centres.CtrCod=degrees.CtrCod" "(SELECT COUNT(*)"
" AND degrees.DegCod=courses.DegCod" " FROM centres,degrees,courses,msg_snt,msg_rcv_deleted"
" AND courses.CrsCod=msg_snt.CrsCod" " WHERE centres.InsCod=%ld"
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod" " AND centres.CtrCod=degrees.CtrCod"
" AND msg_rcv_deleted.Notified='Y')", " AND degrees.DegCod=courses.DegCod"
Gbl.CurrentIns.Ins.InsCod, " AND courses.CrsCod=msg_snt.CrsCod"
Gbl.CurrentIns.Ins.InsCod); " AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
" AND msg_rcv_deleted.Notified='Y')",
Gbl.CurrentIns.Ins.InsCod,
Gbl.CurrentIns.Ins.InsCod);
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
DB_BuildQuery ("SELECT " NumMsgs =
"(SELECT COUNT(*)" (unsigned) DB_QueryCOUNT ("can not get number"
" FROM degrees,courses,msg_snt,msg_rcv" " of received messages",
" WHERE degrees.CtrCod=%ld" "SELECT "
" AND degrees.DegCod=courses.DegCod" "(SELECT COUNT(*)"
" AND courses.CrsCod=msg_snt.CrsCod" " FROM degrees,courses,msg_snt,msg_rcv"
" AND msg_snt.MsgCod=msg_rcv.MsgCod" " WHERE degrees.CtrCod=%ld"
" AND msg_rcv.Notified='Y')" " AND degrees.DegCod=courses.DegCod"
" + " " AND courses.CrsCod=msg_snt.CrsCod"
"(SELECT COUNT(*)" " AND msg_snt.MsgCod=msg_rcv.MsgCod"
" FROM degrees,courses,msg_snt,msg_rcv_deleted" " AND msg_rcv.Notified='Y')"
" WHERE degrees.CtrCod=%ld" " + "
" AND degrees.DegCod=courses.DegCod" "(SELECT COUNT(*)"
" AND courses.CrsCod=msg_snt.CrsCod" " FROM degrees,courses,msg_snt,msg_rcv_deleted"
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod" " WHERE degrees.CtrCod=%ld"
" AND msg_rcv_deleted.Notified='Y')", " AND degrees.DegCod=courses.DegCod"
Gbl.CurrentCtr.Ctr.CtrCod, " AND courses.CrsCod=msg_snt.CrsCod"
Gbl.CurrentCtr.Ctr.CtrCod); " AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
" AND msg_rcv_deleted.Notified='Y')",
Gbl.CurrentCtr.Ctr.CtrCod,
Gbl.CurrentCtr.Ctr.CtrCod);
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
DB_BuildQuery ("SELECT " NumMsgs =
"(SELECT COUNT(*)" (unsigned) DB_QueryCOUNT ("can not get number"
" FROM courses,msg_snt,msg_rcv" " of received messages",
" WHERE courses.DegCod=%ld" "SELECT "
" AND courses.CrsCod=msg_snt.CrsCod" "(SELECT COUNT(*)"
" AND msg_snt.MsgCod=msg_rcv.MsgCod" " FROM courses,msg_snt,msg_rcv"
" AND msg_rcv.Notified='Y')" " WHERE courses.DegCod=%ld"
" + " " AND courses.CrsCod=msg_snt.CrsCod"
"(SELECT COUNT(*)" " AND msg_snt.MsgCod=msg_rcv.MsgCod"
" FROM courses,msg_snt,msg_rcv_deleted" " AND msg_rcv.Notified='Y')"
" WHERE courses.DegCod=%ld" " + "
" AND courses.CrsCod=msg_snt.CrsCod" "(SELECT COUNT(*)"
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod" " FROM courses,msg_snt,msg_rcv_deleted"
" AND msg_rcv_deleted.Notified='Y')", " WHERE courses.DegCod=%ld"
Gbl.CurrentDeg.Deg.DegCod, " AND courses.CrsCod=msg_snt.CrsCod"
Gbl.CurrentDeg.Deg.DegCod); " AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
" AND msg_rcv_deleted.Notified='Y')",
Gbl.CurrentDeg.Deg.DegCod,
Gbl.CurrentDeg.Deg.DegCod);
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT " NumMsgs =
"(SELECT COUNT(*)" (unsigned) DB_QueryCOUNT ("can not get number"
" FROM msg_snt,msg_rcv" " of received messages",
" WHERE msg_snt.CrsCod=%ld" "SELECT "
" AND msg_snt.MsgCod=msg_rcv.MsgCod" "(SELECT COUNT(*)"
" AND msg_rcv.Notified='Y')" " FROM msg_snt,msg_rcv"
" + " " WHERE msg_snt.CrsCod=%ld"
"(SELECT COUNT(*)" " AND msg_snt.MsgCod=msg_rcv.MsgCod"
" FROM msg_snt,msg_rcv_deleted" " AND msg_rcv.Notified='Y')"
" WHERE msg_snt.CrsCod=%ld" " + "
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod" "(SELECT COUNT(*)"
" AND msg_rcv_deleted.Notified='Y')", " FROM msg_snt,msg_rcv_deleted"
Gbl.CurrentCrs.Crs.CrsCod, " WHERE msg_snt.CrsCod=%ld"
Gbl.CurrentCrs.Crs.CrsCod); " AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
" AND msg_rcv_deleted.Notified='Y')",
Gbl.CurrentCrs.Crs.CrsCod,
Gbl.CurrentCrs.Crs.CrsCod);
break; break;
default: default:
Lay_WrongScopeExit (); Lay_WrongScopeExit ();
@ -2352,7 +2420,8 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
} }
break; break;
} }
return (unsigned) DB_QueryCOUNT_new ("can not get number of received messages");
return NumMsgs;
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3378,12 +3447,13 @@ static void Msg_WriteMsgTo (long MsgCod)
}; };
/***** Get number of recipients of a message from database *****/ /***** Get number of recipients of a message from database *****/
DB_BuildQuery ("SELECT " NumRecipientsTotal =
"(SELECT COUNT(*) FROM msg_rcv WHERE MsgCod=%ld)" (unsigned) DB_QueryCOUNT ("can not get number of recipients",
" + " "SELECT "
"(SELECT COUNT(*) FROM msg_rcv_deleted WHERE MsgCod=%ld)", "(SELECT COUNT(*) FROM msg_rcv WHERE MsgCod=%ld)"
MsgCod,MsgCod); " + "
NumRecipientsTotal = (unsigned) DB_QueryCOUNT_new ("can not get number of recipients"); "(SELECT COUNT(*) FROM msg_rcv_deleted WHERE MsgCod=%ld)",
MsgCod,MsgCod);
/***** Get recipients of a message from database *****/ /***** Get recipients of a message from database *****/
NumRecipientsKnown = NumRecipientsKnown =
@ -3730,10 +3800,10 @@ static void Msg_UnbanSender (void)
static bool Msg_CheckIfUsrIsBanned (long FromUsrCod,long ToUsrCod) static bool Msg_CheckIfUsrIsBanned (long FromUsrCod,long ToUsrCod)
{ {
/***** Get if FromUsrCod is banned by ToUsrCod *****/ /***** Get if FromUsrCod is banned by ToUsrCod *****/
DB_BuildQuery ("SELECT COUNT(*) FROM msg_banned" return (DB_QueryCOUNT ("can not check if a user is banned",
" WHERE FromUsrCod=%ld AND ToUsrCod=%ld", "SELECT COUNT(*) FROM msg_banned"
FromUsrCod,ToUsrCod); " WHERE FromUsrCod=%ld AND ToUsrCod=%ld",
return (DB_QueryCOUNT_new ("can not check if a user is banned") != 0); FromUsrCod,ToUsrCod) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -580,16 +580,15 @@ static void Nck_UpdateUsrNick (struct UsrData *UsrDat)
else if (strcasecmp (UsrDat->Nickname,NewNicknameWithoutArroba)) // User's nickname does not match, not even case insensitive, the new nickname else if (strcasecmp (UsrDat->Nickname,NewNicknameWithoutArroba)) // User's nickname does not match, not even case insensitive, the new nickname
{ {
/***** Check if the new nickname matches any of my old nicknames *****/ /***** Check if the new nickname matches any of my old nicknames *****/
DB_BuildQuery ("SELECT COUNT(*) FROM usr_nicknames" if (!DB_QueryCOUNT ("can not check if nickname already existed",
" WHERE UsrCod=%ld AND Nickname='%s'", "SELECT COUNT(*) FROM usr_nicknames"
UsrDat->UsrCod,NewNicknameWithoutArroba); " WHERE UsrCod=%ld AND Nickname='%s'",
if (!DB_QueryCOUNT_new ("can not check if nickname already existed")) // No matches UsrDat->UsrCod,NewNicknameWithoutArroba)) // No matches
{
/***** Check if the new nickname matches any of the nicknames of other users *****/ /***** Check if the new nickname matches any of the nicknames of other users *****/
DB_BuildQuery ("SELECT COUNT(*) FROM usr_nicknames" if (DB_QueryCOUNT ("can not check if nickname already existed",
" WHERE Nickname='%s' AND UsrCod<>%ld", "SELECT COUNT(*) FROM usr_nicknames"
NewNicknameWithoutArroba,UsrDat->UsrCod); " WHERE Nickname='%s' AND UsrCod<>%ld",
if (DB_QueryCOUNT_new ("can not check if nickname already existed")) // A nickname of another user is the same that user's nickname NewNicknameWithoutArroba,UsrDat->UsrCod)) // A nickname of another user is the same that user's nickname
{ {
Gbl.Alert.Type = Ale_WARNING; Gbl.Alert.Type = Ale_WARNING;
Gbl.Alert.Section = Nck_NICKNAME_SECTION_ID; Gbl.Alert.Section = Nck_NICKNAME_SECTION_ID;
@ -597,7 +596,6 @@ static void Nck_UpdateUsrNick (struct UsrData *UsrDat)
Txt_The_nickname_X_had_been_registered_by_another_user, Txt_The_nickname_X_had_been_registered_by_another_user,
NewNicknameWithoutArroba); NewNicknameWithoutArroba);
} }
}
} }
if (Gbl.Alert.Type == Ale_NONE) if (Gbl.Alert.Type == Ale_NONE)
{ {

View File

@ -2115,11 +2115,11 @@ void Ntf_WriteNumberOfNewNtfs (void)
static unsigned Ntf_GetNumberOfAllMyUnseenNtfs (void) static unsigned Ntf_GetNumberOfAllMyUnseenNtfs (void)
{ {
/***** Get number of places with a name from database *****/ /***** Get number of places with a name from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM notif" return DB_QueryCOUNT ("can not get number of unseen notifications",
" WHERE ToUsrCod=%ld AND (Status & %u)=0", "SELECT COUNT(*) FROM notif"
Gbl.Usrs.Me.UsrDat.UsrCod, " WHERE ToUsrCod=%ld AND (Status & %u)=0",
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED)); Gbl.Usrs.Me.UsrDat.UsrCod,
return DB_QueryCOUNT_new ("can not get number of unseen notifications"); (unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED));
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2129,13 +2129,13 @@ static unsigned Ntf_GetNumberOfAllMyUnseenNtfs (void)
static unsigned Ntf_GetNumberOfMyNewUnseenNtfs (void) static unsigned Ntf_GetNumberOfMyNewUnseenNtfs (void)
{ {
/***** Get number of places with a name from database *****/ /***** Get number of places with a name from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM notif" return DB_QueryCOUNT ("can not get number of unseen notifications",
" WHERE ToUsrCod=%ld AND (Status & %u)=0" "SELECT COUNT(*) FROM notif"
" AND TimeNotif>FROM_UNIXTIME(%ld)", " WHERE ToUsrCod=%ld AND (Status & %u)=0"
Gbl.Usrs.Me.UsrDat.UsrCod, " AND TimeNotif>FROM_UNIXTIME(%ld)",
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED), Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Usrs.Me.UsrLast.LastAccNotif); (unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED),
return DB_QueryCOUNT_new ("can not get number of unseen notifications"); Gbl.Usrs.Me.UsrLast.LastAccNotif);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -574,18 +574,17 @@ static bool Pwd_CheckIfPasswdIsUsrIDorName (const char *PlainPassword)
bool Found; bool Found;
/***** Get if password is found in user's ID from database *****/ /***** Get if password is found in user's ID from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM usr_IDs WHERE UsrID='%s'", Found = (DB_QueryCOUNT ("can not check if a password matches a user's ID",
PlainPassword); "SELECT COUNT(*) FROM usr_IDs WHERE UsrID='%s'",
Found = (DB_QueryCOUNT_new ("can not check if a password matches a user's ID") != 0); PlainPassword) != 0);
/***** Get if password is found in first name or surnames of anybody, from database *****/ /***** Get if password is found in first name or surnames of anybody, from database *****/
if (!Found) if (!Found)
{ Found = (DB_QueryCOUNT ("can not check if a password matches"
DB_BuildQuery ("SELECT COUNT(*) FROM usr_data" " a first name or a surname",
" WHERE FirstName='%s' OR Surname1='%s' OR Surname2='%s'", "SELECT COUNT(*) FROM usr_data"
PlainPassword,PlainPassword,PlainPassword); " WHERE FirstName='%s' OR Surname1='%s' OR Surname2='%s'",
Found = (DB_QueryCOUNT_new ("can not check if a password matches a first name or a surname") != 0); PlainPassword,PlainPassword,PlainPassword) != 0);
}
return Found; return Found;
} }
@ -596,17 +595,30 @@ static bool Pwd_CheckIfPasswdIsUsrIDorName (const char *PlainPassword)
static unsigned Pwd_GetNumOtherUsrsWhoUseThisPassword (const char *EncryptedPassword,long UsrCod) static unsigned Pwd_GetNumOtherUsrsWhoUseThisPassword (const char *EncryptedPassword,long UsrCod)
{ {
/***** Get number of other users who use a password from database *****/ unsigned NumUsrs;
/* Query database */ char *SubQuery;
/***** Build subquery *****/
if (UsrCod > 0) if (UsrCod > 0)
DB_BuildQuery ("SELECT COUNT(*) FROM usr_data" {
" WHERE Password='%s' AND UsrCod<>%ld", if (asprintf (&SubQuery," AND UsrCod<>%ld",UsrCod) < 0)
EncryptedPassword,UsrCod); Lay_NotEnoughMemoryExit ();
}
else else
DB_BuildQuery ("SELECT COUNT(*) FROM usr_data" SubQuery = "";
" WHERE Password='%s'",
EncryptedPassword); /***** Get number of other users who use a password from database *****/
return (unsigned) DB_QueryCOUNT_new ("can not check if a password is trivial"); NumUsrs =
(unsigned) DB_QueryCOUNT ("can not check if a password is trivial",
"SELECT COUNT(*) FROM usr_data"
" WHERE Password='%s'%s",
EncryptedPassword,SubQuery);
/***** Free subquery *****/
if (UsrCod > 0)
free ((void *) SubQuery);
return NumUsrs;
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -715,10 +715,13 @@ static void Plc_RenamePlace (Cns_ShrtOrFullName_t ShrtOrFullName)
static bool Plc_CheckIfPlaceNameExists (const char *FieldName,const char *Name,long PlcCod) static bool Plc_CheckIfPlaceNameExists (const char *FieldName,const char *Name,long PlcCod)
{ {
/***** Get number of places with a name from database *****/ /***** Get number of places with a name from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM places" return (DB_QueryCOUNT ("can not check if the name of a place"
" WHERE InsCod=%ld AND %s='%s' AND PlcCod<>%ld", " already existed",
Gbl.CurrentIns.Ins.InsCod,FieldName,Name,PlcCod); "SELECT COUNT(*) FROM places"
return (DB_QueryCOUNT_new ("can not check if the name of a place already existed") != 0); " WHERE InsCod=%ld"
" AND %s='%s' AND PlcCod<>%ld",
Gbl.CurrentIns.Ins.InsCod,
FieldName,Name,PlcCod) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -593,10 +593,11 @@ void Plg_RenamePlugin (void)
static bool Plg_CheckIfPluginNameExists (const char *Name,long PlgCod) static bool Plg_CheckIfPluginNameExists (const char *Name,long PlgCod)
{ {
/***** Get number of plugins with a name from database *****/ /***** Get number of plugins with a name from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM plugins" return (DB_QueryCOUNT ("can not check if the name of a plugin"
" WHERE Name='%s' AND PlgCod<>%ld", " already existed",
Name,PlgCod); "SELECT COUNT(*) FROM plugins"
return (DB_QueryCOUNT_new ("can not check if the name of a plugin already existed") != 0); " WHERE Name='%s' AND PlgCod<>%ld",
Name,PlgCod) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -681,12 +681,12 @@ static unsigned long Prf_GetRankingFigure (long UsrCod,const char *FieldName)
{ {
/***** Select number of rows with figure /***** Select number of rows with figure
greater than the figure of this user *****/ greater than the figure of this user *****/
DB_BuildQuery ("SELECT COUNT(*)+1 FROM usr_figures" return DB_QueryCOUNT ("can not get ranking using a figure",
" WHERE UsrCod<>%ld" // Really not necessary here "SELECT COUNT(*)+1 FROM usr_figures"
" AND %s>" " WHERE UsrCod<>%ld" // Really not necessary here
"(SELECT %s FROM usr_figures WHERE UsrCod=%ld)", " AND %s>"
UsrCod,FieldName,FieldName,UsrCod); "(SELECT %s FROM usr_figures WHERE UsrCod=%ld)",
return DB_QueryCOUNT_new ("can not get ranking using a figure"); UsrCod,FieldName,FieldName,UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -696,8 +696,9 @@ static unsigned long Prf_GetRankingFigure (long UsrCod,const char *FieldName)
static unsigned long Prf_GetNumUsrsWithFigure (const char *FieldName) static unsigned long Prf_GetNumUsrsWithFigure (const char *FieldName)
{ {
/***** Select number of rows with values already calculated *****/ /***** Select number of rows with values already calculated *****/
DB_BuildQuery ("SELECT COUNT(*) FROM usr_figures WHERE %s>=0",FieldName); return DB_QueryCOUNT ("can not get number of users with a figure",
return DB_QueryCOUNT_new ("can not get number of users with a figure"); "SELECT COUNT(*) FROM usr_figures WHERE %s>=0",
FieldName);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -708,22 +709,22 @@ static unsigned long Prf_GetRankingNumClicksPerDay (long UsrCod)
{ {
/***** Select number of rows with number of clicks per day /***** Select number of rows with number of clicks per day
greater than the clicks per day of this user *****/ greater than the clicks per day of this user *****/
DB_BuildQuery ("SELECT COUNT(*)+1 FROM" return DB_QueryCOUNT ("can not get ranking using number of clicks per day",
" (SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)" "SELECT COUNT(*)+1 FROM"
" AS NumClicksPerDay" " (SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)"
" FROM usr_figures" " AS NumClicksPerDay"
" WHERE UsrCod<>%ld" // Necessary because the following comparison is not exact in floating point " FROM usr_figures"
" AND NumClicks>0" " WHERE UsrCod<>%ld" // Necessary because the following comparison is not exact in floating point
" AND UNIX_TIMESTAMP(FirstClickTime)>0)" " AND NumClicks>0"
" AS TableNumClicksPerDay" " AND FirstClickTime>FROM_UNIXTIME(0))"
" WHERE NumClicksPerDay>" " AS TableNumClicksPerDay"
"(SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)" " WHERE NumClicksPerDay>"
" FROM usr_figures" "(SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)"
" WHERE UsrCod=%ld" " FROM usr_figures"
" AND NumClicks>0" " WHERE UsrCod=%ld"
" AND UNIX_TIMESTAMP(FirstClickTime)>0)", " AND NumClicks>0"
UsrCod,UsrCod); " AND FirstClickTime>FROM_UNIXTIME(0))",
return DB_QueryCOUNT_new ("can not get ranking using number of clicks per day"); UsrCod,UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -733,10 +734,11 @@ static unsigned long Prf_GetRankingNumClicksPerDay (long UsrCod)
static unsigned long Prf_GetNumUsrsWithNumClicksPerDay (void) static unsigned long Prf_GetNumUsrsWithNumClicksPerDay (void)
{ {
/***** Select number of rows with values already calculated *****/ /***** Select number of rows with values already calculated *****/
DB_BuildQuery ("SELECT COUNT(*) FROM usr_figures" return DB_QueryCOUNT ("can not get number of users"
" WHERE NumClicks>0" " with number of clicks per day",
" AND UNIX_TIMESTAMP(FirstClickTime)>0"); "SELECT COUNT(*) FROM usr_figures"
return DB_QueryCOUNT_new ("can not get number of users with number of clicks per day"); " WHERE NumClicks>0"
" AND FirstClickTime>FROM_UNIXTIME(0)");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -883,8 +885,10 @@ static void Prf_GetNumClicksAndStoreAsUsrFigure (long UsrCod)
Prf_ResetUsrFigures (&UsrFigures); Prf_ResetUsrFigures (&UsrFigures);
/***** Get number of clicks from database *****/ /***** Get number of clicks from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM log_full WHERE UsrCod=%ld",UsrCod); UsrFigures.NumClicks =
UsrFigures.NumClicks = (long) DB_QueryCOUNT_new ("can not get number of clicks"); (long) DB_QueryCOUNT ("can not get number of clicks",
"SELECT COUNT(*) FROM log_full WHERE UsrCod=%ld",
UsrCod);
/***** Update number of clicks in user's figures *****/ /***** Update number of clicks in user's figures *****/
if (Prf_CheckIfUsrFiguresExists (UsrCod)) if (Prf_CheckIfUsrFiguresExists (UsrCod))
@ -1062,8 +1066,9 @@ void Prf_RemoveUsrFigures (long UsrCod)
static bool Prf_CheckIfUsrFiguresExists (long UsrCod) static bool Prf_CheckIfUsrFiguresExists (long UsrCod)
{ {
DB_BuildQuery ("SELECT COUNT(*) FROM usr_figures WHERE UsrCod=%ld",UsrCod); return (DB_QueryCOUNT ("can not get user's first click",
return (DB_QueryCOUNT_new ("can not get user's first click") != 0); "SELECT COUNT(*) FROM usr_figures WHERE UsrCod=%ld",
UsrCod) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1337,7 +1342,7 @@ void Prf_GetAndShowRankingClicksPerDay (void)
"NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1) AS NumClicksPerDay" "NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1) AS NumClicksPerDay"
" FROM usr_figures" " FROM usr_figures"
" WHERE NumClicks>0" " WHERE NumClicks>0"
" AND UNIX_TIMESTAMP(FirstClickTime)>0" " AND FirstClickTime>FROM_UNIXTIME(0)"
" AND UsrCod NOT IN (SELECT UsrCod FROM usr_banned)" " AND UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY NumClicksPerDay DESC,UsrCod LIMIT 100"); " ORDER BY NumClicksPerDay DESC,UsrCod LIMIT 100");
break; break;
@ -1355,7 +1360,7 @@ void Prf_GetAndShowRankingClicksPerDay (void)
" AND courses.CrsCod=crs_usr.CrsCod" " AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_figures.UsrCod" " AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.NumClicks>0" " AND usr_figures.NumClicks>0"
" AND UNIX_TIMESTAMP(usr_figures.FirstClickTime)>0" " AND usr_figures.FirstClickTime>FROM_UNIXTIME(0)"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)" " AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100", " ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100",
Gbl.CurrentCty.Cty.CtyCod); Gbl.CurrentCty.Cty.CtyCod);
@ -1373,7 +1378,7 @@ void Prf_GetAndShowRankingClicksPerDay (void)
" AND courses.CrsCod=crs_usr.CrsCod" " AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_figures.UsrCod" " AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.NumClicks>0" " AND usr_figures.NumClicks>0"
" AND UNIX_TIMESTAMP(usr_figures.FirstClickTime)>0" " AND usr_figures.FirstClickTime>FROM_UNIXTIME(0)"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)" " AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100", " ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100",
Gbl.CurrentIns.Ins.InsCod); Gbl.CurrentIns.Ins.InsCod);
@ -1390,7 +1395,7 @@ void Prf_GetAndShowRankingClicksPerDay (void)
" AND courses.CrsCod=crs_usr.CrsCod" " AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_figures.UsrCod" " AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.NumClicks>0" " AND usr_figures.NumClicks>0"
" AND UNIX_TIMESTAMP(usr_figures.FirstClickTime)>0" " AND usr_figures.FirstClickTime>FROM_UNIXTIME(0)"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)" " AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100", " ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100",
Gbl.CurrentCtr.Ctr.CtrCod); Gbl.CurrentCtr.Ctr.CtrCod);
@ -1406,7 +1411,7 @@ void Prf_GetAndShowRankingClicksPerDay (void)
" AND courses.CrsCod=crs_usr.CrsCod" " AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.UsrCod=usr_figures.UsrCod" " AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.NumClicks>0" " AND usr_figures.NumClicks>0"
" AND UNIX_TIMESTAMP(usr_figures.FirstClickTime)>0" " AND usr_figures.FirstClickTime>FROM_UNIXTIME(0)"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)" " AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100", " ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100",
Gbl.CurrentDeg.Deg.DegCod); Gbl.CurrentDeg.Deg.DegCod);
@ -1421,7 +1426,7 @@ void Prf_GetAndShowRankingClicksPerDay (void)
" WHERE crs_usr.CrsCod=%ld" " WHERE crs_usr.CrsCod=%ld"
" AND crs_usr.UsrCod=usr_figures.UsrCod" " AND crs_usr.UsrCod=usr_figures.UsrCod"
" AND usr_figures.NumClicks>0" " AND usr_figures.NumClicks>0"
" AND UNIX_TIMESTAMP(usr_figures.FirstClickTime)>0" " AND usr_figures.FirstClickTime>FROM_UNIXTIME(0)"
" AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)" " AND usr_figures.UsrCod NOT IN (SELECT UsrCod FROM usr_banned)"
" ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100", " ORDER BY NumClicksPerDay DESC,usr_figures.UsrCod LIMIT 100",
Gbl.CurrentCrs.Crs.CrsCod); Gbl.CurrentCrs.Crs.CrsCod);

View File

@ -630,11 +630,12 @@ long Rec_GetFieldCod (void)
unsigned Rec_CountNumRecordsInCurrCrsWithField (long FieldCod) unsigned Rec_CountNumRecordsInCurrCrsWithField (long FieldCod)
{ {
/***** Get number of cards with a given field in a course from database *****/ /***** Get number of cards with a given field in a course from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM crs_records WHERE FieldCod=%ld", return
FieldCod); (unsigned) DB_QueryCOUNT ("can not get number of records"
return (unsigned) DB_QueryCOUNT_new ("can not get number of cards" " with a given field not empty in a course",
" with a given field not empty" "SELECT COUNT(*) FROM crs_records"
" in a course"); " WHERE FieldCod=%ld",
FieldCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -63,8 +63,9 @@ static bool Ses_CheckIfHiddenParIsAlreadyInDB (Act_Action_t NextAction,
void Ses_GetNumSessions (void) void Ses_GetNumSessions (void)
{ {
/***** Get the number of open sessions from database *****/ /***** Get the number of open sessions from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM sessions"); Gbl.Session.NumSessions =
Gbl.Session.NumSessions = (unsigned) DB_QueryCOUNT_new ("can not get the number of open sessions"); (unsigned) DB_QueryCOUNT ("can not get the number of open sessions",
"SELECT COUNT(*) FROM sessions");
Gbl.Usrs.Connected.TimeToRefreshInMs = (unsigned long) (Gbl.Session.NumSessions/Cfg_TIMES_PER_SECOND_REFRESH_CONNECTED) * 1000UL; Gbl.Usrs.Connected.TimeToRefreshInMs = (unsigned long) (Gbl.Session.NumSessions/Cfg_TIMES_PER_SECOND_REFRESH_CONNECTED) * 1000UL;
if (Gbl.Usrs.Connected.TimeToRefreshInMs < Con_MIN_TIME_TO_REFRESH_CONNECTED_IN_MS) if (Gbl.Usrs.Connected.TimeToRefreshInMs < Con_MIN_TIME_TO_REFRESH_CONNECTED_IN_MS)
@ -106,8 +107,10 @@ void Ses_CreateSession (void)
bool Ses_CheckIfSessionExists (const char *IdSes) bool Ses_CheckIfSessionExists (const char *IdSes)
{ {
/***** Get if session already exists in database *****/ /***** Get if session already exists in database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM sessions WHERE SessionId='%s'",IdSes); return (DB_QueryCOUNT ("can not check if a session already existed",
return (DB_QueryCOUNT_new ("can not check if a session already existed") != 0); "SELECT COUNT(*) FROM sessions"
" WHERE SessionId='%s'",
IdSes) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -394,10 +397,13 @@ static bool Ses_CheckIfHiddenParIsAlreadyInDB (Act_Action_t NextAction,
const char *ParamName) const char *ParamName)
{ {
/***** Get a hidden parameter from database *****/ /***** Get a hidden parameter from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM hidden_params" return (DB_QueryCOUNT ("can not check if a hidden parameter"
" WHERE SessionId='%s' AND Action=%ld AND ParamName='%s'", " is already in database",
Gbl.Session.Id,Act_GetActCod (NextAction),ParamName); "SELECT COUNT(*) FROM hidden_params"
return (DB_QueryCOUNT_new ("can not check if a hidden parameter is already in database") != 0); " WHERE SessionId='%s'"
" AND Action=%ld AND ParamName='%s'",
Gbl.Session.Id,
Act_GetActCod (NextAction),ParamName) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -2426,10 +2426,10 @@ static void Soc_PutHiddenFormToWriteNewCommentToSocialNote (long NotCod,
static unsigned long Soc_GetNumCommentsInSocialNote (long NotCod) static unsigned long Soc_GetNumCommentsInSocialNote (long NotCod)
{ {
DB_BuildQuery ("SELECT COUNT(*) FROM social_pubs" return DB_QueryCOUNT ("can not get number of comments in a social note",
" WHERE NotCod=%ld AND PubType=%u", "SELECT COUNT(*) FROM social_pubs"
NotCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE); " WHERE NotCod=%ld AND PubType=%u",
return DB_QueryCOUNT_new ("can not get number of comments in a social note"); NotCod,(unsigned) Soc_PUB_COMMENT_TO_NOTE);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -4252,10 +4252,14 @@ void Soc_RemoveUsrSocialContent (long UsrCod)
static bool Soc_CheckIfNoteIsSharedByUsr (long NotCod,long UsrCod) static bool Soc_CheckIfNoteIsSharedByUsr (long NotCod,long UsrCod)
{ {
DB_BuildQuery ("SELECT COUNT(*) FROM social_pubs" return (DB_QueryCOUNT ("can not check if a user has shared a social note",
" WHERE NotCod=%ld AND PublisherCod=%ld AND PubType=%u", "SELECT COUNT(*) FROM social_pubs"
NotCod,UsrCod,(unsigned) Soc_PUB_SHARED_NOTE); " WHERE NotCod=%ld"
return (DB_QueryCOUNT_new ("can not check if a user has shared a social note") != 0); " AND PublisherCod=%ld"
" AND PubType=%u",
NotCod,
UsrCod,
(unsigned) Soc_PUB_SHARED_NOTE) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -4264,10 +4268,11 @@ static bool Soc_CheckIfNoteIsSharedByUsr (long NotCod,long UsrCod)
static bool Soc_CheckIfNoteIsFavedByUsr (long NotCod,long UsrCod) static bool Soc_CheckIfNoteIsFavedByUsr (long NotCod,long UsrCod)
{ {
DB_BuildQuery ("SELECT COUNT(*) FROM social_notes_fav" return (DB_QueryCOUNT ("can not check if a user"
" WHERE NotCod=%ld AND UsrCod=%ld", " has favourited a social note",
NotCod,UsrCod); "SELECT COUNT(*) FROM social_notes_fav"
return (DB_QueryCOUNT_new ("can not check if a user has favourited a social note") != 0); " WHERE NotCod=%ld AND UsrCod=%ld",
NotCod,UsrCod) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -4276,10 +4281,11 @@ static bool Soc_CheckIfNoteIsFavedByUsr (long NotCod,long UsrCod)
static bool Soc_CheckIfCommIsFavedByUsr (long PubCod,long UsrCod) static bool Soc_CheckIfCommIsFavedByUsr (long PubCod,long UsrCod)
{ {
DB_BuildQuery ("SELECT COUNT(*) FROM social_comments_fav" return (DB_QueryCOUNT ("can not check if a user"
" WHERE PubCod=%ld AND UsrCod=%ld", " has favourited a social comment",
PubCod,UsrCod); "SELECT COUNT(*) FROM social_comments_fav"
return (DB_QueryCOUNT_new ("can not check if a user has favourited a social comment") != 0); " WHERE PubCod=%ld AND UsrCod=%ld",
PubCod,UsrCod) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -4289,14 +4295,16 @@ static bool Soc_CheckIfCommIsFavedByUsr (long PubCod,long UsrCod)
static unsigned Soc_UpdateNumTimesANoteHasBeenShared (struct SocialNote *SocNot) static unsigned Soc_UpdateNumTimesANoteHasBeenShared (struct SocialNote *SocNot)
{ {
/***** Get number of times (users) this note has been shared *****/ /***** Get number of times (users) this note has been shared *****/
DB_BuildQuery ("SELECT COUNT(*) FROM social_pubs" return
" WHERE NotCod=%ld" (unsigned) DB_QueryCOUNT ("can not get number of times"
" AND PublisherCod<>%ld" " a note has been shared",
" AND PubType=%u", "SELECT COUNT(*) FROM social_pubs"
SocNot->NotCod, " WHERE NotCod=%ld"
SocNot->UsrCod, // The author " AND PublisherCod<>%ld"
(unsigned) Soc_PUB_SHARED_NOTE); " AND PubType=%u",
return (unsigned) DB_QueryCOUNT_new ("can not get number of times a note has been shared"); SocNot->NotCod,
SocNot->UsrCod, // The author
(unsigned) Soc_PUB_SHARED_NOTE);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -4306,12 +4314,14 @@ static unsigned Soc_UpdateNumTimesANoteHasBeenShared (struct SocialNote *SocNot)
static unsigned Soc_GetNumTimesANoteHasBeenFav (struct SocialNote *SocNot) static unsigned Soc_GetNumTimesANoteHasBeenFav (struct SocialNote *SocNot)
{ {
/***** Get number of times (users) this note has been favourited *****/ /***** Get number of times (users) this note has been favourited *****/
DB_BuildQuery ("SELECT COUNT(*) FROM social_notes_fav" return
" WHERE NotCod=%ld" (unsigned) DB_QueryCOUNT ("can not get number of times"
" AND UsrCod<>%ld", // Extra check " a note has been favourited",
SocNot->NotCod, "SELECT COUNT(*) FROM social_notes_fav"
SocNot->UsrCod); // The author " WHERE NotCod=%ld"
return (unsigned) DB_QueryCOUNT_new ("can not get number of times a note has been favourited"); " AND UsrCod<>%ld", // Extra check
SocNot->NotCod,
SocNot->UsrCod); // The author
} }
/*****************************************************************************/ /*****************************************************************************/
@ -4321,12 +4331,14 @@ static unsigned Soc_GetNumTimesANoteHasBeenFav (struct SocialNote *SocNot)
static unsigned Soc_GetNumTimesACommHasBeenFav (struct SocialComment *SocCom) static unsigned Soc_GetNumTimesACommHasBeenFav (struct SocialComment *SocCom)
{ {
/***** Get number of times (users) this comment has been favourited *****/ /***** Get number of times (users) this comment has been favourited *****/
DB_BuildQuery ("SELECT COUNT(*) FROM social_comments_fav" return
" WHERE PubCod=%ld" (unsigned) DB_QueryCOUNT ("can not get number of times"
" AND UsrCod<>%ld", // Extra check " a comment has been favourited",
SocCom->PubCod, "SELECT COUNT(*) FROM social_comments_fav"
SocCom->UsrCod); // The author " WHERE PubCod=%ld"
return (unsigned) DB_QueryCOUNT_new ("can not get number of times a comment has been favourited"); " AND UsrCod<>%ld", // Extra check
SocCom->PubCod,
SocCom->UsrCod); // The author
} }
/*****************************************************************************/ /*****************************************************************************/

File diff suppressed because it is too large Load Diff

View File

@ -1671,9 +1671,9 @@ void Tst_RenameTag (void)
static bool Tst_CheckIfCurrentCrsHasTestTags (void) static bool Tst_CheckIfCurrentCrsHasTestTags (void)
{ {
/***** Get available tags from database *****/ /***** Get available tags from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM tst_tags WHERE CrsCod=%ld", return (DB_QueryCOUNT ("can not check if course has tags",
Gbl.CurrentCrs.Crs.CrsCod); "SELECT COUNT(*) FROM tst_tags WHERE CrsCod=%ld",
return (DB_QueryCOUNT_new ("can not check if course has tags") != 0); Gbl.CurrentCrs.Crs.CrsCod) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/