Version 20.64.1: Apr 17, 2021 Optimizations in database selects.

This commit is contained in:
acanas 2021-04-17 01:57:19 +02:00
parent d9a0fa9d4a
commit dcac830080
28 changed files with 483 additions and 481 deletions

View File

@ -255,7 +255,7 @@ static int API_GetMyLanguage (struct soap *soap);
static int API_SendMessageToUsr (long OriginalMsgCod,long SenderUsrCod,long ReplyUsrCod,long RecipientUsrCod,bool NotifyByEmail,const char *Subject,const char *Content); static int API_SendMessageToUsr (long OriginalMsgCod,long SenderUsrCod,long ReplyUsrCod,long RecipientUsrCod,bool NotifyByEmail,const char *Subject,const char *Content);
static int API_GetTstConfig (long CrsCod); static int API_GetTstConfig (long CrsCod);
static int API_GetNumTestQuestionsInCrs (long CrsCod); static unsigned API_GetNumTestQuestionsInCrs (long CrsCod);
static int API_GetTstTags (struct soap *soap, static int API_GetTstTags (struct soap *soap,
long CrsCod,struct swad__getTestsOutput *getTestsOut); long CrsCod,struct swad__getTestsOutput *getTestsOut);
static int API_GetTstQuestions (struct soap *soap, static int API_GetTstQuestions (struct soap *soap,
@ -4005,7 +4005,7 @@ int swad__getTestConfig (struct soap *soap,
/***** Get number of tests *****/ /***** Get number of tests *****/
if (TstCfg_GetConfigPluggable () == TstCfg_PLUGGABLE_YES && if (TstCfg_GetConfigPluggable () == TstCfg_PLUGGABLE_YES &&
TstCfg_GetConfigMax () > 0) TstCfg_GetConfigMax () > 0)
getTestConfigOut->numQuestions = API_GetNumTestQuestionsInCrs ((long) courseCode); getTestConfigOut->numQuestions = (int) API_GetNumTestQuestionsInCrs ((long) courseCode);
return SOAP_OK; return SOAP_OK;
} }
@ -4054,31 +4054,31 @@ static int API_GetTstConfig (long CrsCod)
/** Get number of visible test questions from database giving a course code **/ /** Get number of visible test questions from database giving a course code **/
/*****************************************************************************/ /*****************************************************************************/
static int API_GetNumTestQuestionsInCrs (long CrsCod) static unsigned API_GetNumTestQuestionsInCrs (long CrsCod)
{ {
/***** Get number of questions *****/ /***** Get number of questions *****/
// Reject questions with any tag hidden // Reject questions with any tag hidden
// Select only questions with tags // Select only questions with tags
return return (unsigned)
(int) DB_QueryCOUNT ("can not get number of test questions", DB_QueryCOUNT ("can not get number of test questions",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM tst_questions," " FROM tst_questions,"
"tst_question_tags," "tst_question_tags,"
"tst_tags" "tst_tags"
" WHERE tst_questions.CrsCod=%ld" " WHERE tst_questions.CrsCod=%ld"
" AND tst_questions.QstCod NOT IN" " AND tst_questions.QstCod NOT IN"
" (SELECT tst_question_tags.QstCod" " (SELECT tst_question_tags.QstCod"
" FROM tst_tags," " FROM tst_tags,"
"tst_question_tags" "tst_question_tags"
" WHERE tst_tags.CrsCod=%ld" " WHERE tst_tags.CrsCod=%ld"
" AND tst_tags.TagHidden='Y'" " AND tst_tags.TagHidden='Y'"
" AND tst_tags.TagCod=tst_question_tags.TagCod)" " AND tst_tags.TagCod=tst_question_tags.TagCod)"
" AND tst_questions.QstCod=tst_question_tags.QstCod" " AND tst_questions.QstCod=tst_question_tags.QstCod"
" AND tst_question_tags.TagCod=tst_tags.TagCod" " AND tst_question_tags.TagCod=tst_tags.TagCod"
" AND tst_tags.CrsCod=%ld", " AND tst_tags.CrsCod=%ld",
CrsCod, CrsCod,
CrsCod, CrsCod,
CrsCod); CrsCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -1836,11 +1836,12 @@ void Agd_RemoveUsrEvents (long UsrCod)
unsigned Agd_GetNumEventsFromUsr (long UsrCod) unsigned Agd_GetNumEventsFromUsr (long UsrCod)
{ {
/***** Get number of events in a course from database *****/ /***** Get number of events in a course from database *****/
return (unsigned) DB_QueryCOUNT ("can not get number of events from user", return (unsigned)
"SELECT COUNT(*)" DB_QueryCOUNT ("can not get number of events from user",
" FROM agd_agendas" "SELECT COUNT(*)"
" WHERE UsrCod=%ld", " FROM agd_agendas"
UsrCod); " WHERE UsrCod=%ld",
UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -600,13 +600,14 @@ TODO: Salvador Romero Cort
TODO: FIX BUG, URGENT! En las fechas como parámetro Dat_WriteParamsIniEndDates(), por ejemplo al cambiar el color de la gráfica de accesos por día y hora, no se respeta la zona horaria. TODO: FIX BUG, URGENT! En las fechas como parámetro Dat_WriteParamsIniEndDates(), por ejemplo al cambiar el color de la gráfica de accesos por día y hora, no se respeta la zona horaria.
*/ */
#define Log_PLATFORM_VERSION "SWAD 20.64 (2021-04-17)" #define Log_PLATFORM_VERSION "SWAD 20.64.1 (2021-04-17)"
#define CSS_FILE "swad20.45.css" #define CSS_FILE "swad20.45.css"
#define JS_FILE "swad20.6.2.js" #define JS_FILE "swad20.6.2.js"
/* /*
TODO: Rename CENTRE to CENTER in help wiki. TODO: Rename CENTRE to CENTER in help wiki.
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
Version 20.64.1: Apr 17, 2021 Optimizations in database selects. (308523 lines)
Version 20.64: Apr 17, 2021 Optimizations in database selects. (308518 lines) Version 20.64: Apr 17, 2021 Optimizations in database selects. (308518 lines)
Version 20.63: Apr 16, 2021 Optimizations in database selects. (308487 lines) Version 20.63: Apr 16, 2021 Optimizations in database selects. (308487 lines)
Version 20.62: Apr 15, 2021 Optimizations in database selects related to roles. (308574 lines) Version 20.62: Apr 15, 2021 Optimizations in database selects related to roles. (308574 lines)

View File

@ -2021,12 +2021,12 @@ unsigned Deg_GetNumDegsInCtr (long CtrCod)
/***** 3. Slow: number of degrees in a center from database *****/ /***** 3. Slow: number of degrees in a center from database *****/
Gbl.Cache.NumDegsInCtr.CtrCod = CtrCod; Gbl.Cache.NumDegsInCtr.CtrCod = CtrCod;
Gbl.Cache.NumDegsInCtr.NumDegs = Gbl.Cache.NumDegsInCtr.NumDegs = (unsigned)
(unsigned) DB_QueryCOUNT ("can not get the number of degrees in a center", DB_QueryCOUNT ("can not get the number of degrees in a center",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM deg_degrees" " FROM deg_degrees"
" WHERE CtrCod=%ld", " WHERE CtrCod=%ld",
CtrCod); CtrCod);
FigCch_UpdateFigureIntoCache (FigCch_NUM_DEGS,Hie_Lvl_CTR,Gbl.Cache.NumDegsInCtr.CtrCod, FigCch_UpdateFigureIntoCache (FigCch_NUM_DEGS,Hie_Lvl_CTR,Gbl.Cache.NumDegsInCtr.CtrCod,
FigCch_UNSIGNED,&Gbl.Cache.NumDegsInCtr.NumDegs); FigCch_UNSIGNED,&Gbl.Cache.NumDegsInCtr.NumDegs);
return Gbl.Cache.NumDegsInCtr.NumDegs; return Gbl.Cache.NumDegsInCtr.NumDegs;

View File

@ -2072,14 +2072,15 @@ void Exa_GetScoreRange (long ExaCod,double *MinScore,double *MaxScore)
unsigned NumAnswers; unsigned NumAnswers;
/***** Get number of answers of exam from database *****/ /***** Get number of answers of exam from database *****/
NumAnswers = DB_QueryCOUNT ("can not get data of a question", NumAnswers = (unsigned)
"SELECT COUNT(tst_answers.AnsInd)" DB_QueryCOUNT ("can not get data of a question",
" FROM tst_answers," "SELECT COUNT(tst_answers.AnsInd)"
"exa_set_questions" " FROM tst_answers,"
" WHERE exa_set_questions.ExaCod=%ld" "exa_set_questions"
" AND exa_set_questions.QstCod=tst_answers.QstCod" " WHERE exa_set_questions.ExaCod=%ld"
" GROUP BY tst_answers.QstCod", " AND exa_set_questions.QstCod=tst_answers.QstCod"
ExaCod); " GROUP BY tst_answers.QstCod",
ExaCod);
if (NumAnswers < 2) if (NumAnswers < 2)
Lay_ShowErrorAndExit ("Wrong number of answers."); Lay_ShowErrorAndExit ("Wrong number of answers.");

View File

@ -1682,12 +1682,12 @@ unsigned ExaSes_GetNumSessionsInExam (long ExaCod)
return 0; // ...has no sessions return 0; // ...has no sessions
/***** Get number of sessions in an exam from database *****/ /***** Get number of sessions in an exam from database *****/
return return (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of sessions of an exam", DB_QueryCOUNT ("can not get number of sessions of an exam",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM exa_sessions" " FROM exa_sessions"
" WHERE ExaCod=%ld", " WHERE ExaCod=%ld",
ExaCod); ExaCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1701,13 +1701,13 @@ unsigned ExaSes_GetNumOpenSessionsInExam (long ExaCod)
return 0; // ...has no sessions return 0; // ...has no sessions
/***** Get number of open sessions in an exam from database *****/ /***** Get number of open sessions in an exam from database *****/
return return (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of open sessions of an exam", DB_QueryCOUNT ("can not get number of open sessions of an exam",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM exa_sessions" " FROM exa_sessions"
" WHERE ExaCod=%ld" " WHERE ExaCod=%ld"
" AND NOW() BETWEEN StartTime AND EndTime", " AND NOW() BETWEEN StartTime AND EndTime",
ExaCod); ExaCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -188,12 +188,12 @@ long ExaSet_GetParamSetCod (void)
static unsigned ExaSet_GetNumQstsInSet (long SetCod) static unsigned ExaSet_GetNumQstsInSet (long SetCod)
{ {
/***** Get number of questions in set from database *****/ /***** Get number of questions in set from database *****/
return return (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of questions in a set", DB_QueryCOUNT ("can not get number of questions in a set",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM exa_set_questions" " FROM exa_set_questions"
" WHERE SetCod=%ld", " WHERE SetCod=%ld",
SetCod); SetCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -626,12 +626,12 @@ static void ExaSet_UpdateNumQstsToExamDB (const struct ExaSet_Set *Set,
unsigned ExaSet_GetNumSetsExam (long ExaCod) unsigned ExaSet_GetNumSetsExam (long ExaCod)
{ {
/***** Get number of sets in an exam from database *****/ /***** Get number of sets in an exam from database *****/
return return (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of sets in an exam", DB_QueryCOUNT ("can not get number of sets in an exam",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM exa_sets" " FROM exa_sets"
" WHERE ExaCod=%ld", " WHERE ExaCod=%ld",
ExaCod); ExaCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -3929,11 +3929,11 @@ static void Fig_GetAndShowFollowStats (void)
switch (Gbl.Scope.Current) switch (Gbl.Scope.Current)
{ {
case Hie_Lvl_SYS: case Hie_Lvl_SYS:
NumUsrs = NumUsrs = (unsigned)
(unsigned) DB_QueryCOUNT ("can not get the total number" DB_QueryCOUNT ("can not get the total number of following/followers",
" of following/followers", "SELECT COUNT(DISTINCT %s)"
"SELECT COUNT(DISTINCT %s) FROM usr_follow", " FROM usr_follow",
FieldDB[Fol]); FieldDB[Fol]);
break; break;
case Hie_Lvl_CTY: case Hie_Lvl_CTY:
NumUsrs = (unsigned) NumUsrs = (unsigned)

View File

@ -10923,15 +10923,15 @@ static bool Brw_GetIfFolderHasPublicFiles (const char Path[PATH_MAX + 1])
unsigned Brw_GetNumFilesUsr (long UsrCod) unsigned Brw_GetNumFilesUsr (long UsrCod)
{ {
/***** Get current number of files published by a user from database *****/ /***** Get current number of files published by a user from database *****/
return return (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of files from a user", DB_QueryCOUNT ("can not get number of files from a user",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM brw_files" " FROM brw_files"
" WHERE PublisherUsrCod=%ld" " WHERE PublisherUsrCod=%ld"
" AND FileType IN (%u,%u)", " AND FileType IN (%u,%u)",
UsrCod, UsrCod,
(unsigned) Brw_IS_FILE, (unsigned) Brw_IS_FILE,
(unsigned) Brw_IS_UNKNOWN); // Unknown entries are counted as files (unsigned) Brw_IS_UNKNOWN); // Unknown entries are counted as files
} }
/*****************************************************************************/ /*****************************************************************************/
@ -10941,16 +10941,16 @@ unsigned Brw_GetNumFilesUsr (long UsrCod)
unsigned Brw_GetNumPublicFilesUsr (long UsrCod) unsigned Brw_GetNumPublicFilesUsr (long UsrCod)
{ {
/***** Get current number of public files published by a user from database *****/ /***** Get current number of public files published by a user from database *****/
return return (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of public files from a user", DB_QueryCOUNT ("can not get number of public files from a user",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM brw_files" " FROM brw_files"
" WHERE PublisherUsrCod=%ld" " WHERE PublisherUsrCod=%ld"
" AND FileType IN (%u,%u)" " AND FileType IN (%u,%u)"
" AND Public='Y'", " AND Public='Y'",
UsrCod, UsrCod,
(unsigned) Brw_IS_FILE, (unsigned) Brw_IS_FILE,
(unsigned) Brw_IS_UNKNOWN); // Unknown entries are counted as files (unsigned) Brw_IS_UNKNOWN); // Unknown entries are counted as files
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -500,18 +500,18 @@ void Fol_GetNumFollow (long UsrCod,
/***** 3. Slow check: Get number of following/followers from database *****/ /***** 3. Slow check: Get number of following/followers from database *****/
Gbl.Cache.Follow.UsrCod = UsrCod; Gbl.Cache.Follow.UsrCod = UsrCod;
*NumFollowing = Gbl.Cache.Follow.NumFollowing = *NumFollowing = Gbl.Cache.Follow.NumFollowing = (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of followed", DB_QueryCOUNT ("can not get number of followed",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM usr_follow" " FROM usr_follow"
" WHERE FollowerCod=%ld", " WHERE FollowerCod=%ld",
UsrCod); UsrCod);
*NumFollowers = Gbl.Cache.Follow.NumFollowers = *NumFollowers = Gbl.Cache.Follow.NumFollowers = (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of followers", DB_QueryCOUNT ("can not get number of followers",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM usr_follow" " FROM usr_follow"
" WHERE FollowedCod=%ld", " WHERE FollowedCod=%ld",
UsrCod); UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -873,13 +873,12 @@ static void For_UpdateThrReadTime (long ThrCod,
static unsigned For_GetNumOfReadersOfThr (long ThrCod) static unsigned For_GetNumOfReadersOfThr (long ThrCod)
{ {
/***** Get number of distinct readers of a thread from database *****/ /***** Get number of distinct readers of a thread from database *****/
return return (unsigned)
(unsigned) DB_QueryCOUNT ("can not get the number of readers" DB_QueryCOUNT ("can not get the number of readers of a thread of a forum",
" of a thread of a forum", "SELECT COUNT(*)"
"SELECT COUNT(*)" " FROM for_read"
" FROM for_read" " WHERE ThrCod=%ld",
" WHERE ThrCod=%ld", ThrCod);
ThrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -903,13 +902,12 @@ static unsigned For_GetNumOfWritersInThr (long ThrCod)
static unsigned For_GetNumPstsInThr (long ThrCod) static unsigned For_GetNumPstsInThr (long ThrCod)
{ {
/***** Get number of posts in a thread from database *****/ /***** Get number of posts in a thread from database *****/
return return (unsigned)
(unsigned) DB_QueryCOUNT ("can not get the number of posts" DB_QueryCOUNT ("can not get the number of posts in a thread of a forum",
" in a thread of a forum", "SELECT COUNT(*)"
"SELECT COUNT(*)" " FROM for_posts"
" FROM for_posts" " WHERE ThrCod=%ld",
" WHERE ThrCod=%ld", ThrCod);
ThrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -919,14 +917,14 @@ static unsigned For_GetNumPstsInThr (long ThrCod)
static unsigned For_GetNumMyPstInThr (long ThrCod) static unsigned For_GetNumMyPstInThr (long ThrCod)
{ {
/***** Get if I have write posts in a thread from database *****/ /***** Get if I have write posts in a thread from database *****/
return return (unsigned)
(unsigned) DB_QueryCOUNT ("can not check if you have written" DB_QueryCOUNT ("can not check if you have written posts in a thead of a forum",
" posts in a thead of a forum", "SELECT COUNT(*)"
"SELECT COUNT(*)" " FROM for_posts"
" FROM for_posts" " WHERE ThrCod=%ld"
" WHERE ThrCod=%ld" " AND UsrCod=%ld",
" AND UsrCod=%ld", ThrCod,
ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1467,19 +1465,18 @@ static void For_WriteNumberOfPosts (const struct For_Forums *Forums,long UsrCod)
Forums->Forum.Location); Forums->Forum.Location);
else else
SubQuery[0] = '\0'; SubQuery[0] = '\0';
NumPsts = NumPsts = (unsigned)
(unsigned) DB_QueryCOUNT ("can not get the number of posts of a user" DB_QueryCOUNT ("can not get the number of posts of a user in a forum",
" in a forum", "SELECT COUNT(*)"
"SELECT COUNT(*)" " FROM for_posts,"
" FROM for_posts," "for_threads"
"for_threads" " WHERE for_posts.UsrCod=%ld"
" WHERE for_posts.UsrCod=%ld" " AND for_posts.ThrCod=for_threads.ThrCod"
" AND for_posts.ThrCod=for_threads.ThrCod" " AND for_threads.ForumType=%u"
" AND for_threads.ForumType=%u" "%s",
"%s", UsrCod,
UsrCod, (unsigned) Forums->Forum.Type,
(unsigned) Forums->Forum.Type, SubQuery);
SubQuery);
/***** Write number of threads and number of posts *****/ /***** Write number of threads and number of posts *****/
HTM_TxtF ("[%u %s]",NumPsts,NumPsts == 1 ? Txt_FORUM_post : HTM_TxtF ("[%u %s]",NumPsts,NumPsts == 1 ? Txt_FORUM_post :
@ -2377,14 +2374,14 @@ 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 *****/
return return (unsigned)
(unsigned) DB_QueryCOUNT ("can not check if there are new posts" DB_QueryCOUNT ("can not check if there are new posts in a thread of a forum",
" in a thread of a forum", "SELECT COUNT(*)"
"SELECT COUNT(*)" " FROM for_posts"
" FROM for_posts" " WHERE ThrCod=%ld"
" WHERE ThrCod=%ld" " AND ModifTime>'%s'",
" AND ModifTime>'%s'", ThrCod,
ThrCod,Time); Time);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3137,14 +3134,14 @@ static unsigned For_GetNumThrsInForum (const struct For_Forum *Forum)
sprintf (SubQuery," AND Location=%ld",Forum->Location); sprintf (SubQuery," AND Location=%ld",Forum->Location);
else else
SubQuery[0] = '\0'; SubQuery[0] = '\0';
return return (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of threads in a forum", DB_QueryCOUNT ("can not get number of threads in a forum",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM for_threads" " FROM for_threads"
" WHERE ForumType=%u" " WHERE ForumType=%u"
"%s", "%s",
(unsigned) Forum->Type, (unsigned) Forum->Type,
SubQuery); SubQuery);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -2858,14 +2858,15 @@ void Gam_GetScoreRange (long GamCod,double *MinScore,double *MaxScore)
unsigned NumAnswers; unsigned NumAnswers;
/***** Get maximum score of a game from database *****/ /***** Get maximum score of a game from database *****/
NumAnswers = DB_QueryCOUNT ("can not number of answers of a question", NumAnswers = (unsigned)
"SELECT COUNT(tst_answers.AnsInd)" DB_QueryCOUNT ("can not number of answers of a question",
" FROM tst_answers," "SELECT COUNT(tst_answers.AnsInd)"
"gam_questions" " FROM tst_answers,"
" WHERE gam_questions.GamCod=%ld" "gam_questions"
" AND gam_questions.QstCod=tst_answers.QstCod" " WHERE gam_questions.GamCod=%ld"
" GROUP BY tst_answers.QstCod", " AND gam_questions.QstCod=tst_answers.QstCod"
GamCod); " GROUP BY tst_answers.QstCod",
GamCod);
if (NumAnswers < 2) if (NumAnswers < 2)
Lay_ShowErrorAndExit ("Wrong number of answers."); Lay_ShowErrorAndExit ("Wrong number of answers.");

View File

@ -3050,14 +3050,14 @@ 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 *****/
return return (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of groups in this course", DB_QueryCOUNT ("can not get number of groups in this course",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM grp_types," " FROM grp_types,"
"grp_groups" "grp_groups"
" WHERE grp_types.CrsCod=%ld" " WHERE grp_types.CrsCod=%ld"
" AND grp_types.GrpTypCod=grp_groups.GrpTypCod", " AND grp_types.GrpTypCod=grp_groups.GrpTypCod",
Gbl.Hierarchy.Crs.CrsCod); Gbl.Hierarchy.Crs.CrsCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3067,12 +3067,12 @@ 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 *****/
return return (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of groups of a type", DB_QueryCOUNT ("can not get number of groups of a type",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM grp_groups" " FROM grp_groups"
" WHERE GrpTypCod=%ld", " WHERE GrpTypCod=%ld",
GrpTypCod); GrpTypCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3311,20 +3311,21 @@ 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 *****/
return return (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of users in a group", DB_QueryCOUNT ("can not get number of users in a group",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM grp_users," " FROM grp_users,"
"grp_groups," "grp_groups,"
"grp_types," "grp_types,"
"crs_users" "crs_users"
" WHERE grp_users.GrpCod=%ld" " WHERE grp_users.GrpCod=%ld"
" AND grp_users.GrpCod=grp_groups.GrpCod" " AND grp_users.GrpCod=grp_groups.GrpCod"
" AND grp_groups.GrpTypCod=grp_types.GrpTypCod" " AND grp_groups.GrpTypCod=grp_types.GrpTypCod"
" AND grp_types.CrsCod=crs_users.CrsCod" " AND grp_types.CrsCod=crs_users.CrsCod"
" AND grp_users.UsrCod=crs_users.UsrCod" " AND grp_users.UsrCod=crs_users.UsrCod"
" AND crs_users.Role=%u", " AND crs_users.Role=%u",
GrpCod,(unsigned) Role); GrpCod,
(unsigned) Role);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3358,20 +3359,16 @@ static unsigned Grp_CountNumUsrsInNoGrpsOfType (Rol_Role_t Role,long GrpTypCod)
static bool Grp_CheckIfIBelongToGrpsOfType (long GrpTypCod) static bool Grp_CheckIfIBelongToGrpsOfType (long GrpTypCod)
{ {
unsigned long NumGrps;
/***** Get a group which I belong to from database *****/ /***** Get a group which I belong to from database *****/
NumGrps = DB_QueryCOUNT ("can not check if you belong to a group type", return (DB_QueryCOUNT ("can not check if you belong to a group type",
"SELECT COUNT(grp_groups.GrpCod)" "SELECT COUNT(grp_groups.GrpCod)"
" FROM grp_groups," " FROM grp_groups,"
"grp_users" "grp_users"
" WHERE grp_groups.GrpTypCod=%ld" " WHERE grp_groups.GrpTypCod=%ld"
" AND grp_groups.GrpCod=grp_users.GrpCod" " AND grp_groups.GrpCod=grp_users.GrpCod"
" AND grp_users.UsrCod=%ld", // I belong " AND grp_users.UsrCod=%ld", // I belong
GrpTypCod, GrpTypCod,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod) != 0);
return (NumGrps != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3517,71 +3514,69 @@ bool Grp_GetIfAvailableGrpTyp (long GrpTypCod)
/***** Get the number of types of group in this course /***** Get the number of types of group in this course
with one or more open groups with vacants, from database *****/ with one or more open groups with vacants, from database *****/
NumGrpTypes = NumGrpTypes = (unsigned)
(unsigned) DB_QueryCOUNT ("can not check if there has available mandatory group types", DB_QueryCOUNT ("can not check if there has available mandatory group types",
"SELECT COUNT(GrpTypCod) FROM " "SELECT COUNT(GrpTypCod)"
"(" " FROM ("
// Available mandatory groups with students
"SELECT GrpTypCod"
" FROM (SELECT grp_types.GrpTypCod AS GrpTypCod,"
"COUNT(*) AS NumStudents,"
"grp_groups.MaxStudents as MaxStudents"
" FROM grp_types,"
"grp_groups,"
"grp_users,"
"crs_users"
" WHERE %s" // Which group types?
" AND grp_types.GrpTypCod=grp_groups.GrpTypCod"
" AND grp_groups.Open='Y'" // Open
" AND grp_groups.MaxStudents>0" // Admits students
" AND grp_types.CrsCod=crs_users.CrsCod"
" AND grp_groups.GrpCod=grp_users.GrpCod"
" AND grp_users.UsrCod=crs_users.UsrCod"
" AND crs_users.Role=%u" // Student
" GROUP BY grp_groups.GrpCod"
" HAVING NumStudents<MaxStudents" // Not full
") AS available_grp_types_with_stds"
// Available mandatory groups with students " UNION "
"SELECT GrpTypCod FROM"
" ("
"SELECT grp_types.GrpTypCod AS GrpTypCod,"
"COUNT(*) AS NumStudents,"
"grp_groups.MaxStudents as MaxStudents"
" FROM grp_types,"
"grp_groups,"
"grp_users,"
"crs_users"
" WHERE %s" // Which group types?
" AND grp_types.GrpTypCod=grp_groups.GrpTypCod"
" AND grp_groups.Open='Y'" // Open
" AND grp_groups.MaxStudents>0" // Admits students
" AND grp_types.CrsCod=crs_users.CrsCod"
" AND grp_groups.GrpCod=grp_users.GrpCod"
" AND grp_users.UsrCod=crs_users.UsrCod"
" AND crs_users.Role=%u" // Student
" GROUP BY grp_groups.GrpCod"
" HAVING NumStudents<MaxStudents" // Not full
") AS available_grp_types_with_stds"
" UNION " // Available mandatory groups...
"SELECT grp_types.GrpTypCod AS GrpTypCod"
" FROM grp_types,"
"grp_groups"
" WHERE %s" // Which group types?
" AND grp_types.GrpTypCod=grp_groups.GrpTypCod"
" AND grp_groups.Open='Y'" // Open
" AND grp_groups.MaxStudents>0" // Admits students
// ...without students
" AND grp_groups.GrpCod NOT IN"
" (SELECT grp_users.GrpCod"
" FROM crs_users,"
"grp_users"
" WHERE crs_users.CrsCod=%ld"
" AND crs_users.Role=%u" // Student
" AND crs_users.UsrCod=grp_users.UsrCod)"
// Available mandatory groups... ") AS available_grp_types"
"SELECT grp_types.GrpTypCod AS GrpTypCod"
" FROM grp_types,"
"grp_groups"
" WHERE %s" // Which group types?
" AND grp_types.GrpTypCod=grp_groups.GrpTypCod"
" AND grp_groups.Open='Y'" // Open
" AND grp_groups.MaxStudents>0" // Admits students
// ...without students
" AND grp_groups.GrpCod NOT IN"
" (SELECT grp_users.GrpCod"
" FROM crs_users,"
"grp_users"
" WHERE crs_users.CrsCod=%ld"
" AND crs_users.Role=%u" // Student
" AND crs_users.UsrCod=grp_users.UsrCod)"
") AS available_grp_types" // ...to which I don't belong
" WHERE GrpTypCod NOT IN"
" (SELECT grp_types.GrpTypCod"
" FROM grp_types,"
"grp_groups,"
"grp_users"
" WHERE %s" // Which group types?
" AND grp_types.GrpTypCod=grp_groups.GrpTypCod"
" AND grp_groups.Open='Y'" // Open
" AND grp_groups.MaxStudents>0" // Admits students
" AND grp_groups.GrpCod=grp_users.GrpCod"
" AND grp_users.UsrCod=%ld)", // I belong
// ...to which I don't belong SubQueryGrpTypes,(unsigned) Rol_STD,
" WHERE GrpTypCod NOT IN" SubQueryGrpTypes,
" (SELECT grp_types.GrpTypCod" Gbl.Hierarchy.Crs.CrsCod,(unsigned) Rol_STD,
" FROM grp_types," SubQueryGrpTypes,Gbl.Usrs.Me.UsrDat.UsrCod);
"grp_groups,"
"grp_users"
" WHERE %s" // Which group types?
" AND grp_types.GrpTypCod=grp_groups.GrpTypCod"
" AND grp_groups.Open='Y'" // Open
" AND grp_groups.MaxStudents>0" // Admits students
" AND grp_groups.GrpCod=grp_users.GrpCod"
" AND grp_users.UsrCod=%ld)", // I belong
SubQueryGrpTypes,(unsigned) Rol_STD,
SubQueryGrpTypes,
Gbl.Hierarchy.Crs.CrsCod,(unsigned) Rol_STD,
SubQueryGrpTypes,Gbl.Usrs.Me.UsrDat.UsrCod);
/***** Free allocated memory for subquery *****/ /***** Free allocated memory for subquery *****/
free (SubQueryGrpTypes); free (SubQueryGrpTypes);

View File

@ -1946,13 +1946,12 @@ unsigned Ins_GetNumInssInCty (long CtyCod)
/***** 2. Slow: number of institutions in a country from database *****/ /***** 2. Slow: number of institutions in a country from database *****/
Gbl.Cache.NumInssInCty.CtyCod = CtyCod; Gbl.Cache.NumInssInCty.CtyCod = CtyCod;
Gbl.Cache.NumInssInCty.NumInss = Gbl.Cache.NumInssInCty.NumInss = (unsigned)
(unsigned) DB_QueryCOUNT ("can not get the number of institutions" DB_QueryCOUNT ("can not get the number of institutions in a country",
" in a country", "SELECT COUNT(*)"
"SELECT COUNT(*)" " FROM ins_instits"
" FROM ins_instits" " WHERE CtyCod=%ld",
" WHERE CtyCod=%ld", CtyCod);
CtyCod);
Gbl.Cache.NumInssInCty.Valid = true; Gbl.Cache.NumInssInCty.Valid = true;
FigCch_UpdateFigureIntoCache (FigCch_NUM_INSS,Hie_Lvl_CTY,Gbl.Cache.NumInssInCty.CtyCod, FigCch_UpdateFigureIntoCache (FigCch_NUM_INSS,Hie_Lvl_CTY,Gbl.Cache.NumInssInCty.CtyCod,
FigCch_UNSIGNED,&Gbl.Cache.NumInssInCty.NumInss); FigCch_UNSIGNED,&Gbl.Cache.NumInssInCty.NumInss);

View File

@ -3830,8 +3830,7 @@ static void Mch_SetMatchAsNotBeingPlayed (long MchCod)
static bool Mch_GetIfMatchIsBeingPlayed (long MchCod) static bool Mch_GetIfMatchIsBeingPlayed (long MchCod)
{ {
/***** Get if a match is being played or not *****/ /***** Get if a match is being played or not *****/
return return (DB_QueryCOUNT ("can not get if match is being played",
(bool) (DB_QueryCOUNT ("can not get if match is being played",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM mch_playing" " FROM mch_playing"
" WHERE MchCod=%ld", " WHERE MchCod=%ld",
@ -3845,12 +3844,12 @@ static bool Mch_GetIfMatchIsBeingPlayed (long MchCod)
static void Mch_GetNumPlayers (struct Mch_Match *Match) static void Mch_GetNumPlayers (struct Mch_Match *Match)
{ {
/***** Get number of players who are playing a match *****/ /***** Get number of players who are playing a match *****/
Match->Status.NumPlayers = Match->Status.NumPlayers = (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of players", DB_QueryCOUNT ("can not get number of players",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM mch_players" " FROM mch_players"
" WHERE MchCod=%ld", " WHERE MchCod=%ld",
Match->MchCod); Match->MchCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -95,12 +95,12 @@ static void Msg_PutFormMsgUsrs (struct Msg_Messages *Messages,
char Content[Cns_MAX_BYTES_LONG_TEXT + 1]); char Content[Cns_MAX_BYTES_LONG_TEXT + 1]);
static void Msg_ShowSentOrReceivedMessages (struct Msg_Messages *Messages); static void Msg_ShowSentOrReceivedMessages (struct Msg_Messages *Messages);
static unsigned long Msg_GetNumUsrsBannedByMe (void); static unsigned Msg_GetNumUsrsBannedByMe (void);
static void Msg_PutLinkToViewBannedUsers(void); static void Msg_PutLinkToViewBannedUsers(void);
static unsigned long Msg_GetSentOrReceivedMsgs (const struct Msg_Messages *Messages, static unsigned Msg_GetSentOrReceivedMsgs (const struct Msg_Messages *Messages,
long UsrCod, long UsrCod,
const char *FilterFromToSubquery, const char *FilterFromToSubquery,
MYSQL_RES **mysql_res); MYSQL_RES **mysql_res);
static void Msg_SetNumMsgsStr (const struct Msg_Messages *Messages, static void Msg_SetNumMsgsStr (const struct Msg_Messages *Messages,
char **NumMsgsStr,unsigned NumUnreadMsgs); char **NumMsgsStr,unsigned NumUnreadMsgs);
@ -1438,8 +1438,8 @@ static unsigned long Msg_DelSomeRecOrSntMsgsUsr (const struct Msg_Messages *Mess
const char *FilterFromToSubquery) const char *FilterFromToSubquery)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
unsigned long MsgNum; unsigned NumMsgs;
unsigned long NumMsgs; unsigned NumMsg;
long MsgCod; long MsgCod;
/***** Get some of the messages received or sent by this user from database *****/ /***** Get some of the messages received or sent by this user from database *****/
@ -1449,9 +1449,9 @@ static unsigned long Msg_DelSomeRecOrSntMsgsUsr (const struct Msg_Messages *Mess
&mysql_res); &mysql_res);
/***** Delete each message *****/ /***** Delete each message *****/
for (MsgNum = 0; for (NumMsg = 0;
MsgNum < NumMsgs; NumMsg < NumMsgs;
MsgNum++) NumMsg++)
{ {
MsgCod = DB_GetNextCode (mysql_res); MsgCod = DB_GetNextCode (mysql_res);
if (MsgCod <= 0) if (MsgCod <= 0)
@ -1784,20 +1784,20 @@ static unsigned Msg_GetNumUnreadMsgs (const struct Msg_Messages *Messages,
} }
if (Messages->FilterContent[0]) if (Messages->FilterContent[0])
NumMsgs = NumMsgs = (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of unread messages", DB_QueryCOUNT ("can not get number of unread messages",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM msg_content" " FROM msg_content"
" WHERE MsgCod IN (%s)" " WHERE MsgCod IN (%s)"
" AND MATCH (Subject,Content) AGAINST ('%s')", " AND MATCH (Subject,Content) AGAINST ('%s')",
SubQuery, SubQuery,
Messages->FilterContent); Messages->FilterContent);
else else
NumMsgs = NumMsgs = (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of unread messages", DB_QueryCOUNT ("can not get number of unread messages",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM (%s) AS T", " FROM (%s) AS T",
SubQuery); SubQuery);
free (SubQuery); free (SubQuery);
@ -2033,14 +2033,15 @@ static void Msg_ShowSentOrReceivedMessages (struct Msg_Messages *Messages)
/********************* Get number of user I have banned **********************/ /********************* Get number of user I have banned **********************/
/*****************************************************************************/ /*****************************************************************************/
static unsigned long Msg_GetNumUsrsBannedByMe (void) static unsigned Msg_GetNumUsrsBannedByMe (void)
{ {
/***** Get number of users I have banned *****/ /***** Get number of users I have banned *****/
return DB_QueryCOUNT ("can not get number of users you have banned", return (unsigned)
"SELECT COUNT(*)" DB_QueryCOUNT ("can not get number of users you have banned",
" FROM msg_banned" "SELECT COUNT(*)"
" WHERE ToUsrCod=%ld", " FROM msg_banned"
Gbl.Usrs.Me.UsrDat.UsrCod); " WHERE ToUsrCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2061,10 +2062,10 @@ static void Msg_PutLinkToViewBannedUsers(void)
/********* Generate a query to select messages received or sent **************/ /********* Generate a query to select messages received or sent **************/
/*****************************************************************************/ /*****************************************************************************/
static unsigned long Msg_GetSentOrReceivedMsgs (const struct Msg_Messages *Messages, static unsigned Msg_GetSentOrReceivedMsgs (const struct Msg_Messages *Messages,
long UsrCod, long UsrCod,
const char *FilterFromToSubquery, const char *FilterFromToSubquery,
MYSQL_RES **mysql_res) MYSQL_RES **mysql_res)
{ {
char *SubQuery; char *SubQuery;
const char *StrUnreadMsg; const char *StrUnreadMsg;
@ -2289,20 +2290,21 @@ unsigned Msg_GetNumMsgsSentByTchsCrs (long CrsCod)
/************** Get the number of unique messages sent by a user *************/ /************** Get the number of unique messages sent by a user *************/
/*****************************************************************************/ /*****************************************************************************/
unsigned long Msg_GetNumMsgsSentByUsr (long UsrCod) unsigned 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 *****/
return DB_QueryCOUNT ("can not get the number of messages sent by a user", return (unsigned)
"SELECT" DB_QueryCOUNT ("can not get the number of messages sent by a user",
" (SELECT COUNT(*)" "SELECT"
" FROM msg_snt" " (SELECT COUNT(*)"
" WHERE UsrCod=%ld)" " FROM msg_snt"
" +" " WHERE UsrCod=%ld)"
" (SELECT COUNT(*)" " +"
" FROM msg_snt_deleted" " (SELECT COUNT(*)"
" WHERE UsrCod=%ld)", " FROM msg_snt_deleted"
UsrCod, " WHERE UsrCod=%ld)",
UsrCod); UsrCod,
UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3735,18 +3737,18 @@ static void Msg_WriteMsgTo (struct Msg_Messages *Messages,long MsgCod)
}; };
/***** Get number of recipients of a message from database *****/ /***** Get number of recipients of a message from database *****/
NumRecipientsTotal = NumRecipientsTotal = (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of recipients", DB_QueryCOUNT ("can not get number of recipients",
"SELECT " "SELECT "
"(SELECT COUNT(*)" "(SELECT COUNT(*)"
" FROM msg_rcv" " FROM msg_rcv"
" WHERE MsgCod=%ld)" " WHERE MsgCod=%ld)"
" + " " + "
"(SELECT COUNT(*)" "(SELECT COUNT(*)"
" FROM msg_rcv_deleted" " FROM msg_rcv_deleted"
" WHERE MsgCod=%ld)", " WHERE MsgCod=%ld)",
MsgCod, MsgCod,
MsgCod); MsgCod);
/***** Get recipients of a message from database *****/ /***** Get recipients of a message from database *****/
NumRecipientsKnown = (unsigned) NumRecipientsKnown = (unsigned)

View File

@ -110,7 +110,7 @@ void Msg_ShowSntMsgs (void);
void Msg_ShowRecMsgs (void); void Msg_ShowRecMsgs (void);
unsigned Msg_GetNumMsgsSentByTchsCrs (long CrsCod); unsigned Msg_GetNumMsgsSentByTchsCrs (long CrsCod);
unsigned long Msg_GetNumMsgsSentByUsr (long UsrCod); unsigned Msg_GetNumMsgsSentByUsr (long UsrCod);
unsigned Msg_GetNumMsgsSent (Hie_Lvl_Level_t Scope,Msg_Status_t MsgStatus); unsigned Msg_GetNumMsgsSent (Hie_Lvl_Level_t Scope,Msg_Status_t MsgStatus);
unsigned Msg_GetNumMsgsReceived (Hie_Lvl_Level_t Scope,Msg_Status_t MsgStatus); unsigned Msg_GetNumMsgsReceived (Hie_Lvl_Level_t Scope,Msg_Status_t MsgStatus);

View File

@ -550,13 +550,13 @@ static void Nck_UpdateUsrNick (struct UsrData *UsrDat)
else if (strcasecmp (UsrDat->Nickname,NewNickWithoutArr)) // User's nickname does not match, not even case insensitive, the new nickname else if (strcasecmp (UsrDat->Nickname,NewNickWithoutArr)) // 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 *****/
if (!DB_QueryCOUNT ("can not check if nickname already existed", if (DB_QueryCOUNT ("can not check if nickname already existed",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM usr_nicknames" " FROM usr_nicknames"
" WHERE UsrCod=%ld" " WHERE UsrCod=%ld"
" AND Nickname='%s'", " AND Nickname='%s'",
UsrDat->UsrCod, UsrDat->UsrCod,
NewNickWithoutArr)) // No matches NewNickWithoutArr) == 0) // 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 *****/
if (DB_QueryCOUNT ("can not check if nickname already existed", if (DB_QueryCOUNT ("can not check if nickname already existed",
"SELECT COUNT(*)" "SELECT COUNT(*)"

View File

@ -2159,13 +2159,14 @@ 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 *****/
return DB_QueryCOUNT ("can not get number of unseen notifications", return (unsigned)
"SELECT COUNT(*)" DB_QueryCOUNT ("can not get number of unseen notifications",
" FROM ntf_notifications" "SELECT COUNT(*)"
" WHERE ToUsrCod=%ld" " FROM ntf_notifications"
" AND (Status & %u)=0", " WHERE ToUsrCod=%ld"
Gbl.Usrs.Me.UsrDat.UsrCod, " AND (Status & %u)=0",
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED)); Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED));
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2175,15 +2176,16 @@ 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 *****/
return DB_QueryCOUNT ("can not get number of unseen notifications", return (unsigned)
"SELECT COUNT(*)" DB_QueryCOUNT ("can not get number of unseen notifications",
" FROM ntf_notifications" "SELECT COUNT(*)"
" WHERE ToUsrCod=%ld" " FROM ntf_notifications"
" AND (Status & %u)=0" " WHERE ToUsrCod=%ld"
" AND TimeNotif>FROM_UNIXTIME(%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),
Gbl.Usrs.Me.UsrLast.LastAccNotif);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -580,14 +580,14 @@ static unsigned Pwd_GetNumOtherUsrsWhoUseThisPassword (const char *EncryptedPass
SubQuery = ""; SubQuery = "";
/***** Get number of other users who use a password from database *****/ /***** Get number of other users who use a password from database *****/
NumUsrs = NumUsrs = (unsigned)
(unsigned) DB_QueryCOUNT ("can not check if a password is trivial", DB_QueryCOUNT ("can not check if a password is trivial",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM usr_data" " FROM usr_data"
" WHERE Password='%s'" " WHERE Password='%s'"
"%s", "%s",
EncryptedPassword, EncryptedPassword,
SubQuery); SubQuery);
/***** Free subquery *****/ /***** Free subquery *****/
if (UsrCod > 0) if (UsrCod > 0)

View File

@ -1108,12 +1108,12 @@ static void Prf_GetNumClicksAndStoreAsUsrFigure (long UsrCod)
Prf_ResetUsrFigures (&UsrFigures); Prf_ResetUsrFigures (&UsrFigures);
/***** Get number of clicks from database *****/ /***** Get number of clicks from database *****/
UsrFigures.NumClicks = UsrFigures.NumClicks = (int)
(long) DB_QueryCOUNT ("can not get number of clicks", DB_QueryCOUNT ("can not get number of clicks",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM log" " FROM log"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld",
UsrCod); 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))
@ -1142,7 +1142,7 @@ static void Prf_GetNumSocialPubsAndStoreAsUsrFigure (long UsrCod)
Prf_ResetUsrFigures (&UsrFigures); Prf_ResetUsrFigures (&UsrFigures);
/***** Get number of forum posts from database *****/ /***** Get number of forum posts from database *****/
UsrFigures.NumSocPub = Tml_DB_GetNumPubsUsr (UsrCod); UsrFigures.NumSocPub = (int) Tml_DB_GetNumPubsUsr (UsrCod);
/***** Update number of forum posts in user's figures *****/ /***** Update number of forum posts in user's figures *****/
if (Prf_CheckIfUsrFiguresExists (UsrCod)) if (Prf_CheckIfUsrFiguresExists (UsrCod))
@ -1229,7 +1229,7 @@ static void Prf_GetNumMessagesSentAndStoreAsUsrFigure (long UsrCod)
Prf_ResetUsrFigures (&UsrFigures); Prf_ResetUsrFigures (&UsrFigures);
/***** Get number of messages sent from database *****/ /***** Get number of messages sent from database *****/
UsrFigures.NumMsgSnt = Msg_GetNumMsgsSentByUsr (UsrCod); UsrFigures.NumMsgSnt = (int) Msg_GetNumMsgsSentByUsr (UsrCod);
/***** Update number of messages sent in user's figures *****/ /***** Update number of messages sent in user's figures *****/
if (Prf_CheckIfUsrFiguresExists (UsrCod)) if (Prf_CheckIfUsrFiguresExists (UsrCod))

View File

@ -2253,13 +2253,14 @@ static void Prj_ShowTableAllProjectsMembersWithARole (const struct Prj_Project *
static unsigned Prj_GetNumUsrsInPrj (long PrjCod,Prj_RoleInProject_t RoleInProject) static unsigned Prj_GetNumUsrsInPrj (long PrjCod,Prj_RoleInProject_t RoleInProject)
{ {
/***** Get users in project from database *****/ /***** Get users in project from database *****/
return (unsigned) DB_QueryCOUNT ("can not get number of users in project", return (unsigned)
"SELECT COUNT(UsrCod)" DB_QueryCOUNT ("can not get number of users in project",
" FROM prj_users" "SELECT COUNT(UsrCod)"
" WHERE PrjCod=%ld" " FROM prj_users"
" AND RoleInProject=%u", " WHERE PrjCod=%ld"
PrjCod, " AND RoleInProject=%u",
(unsigned) RoleInProject); PrjCod,
(unsigned) RoleInProject);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -594,13 +594,13 @@ 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 *****/
return return (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of records" DB_QueryCOUNT ("can not get number of records"
" with a given field not empty in a course", " with a given field not empty in a course",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM crs_records" " FROM crs_records"
" WHERE FieldCod=%ld", " WHERE FieldCod=%ld",
FieldCod); FieldCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -2622,12 +2622,12 @@ static bool Svy_CheckIfICanDoThisSurveyBasedOnGrps (long SvyCod)
static unsigned Svy_GetNumQstsSvy (long SvyCod) static unsigned Svy_GetNumQstsSvy (long SvyCod)
{ {
/***** Get data of questions from database *****/ /***** Get data of questions from database *****/
return return (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of questions of a survey", DB_QueryCOUNT ("can not get number of questions of a survey",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM svy_questions" " FROM svy_questions"
" WHERE SvyCod=%ld", " WHERE SvyCod=%ld",
SvyCod); SvyCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3870,13 +3870,12 @@ static bool Svy_CheckIfIHaveAnsweredSvy (long SvyCod)
static unsigned Svy_GetNumUsrsWhoHaveAnsweredSvy (long SvyCod) static unsigned Svy_GetNumUsrsWhoHaveAnsweredSvy (long SvyCod)
{ {
/***** Get number of surveys with a field value from database *****/ /***** Get number of surveys with a field value from database *****/
return return (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of users" DB_QueryCOUNT ("can not get number of users who have answered a survey",
" who have answered a survey", "SELECT COUNT(*)"
"SELECT COUNT(*)" " FROM svy_users"
" FROM svy_users" " WHERE SvyCod=%ld",
" WHERE SvyCod=%ld", SvyCod);
SvyCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -2671,11 +2671,12 @@ void Tst_PutParamsEditQst (void *Test)
unsigned Tst_GetNumAnswersQst (long QstCod) unsigned Tst_GetNumAnswersQst (long QstCod)
{ {
return (unsigned) DB_QueryCOUNT ("can not get number of answers of a question", return (unsigned)
"SELECT COUNT(*)" DB_QueryCOUNT ("can not get number of answers of a question",
" FROM tst_answers" "SELECT COUNT(*)"
" WHERE QstCod=%ld", " FROM tst_answers"
QstCod); " WHERE QstCod=%ld",
QstCod);
} }
void Tst_GetAnswersQst (struct Tst_Question *Question,MYSQL_RES **mysql_res, void Tst_GetAnswersQst (struct Tst_Question *Question,MYSQL_RES **mysql_res,

View File

@ -881,14 +881,15 @@ long Tml_DB_GetPubCodFromSession (const char *FieldName)
/****************** Get number of publications from a user *******************/ /****************** Get number of publications from a user *******************/
/*****************************************************************************/ /*****************************************************************************/
unsigned long Tml_DB_GetNumPubsUsr (long UsrCod) unsigned Tml_DB_GetNumPubsUsr (long UsrCod)
{ {
/***** Get number of posts from a user from database *****/ /***** Get number of posts from a user from database *****/
return DB_QueryCOUNT ("can not get number of publications from a user", return (unsigned)
"SELECT COUNT(*)" DB_QueryCOUNT ("can not get number of publications from a user",
" FROM tml_pubs" "SELECT COUNT(*)"
" WHERE PublisherCod=%ld", " FROM tml_pubs"
UsrCod); " WHERE PublisherCod=%ld",
UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -110,7 +110,7 @@ unsigned Tml_DB_SelectTheMostRecentPub (const struct Tml_Pub_SubQueries *SubQuer
unsigned Tml_DB_GetDataOfPubByCod (long PubCod,MYSQL_RES **mysql_res); unsigned Tml_DB_GetDataOfPubByCod (long PubCod,MYSQL_RES **mysql_res);
long Tml_DB_GetNotCodFromPubCod (long PubCod); long Tml_DB_GetNotCodFromPubCod (long PubCod);
long Tml_DB_GetPubCodFromSession (const char *FieldName); long Tml_DB_GetPubCodFromSession (const char *FieldName);
unsigned long Tml_DB_GetNumPubsUsr (long UsrCod); unsigned Tml_DB_GetNumPubsUsr (long UsrCod);
long Tml_DB_CreateNewPub (const struct Tml_Pub_Publication *Pub); long Tml_DB_CreateNewPub (const struct Tml_Pub_Publication *Pub);
void Tml_DB_UpdateFirstPubCodInSession (long FirstPubCod); void Tml_DB_UpdateFirstPubCodInSession (long FirstPubCod);
void Tml_DB_UpdateLastPubCodInSession (void); void Tml_DB_UpdateLastPubCodInSession (void);

View File

@ -1160,14 +1160,14 @@ unsigned Usr_GetNumUsrsInCrssOfAUsr (long UsrCod,Rol_Role_t UsrRole,
Str_Concat (OthersRolesStr,",",sizeof (OthersRolesStr) - 1); Str_Concat (OthersRolesStr,",",sizeof (OthersRolesStr) - 1);
Str_Concat (OthersRolesStr,UnsignedStr,sizeof (OthersRolesStr) - 1); Str_Concat (OthersRolesStr,UnsignedStr,sizeof (OthersRolesStr) - 1);
} }
NumUsrs = NumUsrs = (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of users", DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(DISTINCT crs_users.UsrCod)" "SELECT COUNT(DISTINCT crs_users.UsrCod)"
" FROM crs_users," " FROM crs_users,"
"usr_courses_tmp" "usr_courses_tmp"
" WHERE crs_users.CrsCod=usr_courses_tmp.CrsCod" " WHERE crs_users.CrsCod=usr_courses_tmp.CrsCod"
" AND crs_users.Role IN (%s)", " AND crs_users.Role IN (%s)",
OthersRolesStr); OthersRolesStr);
/***** Remove temporary table *****/ /***** Remove temporary table *****/
DB_Query ("can not remove temporary tables", DB_Query ("can not remove temporary tables",
@ -1914,19 +1914,19 @@ bool Usr_CheckIfUsrBelongsToIns (long UsrCod,long InsCod)
Gbl.Cache.UsrBelongsToIns.UsrCod = UsrCod; Gbl.Cache.UsrBelongsToIns.UsrCod = UsrCod;
Gbl.Cache.UsrBelongsToIns.InsCod = InsCod; Gbl.Cache.UsrBelongsToIns.InsCod = InsCod;
Gbl.Cache.UsrBelongsToIns.Belongs = Gbl.Cache.UsrBelongsToIns.Belongs =
(DB_QueryCOUNT ("can not check if a user belongs to an institution", (DB_QueryCOUNT ("can not check if a user belongs to an institution",
"SELECT COUNT(DISTINCT ctr_centers.InsCod)" "SELECT COUNT(DISTINCT ctr_centers.InsCod)"
" FROM crs_users," " FROM crs_users,"
"crs_courses," "crs_courses,"
"deg_degrees," "deg_degrees,"
"ctr_centers" "ctr_centers"
" WHERE crs_users.UsrCod=%ld" " WHERE crs_users.UsrCod=%ld"
" AND crs_users.Accepted='Y'" // Only if user accepted " AND crs_users.Accepted='Y'" // Only if user accepted
" AND crs_users.CrsCod=crs_courses.CrsCod" " AND crs_users.CrsCod=crs_courses.CrsCod"
" AND crs_courses.DegCod=deg_degrees.DegCod" " AND crs_courses.DegCod=deg_degrees.DegCod"
" AND deg_degrees.CtrCod=ctr_centers.CtrCod" " AND deg_degrees.CtrCod=ctr_centers.CtrCod"
" AND ctr_centers.InsCod=%ld", " AND ctr_centers.InsCod=%ld",
UsrCod,InsCod) != 0); UsrCod,InsCod) != 0);
return Gbl.Cache.UsrBelongsToIns.Belongs; return Gbl.Cache.UsrBelongsToIns.Belongs;
} }
@ -4163,11 +4163,11 @@ unsigned Usr_GetNumUsrsWhoDontClaimToBelongToAnyCty (void)
/***** 2. Slow: number of users who don't claim to belong to any country /***** 2. Slow: number of users who don't claim to belong to any country
from database *****/ from database *****/
Gbl.Cache.NumUsrsWhoDontClaimToBelongToAnyCty.NumUsrs = Gbl.Cache.NumUsrsWhoDontClaimToBelongToAnyCty.NumUsrs = (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of users", DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(UsrCod)" "SELECT COUNT(UsrCod)"
" FROM usr_data" " FROM usr_data"
" WHERE CtyCod<0"); " WHERE CtyCod<0");
Gbl.Cache.NumUsrsWhoDontClaimToBelongToAnyCty.Valid = true; Gbl.Cache.NumUsrsWhoDontClaimToBelongToAnyCty.Valid = true;
FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_CTY,Hie_Lvl_CTY,-1L, FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_CTY,Hie_Lvl_CTY,-1L,
FigCch_UNSIGNED,&Gbl.Cache.NumUsrsWhoDontClaimToBelongToAnyCty.NumUsrs); FigCch_UNSIGNED,&Gbl.Cache.NumUsrsWhoDontClaimToBelongToAnyCty.NumUsrs);
@ -4204,11 +4204,11 @@ unsigned Usr_GetNumUsrsWhoClaimToBelongToAnotherCty (void)
/***** 2. Slow: number of users who claim to belong to another country /***** 2. Slow: number of users who claim to belong to another country
from database *****/ from database *****/
Gbl.Cache.NumUsrsWhoClaimToBelongToAnotherCty.NumUsrs = Gbl.Cache.NumUsrsWhoClaimToBelongToAnotherCty.NumUsrs = (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of users", DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(UsrCod)" "SELECT COUNT(UsrCod)"
" FROM usr_data" " FROM usr_data"
" WHERE CtyCod=0"); " WHERE CtyCod=0");
Gbl.Cache.NumUsrsWhoClaimToBelongToAnotherCty.Valid = true; Gbl.Cache.NumUsrsWhoClaimToBelongToAnotherCty.Valid = true;
FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_CTY,Hie_Lvl_CTY,0, FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_CTY,Hie_Lvl_CTY,0,
FigCch_UNSIGNED,&Gbl.Cache.NumUsrsWhoClaimToBelongToAnotherCty.NumUsrs); FigCch_UNSIGNED,&Gbl.Cache.NumUsrsWhoClaimToBelongToAnotherCty.NumUsrs);
@ -4260,12 +4260,12 @@ unsigned Usr_GetNumUsrsWhoClaimToBelongToCty (struct Cty_Countr *Cty)
from database *****/ from database *****/
Gbl.Cache.NumUsrsWhoClaimToBelongToCty.CtyCod = Cty->CtyCod; Gbl.Cache.NumUsrsWhoClaimToBelongToCty.CtyCod = Cty->CtyCod;
Gbl.Cache.NumUsrsWhoClaimToBelongToCty.NumUsrs = Gbl.Cache.NumUsrsWhoClaimToBelongToCty.NumUsrs =
Cty->NumUsrsWhoClaimToBelongToCty.NumUsrs = Cty->NumUsrsWhoClaimToBelongToCty.NumUsrs = (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of users", DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(UsrCod)" "SELECT COUNT(UsrCod)"
" FROM usr_data" " FROM usr_data"
" WHERE CtyCod=%ld", " WHERE CtyCod=%ld",
Cty->CtyCod); Cty->CtyCod);
Cty->NumUsrsWhoClaimToBelongToCty.Valid = true; Cty->NumUsrsWhoClaimToBelongToCty.Valid = true;
FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_CTY,Hie_Lvl_CTY,Gbl.Cache.NumUsrsWhoClaimToBelongToCty.CtyCod, FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_CTY,Hie_Lvl_CTY,Gbl.Cache.NumUsrsWhoClaimToBelongToCty.CtyCod,
FigCch_UNSIGNED,&Gbl.Cache.NumUsrsWhoClaimToBelongToCty.NumUsrs); FigCch_UNSIGNED,&Gbl.Cache.NumUsrsWhoClaimToBelongToCty.NumUsrs);
@ -4317,12 +4317,12 @@ unsigned Usr_GetNumUsrsWhoClaimToBelongToIns (struct Ins_Instit *Ins)
from database *****/ from database *****/
Gbl.Cache.NumUsrsWhoClaimToBelongToIns.InsCod = Ins->InsCod; Gbl.Cache.NumUsrsWhoClaimToBelongToIns.InsCod = Ins->InsCod;
Gbl.Cache.NumUsrsWhoClaimToBelongToIns.NumUsrs = Gbl.Cache.NumUsrsWhoClaimToBelongToIns.NumUsrs =
Ins->NumUsrsWhoClaimToBelongToIns.NumUsrs = Ins->NumUsrsWhoClaimToBelongToIns.NumUsrs = (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of users", DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(UsrCod)" "SELECT COUNT(UsrCod)"
" FROM usr_data" " FROM usr_data"
" WHERE InsCod=%ld", " WHERE InsCod=%ld",
Ins->InsCod); Ins->InsCod);
Ins->NumUsrsWhoClaimToBelongToIns.Valid = true; Ins->NumUsrsWhoClaimToBelongToIns.Valid = true;
FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_INS,Hie_Lvl_INS,Gbl.Cache.NumUsrsWhoClaimToBelongToIns.InsCod, FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_INS,Hie_Lvl_INS,Gbl.Cache.NumUsrsWhoClaimToBelongToIns.InsCod,
FigCch_UNSIGNED,&Gbl.Cache.NumUsrsWhoClaimToBelongToIns.NumUsrs); FigCch_UNSIGNED,&Gbl.Cache.NumUsrsWhoClaimToBelongToIns.NumUsrs);
@ -4374,12 +4374,12 @@ unsigned Usr_GetNumUsrsWhoClaimToBelongToCtr (struct Ctr_Center *Ctr)
from database *****/ from database *****/
Gbl.Cache.NumUsrsWhoClaimToBelongToCtr.CtrCod = Ctr->CtrCod; Gbl.Cache.NumUsrsWhoClaimToBelongToCtr.CtrCod = Ctr->CtrCod;
Gbl.Cache.NumUsrsWhoClaimToBelongToCtr.NumUsrs = Gbl.Cache.NumUsrsWhoClaimToBelongToCtr.NumUsrs =
Ctr->NumUsrsWhoClaimToBelongToCtr.NumUsrs = Ctr->NumUsrsWhoClaimToBelongToCtr.NumUsrs = (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of users", DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(UsrCod)" "SELECT COUNT(UsrCod)"
" FROM usr_data" " FROM usr_data"
" WHERE CtrCod=%ld", " WHERE CtrCod=%ld",
Ctr->CtrCod); Ctr->CtrCod);
FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_CTR,Hie_Lvl_CTR,Gbl.Cache.NumUsrsWhoClaimToBelongToCtr.CtrCod, FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_CTR,Hie_Lvl_CTR,Gbl.Cache.NumUsrsWhoClaimToBelongToCtr.CtrCod,
FigCch_UNSIGNED,&Gbl.Cache.NumUsrsWhoClaimToBelongToCtr.NumUsrs); FigCch_UNSIGNED,&Gbl.Cache.NumUsrsWhoClaimToBelongToCtr.NumUsrs);
return Ctr->NumUsrsWhoClaimToBelongToCtr.NumUsrs; return Ctr->NumUsrsWhoClaimToBelongToCtr.NumUsrs;
@ -9324,6 +9324,7 @@ void Usr_ConstructPathUsr (long UsrCod,char PathUsr[PATH_MAX + 1 + Cns_MAX_DECIM
bool Usr_ChkIfUsrCodExists (long UsrCod) bool Usr_ChkIfUsrCodExists (long UsrCod)
{ {
/***** Trivial check: user's code should be > 0 *****/
if (UsrCod <= 0) // Wrong user's code if (UsrCod <= 0) // Wrong user's code
return false; return false;
@ -9488,17 +9489,18 @@ unsigned Usr_GetNumUsrsInCrss (Hie_Lvl_Level_t Scope,long Cod,unsigned Roles)
{ {
case Hie_Lvl_SYS: case Hie_Lvl_SYS:
if (AnyUserInCourses) // Any user if (AnyUserInCourses) // Any user
NumUsrs = NumUsrs = (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of users", DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(DISTINCT UsrCod)" "SELECT COUNT(DISTINCT UsrCod)"
" FROM crs_users"); " FROM crs_users");
else else
NumUsrs = NumUsrs = (unsigned)
(unsigned) DB_QueryCOUNT ("can not get number of users", DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(DISTINCT UsrCod)" "SELECT COUNT(DISTINCT UsrCod)"
" FROM crs_users" " FROM crs_users"
" WHERE Role%s", " WHERE Role"
SubQueryRoles); "%s",
SubQueryRoles);
break; break;
case Hie_Lvl_CTY: case Hie_Lvl_CTY:
if (AnyUserInCourses) // Any user if (AnyUserInCourses) // Any user
@ -9694,13 +9696,13 @@ unsigned Usr_GetCachedNumUsrsNotBelongingToAnyCrs (void)
{ {
/***** Get current number of guests from database and update cache *****/ /***** Get current number of guests from database and update cache *****/
NumGsts = (unsigned) NumGsts = (unsigned)
DB_QueryCOUNT ("can not get number of users" DB_QueryCOUNT ("can not get number of users"
" who do not belong to any course", " who do not belong to any course",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM usr_data" " FROM usr_data"
" WHERE UsrCod NOT IN" " WHERE UsrCod NOT IN"
" (SELECT DISTINCT(UsrCod)" " (SELECT DISTINCT(UsrCod)"
" FROM crs_users)"); " FROM crs_users)");
FigCch_UpdateFigureIntoCache (FigCch_NUM_GSTS,Hie_Lvl_SYS,-1L, FigCch_UpdateFigureIntoCache (FigCch_NUM_GSTS,Hie_Lvl_SYS,-1L,
FigCch_UNSIGNED,&NumGsts); FigCch_UNSIGNED,&NumGsts);
} }