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_GetTstConfig (long CrsCod);
static int API_GetNumTestQuestionsInCrs (long CrsCod);
static unsigned API_GetNumTestQuestionsInCrs (long CrsCod);
static int API_GetTstTags (struct soap *soap,
long CrsCod,struct swad__getTestsOutput *getTestsOut);
static int API_GetTstQuestions (struct soap *soap,
@ -4005,7 +4005,7 @@ int swad__getTestConfig (struct soap *soap,
/***** Get number of tests *****/
if (TstCfg_GetConfigPluggable () == TstCfg_PLUGGABLE_YES &&
TstCfg_GetConfigMax () > 0)
getTestConfigOut->numQuestions = API_GetNumTestQuestionsInCrs ((long) courseCode);
getTestConfigOut->numQuestions = (int) API_GetNumTestQuestionsInCrs ((long) courseCode);
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 **/
/*****************************************************************************/
static int API_GetNumTestQuestionsInCrs (long CrsCod)
static unsigned API_GetNumTestQuestionsInCrs (long CrsCod)
{
/***** Get number of questions *****/
// Reject questions with any tag hidden
// Select only questions with tags
return
(int) DB_QueryCOUNT ("can not get number of test questions",
"SELECT COUNT(*)"
" FROM tst_questions,"
"tst_question_tags,"
"tst_tags"
" WHERE tst_questions.CrsCod=%ld"
" AND tst_questions.QstCod NOT IN"
" (SELECT tst_question_tags.QstCod"
" FROM tst_tags,"
"tst_question_tags"
" WHERE tst_tags.CrsCod=%ld"
" AND tst_tags.TagHidden='Y'"
" AND tst_tags.TagCod=tst_question_tags.TagCod)"
" AND tst_questions.QstCod=tst_question_tags.QstCod"
" AND tst_question_tags.TagCod=tst_tags.TagCod"
" AND tst_tags.CrsCod=%ld",
CrsCod,
CrsCod,
CrsCod);
return (unsigned)
DB_QueryCOUNT ("can not get number of test questions",
"SELECT COUNT(*)"
" FROM tst_questions,"
"tst_question_tags,"
"tst_tags"
" WHERE tst_questions.CrsCod=%ld"
" AND tst_questions.QstCod NOT IN"
" (SELECT tst_question_tags.QstCod"
" FROM tst_tags,"
"tst_question_tags"
" WHERE tst_tags.CrsCod=%ld"
" AND tst_tags.TagHidden='Y'"
" AND tst_tags.TagCod=tst_question_tags.TagCod)"
" AND tst_questions.QstCod=tst_question_tags.QstCod"
" AND tst_question_tags.TagCod=tst_tags.TagCod"
" AND tst_tags.CrsCod=%ld",
CrsCod,
CrsCod,
CrsCod);
}
/*****************************************************************************/

View File

@ -1836,11 +1836,12 @@ void Agd_RemoveUsrEvents (long UsrCod)
unsigned Agd_GetNumEventsFromUsr (long UsrCod)
{
/***** Get number of events in a course from database *****/
return (unsigned) DB_QueryCOUNT ("can not get number of events from user",
"SELECT COUNT(*)"
" FROM agd_agendas"
" WHERE UsrCod=%ld",
UsrCod);
return (unsigned)
DB_QueryCOUNT ("can not get number of events from user",
"SELECT COUNT(*)"
" FROM agd_agendas"
" 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.
*/
#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 JS_FILE "swad20.6.2.js"
/*
TODO: Rename CENTRE to CENTER in help wiki.
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.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)

View File

@ -2021,12 +2021,12 @@ unsigned Deg_GetNumDegsInCtr (long CtrCod)
/***** 3. Slow: number of degrees in a center from database *****/
Gbl.Cache.NumDegsInCtr.CtrCod = CtrCod;
Gbl.Cache.NumDegsInCtr.NumDegs =
(unsigned) DB_QueryCOUNT ("can not get the number of degrees in a center",
"SELECT COUNT(*)"
" FROM deg_degrees"
" WHERE CtrCod=%ld",
CtrCod);
Gbl.Cache.NumDegsInCtr.NumDegs = (unsigned)
DB_QueryCOUNT ("can not get the number of degrees in a center",
"SELECT COUNT(*)"
" FROM deg_degrees"
" WHERE CtrCod=%ld",
CtrCod);
FigCch_UpdateFigureIntoCache (FigCch_NUM_DEGS,Hie_Lvl_CTR,Gbl.Cache.NumDegsInCtr.CtrCod,
FigCch_UNSIGNED,&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;
/***** Get number of answers of exam from database *****/
NumAnswers = DB_QueryCOUNT ("can not get data of a question",
"SELECT COUNT(tst_answers.AnsInd)"
" FROM tst_answers,"
"exa_set_questions"
" WHERE exa_set_questions.ExaCod=%ld"
" AND exa_set_questions.QstCod=tst_answers.QstCod"
" GROUP BY tst_answers.QstCod",
ExaCod);
NumAnswers = (unsigned)
DB_QueryCOUNT ("can not get data of a question",
"SELECT COUNT(tst_answers.AnsInd)"
" FROM tst_answers,"
"exa_set_questions"
" WHERE exa_set_questions.ExaCod=%ld"
" AND exa_set_questions.QstCod=tst_answers.QstCod"
" GROUP BY tst_answers.QstCod",
ExaCod);
if (NumAnswers < 2)
Lay_ShowErrorAndExit ("Wrong number of answers.");

View File

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

View File

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

View File

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

View File

@ -10923,15 +10923,15 @@ static bool Brw_GetIfFolderHasPublicFiles (const char Path[PATH_MAX + 1])
unsigned Brw_GetNumFilesUsr (long UsrCod)
{
/***** Get current number of files published by a user from database *****/
return
(unsigned) DB_QueryCOUNT ("can not get number of files from a user",
"SELECT COUNT(*)"
" FROM brw_files"
" WHERE PublisherUsrCod=%ld"
" AND FileType IN (%u,%u)",
UsrCod,
(unsigned) Brw_IS_FILE,
(unsigned) Brw_IS_UNKNOWN); // Unknown entries are counted as files
return (unsigned)
DB_QueryCOUNT ("can not get number of files from a user",
"SELECT COUNT(*)"
" FROM brw_files"
" WHERE PublisherUsrCod=%ld"
" AND FileType IN (%u,%u)",
UsrCod,
(unsigned) Brw_IS_FILE,
(unsigned) Brw_IS_UNKNOWN); // Unknown entries are counted as files
}
/*****************************************************************************/
@ -10941,16 +10941,16 @@ unsigned Brw_GetNumFilesUsr (long UsrCod)
unsigned Brw_GetNumPublicFilesUsr (long UsrCod)
{
/***** Get current number of public files published by a user from database *****/
return
(unsigned) DB_QueryCOUNT ("can not get number of public files from a user",
"SELECT COUNT(*)"
" FROM brw_files"
" WHERE PublisherUsrCod=%ld"
" AND FileType IN (%u,%u)"
" AND Public='Y'",
UsrCod,
(unsigned) Brw_IS_FILE,
(unsigned) Brw_IS_UNKNOWN); // Unknown entries are counted as files
return (unsigned)
DB_QueryCOUNT ("can not get number of public files from a user",
"SELECT COUNT(*)"
" FROM brw_files"
" WHERE PublisherUsrCod=%ld"
" AND FileType IN (%u,%u)"
" AND Public='Y'",
UsrCod,
(unsigned) Brw_IS_FILE,
(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 *****/
Gbl.Cache.Follow.UsrCod = UsrCod;
*NumFollowing = Gbl.Cache.Follow.NumFollowing =
(unsigned) DB_QueryCOUNT ("can not get number of followed",
"SELECT COUNT(*)"
" FROM usr_follow"
" WHERE FollowerCod=%ld",
UsrCod);
*NumFollowers = Gbl.Cache.Follow.NumFollowers =
(unsigned) DB_QueryCOUNT ("can not get number of followers",
"SELECT COUNT(*)"
" FROM usr_follow"
" WHERE FollowedCod=%ld",
UsrCod);
*NumFollowing = Gbl.Cache.Follow.NumFollowing = (unsigned)
DB_QueryCOUNT ("can not get number of followed",
"SELECT COUNT(*)"
" FROM usr_follow"
" WHERE FollowerCod=%ld",
UsrCod);
*NumFollowers = Gbl.Cache.Follow.NumFollowers = (unsigned)
DB_QueryCOUNT ("can not get number of followers",
"SELECT COUNT(*)"
" FROM usr_follow"
" WHERE FollowedCod=%ld",
UsrCod);
}
/*****************************************************************************/

View File

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

View File

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

View File

@ -3050,14 +3050,14 @@ void Grp_FreeListGrpTypesAndGrps (void)
unsigned Grp_CountNumGrpsInCurrentCrs (void)
{
/***** Get number of group in current course from database *****/
return
(unsigned) DB_QueryCOUNT ("can not get number of groups in this course",
"SELECT COUNT(*)"
" FROM grp_types,"
"grp_groups"
" WHERE grp_types.CrsCod=%ld"
" AND grp_types.GrpTypCod=grp_groups.GrpTypCod",
Gbl.Hierarchy.Crs.CrsCod);
return (unsigned)
DB_QueryCOUNT ("can not get number of groups in this course",
"SELECT COUNT(*)"
" FROM grp_types,"
"grp_groups"
" WHERE grp_types.CrsCod=%ld"
" AND grp_types.GrpTypCod=grp_groups.GrpTypCod",
Gbl.Hierarchy.Crs.CrsCod);
}
/*****************************************************************************/
@ -3067,12 +3067,12 @@ unsigned Grp_CountNumGrpsInCurrentCrs (void)
static unsigned Grp_CountNumGrpsInThisCrsOfType (long GrpTypCod)
{
/***** Get number of groups of a type from database *****/
return
(unsigned) DB_QueryCOUNT ("can not get number of groups of a type",
"SELECT COUNT(*)"
" FROM grp_groups"
" WHERE GrpTypCod=%ld",
GrpTypCod);
return (unsigned)
DB_QueryCOUNT ("can not get number of groups of a type",
"SELECT COUNT(*)"
" FROM grp_groups"
" WHERE GrpTypCod=%ld",
GrpTypCod);
}
/*****************************************************************************/
@ -3311,20 +3311,21 @@ bool Grp_CheckIfGroupBelongsToCourse (long GrpCod,long CrsCod)
unsigned Grp_CountNumUsrsInGrp (Rol_Role_t Role,long GrpCod)
{
/***** Get number of students in a group from database *****/
return
(unsigned) DB_QueryCOUNT ("can not get number of users in a group",
"SELECT COUNT(*)"
" FROM grp_users,"
"grp_groups,"
"grp_types,"
"crs_users"
" WHERE grp_users.GrpCod=%ld"
" AND grp_users.GrpCod=grp_groups.GrpCod"
" AND grp_groups.GrpTypCod=grp_types.GrpTypCod"
" AND grp_types.CrsCod=crs_users.CrsCod"
" AND grp_users.UsrCod=crs_users.UsrCod"
" AND crs_users.Role=%u",
GrpCod,(unsigned) Role);
return (unsigned)
DB_QueryCOUNT ("can not get number of users in a group",
"SELECT COUNT(*)"
" FROM grp_users,"
"grp_groups,"
"grp_types,"
"crs_users"
" WHERE grp_users.GrpCod=%ld"
" AND grp_users.GrpCod=grp_groups.GrpCod"
" AND grp_groups.GrpTypCod=grp_types.GrpTypCod"
" AND grp_types.CrsCod=crs_users.CrsCod"
" AND grp_users.UsrCod=crs_users.UsrCod"
" AND crs_users.Role=%u",
GrpCod,
(unsigned) Role);
}
/*****************************************************************************/
@ -3358,20 +3359,16 @@ static unsigned Grp_CountNumUsrsInNoGrpsOfType (Rol_Role_t Role,long GrpTypCod)
static bool Grp_CheckIfIBelongToGrpsOfType (long GrpTypCod)
{
unsigned long NumGrps;
/***** Get a group which I belong to from database *****/
NumGrps = DB_QueryCOUNT ("can not check if you belong to a group type",
"SELECT COUNT(grp_groups.GrpCod)"
" FROM grp_groups,"
"grp_users"
" WHERE grp_groups.GrpTypCod=%ld"
" AND grp_groups.GrpCod=grp_users.GrpCod"
" AND grp_users.UsrCod=%ld", // I belong
GrpTypCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
return (NumGrps != 0);
return (DB_QueryCOUNT ("can not check if you belong to a group type",
"SELECT COUNT(grp_groups.GrpCod)"
" FROM grp_groups,"
"grp_users"
" WHERE grp_groups.GrpTypCod=%ld"
" AND grp_groups.GrpCod=grp_users.GrpCod"
" AND grp_users.UsrCod=%ld", // I belong
GrpTypCod,
Gbl.Usrs.Me.UsrDat.UsrCod) != 0);
}
/*****************************************************************************/
@ -3517,71 +3514,69 @@ bool Grp_GetIfAvailableGrpTyp (long GrpTypCod)
/***** Get the number of types of group in this course
with one or more open groups with vacants, from database *****/
NumGrpTypes =
(unsigned) DB_QueryCOUNT ("can not check if there has available mandatory group types",
"SELECT COUNT(GrpTypCod) FROM "
"("
NumGrpTypes = (unsigned)
DB_QueryCOUNT ("can not check if there has available mandatory group types",
"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
"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 "
" 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...
"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"
") 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
" 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
SubQueryGrpTypes,(unsigned) Rol_STD,
SubQueryGrpTypes,
Gbl.Hierarchy.Crs.CrsCod,(unsigned) Rol_STD,
SubQueryGrpTypes,Gbl.Usrs.Me.UsrDat.UsrCod);
SubQueryGrpTypes,(unsigned) Rol_STD,
SubQueryGrpTypes,
Gbl.Hierarchy.Crs.CrsCod,(unsigned) Rol_STD,
SubQueryGrpTypes,Gbl.Usrs.Me.UsrDat.UsrCod);
/***** Free allocated memory for subquery *****/
free (SubQueryGrpTypes);

View File

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

View File

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

View File

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

View File

@ -110,7 +110,7 @@ void Msg_ShowSntMsgs (void);
void Msg_ShowRecMsgs (void);
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_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
{
/***** Check if the new nickname matches any of my old nicknames *****/
if (!DB_QueryCOUNT ("can not check if nickname already existed",
"SELECT COUNT(*)"
" FROM usr_nicknames"
" WHERE UsrCod=%ld"
" AND Nickname='%s'",
UsrDat->UsrCod,
NewNickWithoutArr)) // No matches
if (DB_QueryCOUNT ("can not check if nickname already existed",
"SELECT COUNT(*)"
" FROM usr_nicknames"
" WHERE UsrCod=%ld"
" AND Nickname='%s'",
UsrDat->UsrCod,
NewNickWithoutArr) == 0) // No matches
/***** Check if the new nickname matches any of the nicknames of other users *****/
if (DB_QueryCOUNT ("can not check if nickname already existed",
"SELECT COUNT(*)"

View File

@ -2159,13 +2159,14 @@ void Ntf_WriteNumberOfNewNtfs (void)
static unsigned Ntf_GetNumberOfAllMyUnseenNtfs (void)
{
/***** Get number of places with a name from database *****/
return DB_QueryCOUNT ("can not get number of unseen notifications",
"SELECT COUNT(*)"
" FROM ntf_notifications"
" WHERE ToUsrCod=%ld"
" AND (Status & %u)=0",
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED));
return (unsigned)
DB_QueryCOUNT ("can not get number of unseen notifications",
"SELECT COUNT(*)"
" FROM ntf_notifications"
" WHERE ToUsrCod=%ld"
" AND (Status & %u)=0",
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)
{
/***** Get number of places with a name from database *****/
return DB_QueryCOUNT ("can not get number of unseen notifications",
"SELECT COUNT(*)"
" FROM ntf_notifications"
" WHERE ToUsrCod=%ld"
" AND (Status & %u)=0"
" AND TimeNotif>FROM_UNIXTIME(%ld)",
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED),
Gbl.Usrs.Me.UsrLast.LastAccNotif);
return (unsigned)
DB_QueryCOUNT ("can not get number of unseen notifications",
"SELECT COUNT(*)"
" FROM ntf_notifications"
" WHERE ToUsrCod=%ld"
" AND (Status & %u)=0"
" AND TimeNotif>FROM_UNIXTIME(%ld)",
Gbl.Usrs.Me.UsrDat.UsrCod,
(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 = "";
/***** Get number of other users who use a password from database *****/
NumUsrs =
(unsigned) DB_QueryCOUNT ("can not check if a password is trivial",
"SELECT COUNT(*)"
" FROM usr_data"
" WHERE Password='%s'"
"%s",
EncryptedPassword,
SubQuery);
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)

View File

@ -1108,12 +1108,12 @@ static void Prf_GetNumClicksAndStoreAsUsrFigure (long UsrCod)
Prf_ResetUsrFigures (&UsrFigures);
/***** Get number of clicks from database *****/
UsrFigures.NumClicks =
(long) DB_QueryCOUNT ("can not get number of clicks",
"SELECT COUNT(*)"
" FROM log"
" WHERE UsrCod=%ld",
UsrCod);
UsrFigures.NumClicks = (int)
DB_QueryCOUNT ("can not get number of clicks",
"SELECT COUNT(*)"
" FROM log"
" WHERE UsrCod=%ld",
UsrCod);
/***** Update number of clicks in user's figures *****/
if (Prf_CheckIfUsrFiguresExists (UsrCod))
@ -1142,7 +1142,7 @@ static void Prf_GetNumSocialPubsAndStoreAsUsrFigure (long UsrCod)
Prf_ResetUsrFigures (&UsrFigures);
/***** 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 *****/
if (Prf_CheckIfUsrFiguresExists (UsrCod))
@ -1229,7 +1229,7 @@ static void Prf_GetNumMessagesSentAndStoreAsUsrFigure (long UsrCod)
Prf_ResetUsrFigures (&UsrFigures);
/***** 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 *****/
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)
{
/***** Get users in project from database *****/
return (unsigned) DB_QueryCOUNT ("can not get number of users in project",
"SELECT COUNT(UsrCod)"
" FROM prj_users"
" WHERE PrjCod=%ld"
" AND RoleInProject=%u",
PrjCod,
(unsigned) RoleInProject);
return (unsigned)
DB_QueryCOUNT ("can not get number of users in project",
"SELECT COUNT(UsrCod)"
" FROM prj_users"
" WHERE PrjCod=%ld"
" AND RoleInProject=%u",
PrjCod,
(unsigned) RoleInProject);
}
/*****************************************************************************/

View File

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

View File

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

View File

@ -2671,11 +2671,12 @@ void Tst_PutParamsEditQst (void *Test)
unsigned Tst_GetNumAnswersQst (long QstCod)
{
return (unsigned) DB_QueryCOUNT ("can not get number of answers of a question",
"SELECT COUNT(*)"
" FROM tst_answers"
" WHERE QstCod=%ld",
QstCod);
return (unsigned)
DB_QueryCOUNT ("can not get number of answers of a question",
"SELECT COUNT(*)"
" FROM tst_answers"
" WHERE QstCod=%ld",
QstCod);
}
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 *******************/
/*****************************************************************************/
unsigned long Tml_DB_GetNumPubsUsr (long UsrCod)
unsigned Tml_DB_GetNumPubsUsr (long UsrCod)
{
/***** Get number of posts from a user from database *****/
return DB_QueryCOUNT ("can not get number of publications from a user",
"SELECT COUNT(*)"
" FROM tml_pubs"
" WHERE PublisherCod=%ld",
UsrCod);
return (unsigned)
DB_QueryCOUNT ("can not get number of publications from a user",
"SELECT COUNT(*)"
" FROM tml_pubs"
" 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);
long Tml_DB_GetNotCodFromPubCod (long PubCod);
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);
void Tml_DB_UpdateFirstPubCodInSession (long FirstPubCod);
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,UnsignedStr,sizeof (OthersRolesStr) - 1);
}
NumUsrs =
(unsigned) DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(DISTINCT crs_users.UsrCod)"
" FROM crs_users,"
"usr_courses_tmp"
" WHERE crs_users.CrsCod=usr_courses_tmp.CrsCod"
" AND crs_users.Role IN (%s)",
OthersRolesStr);
NumUsrs = (unsigned)
DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(DISTINCT crs_users.UsrCod)"
" FROM crs_users,"
"usr_courses_tmp"
" WHERE crs_users.CrsCod=usr_courses_tmp.CrsCod"
" AND crs_users.Role IN (%s)",
OthersRolesStr);
/***** Remove temporary table *****/
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.InsCod = InsCod;
Gbl.Cache.UsrBelongsToIns.Belongs =
(DB_QueryCOUNT ("can not check if a user belongs to an institution",
"SELECT COUNT(DISTINCT ctr_centers.InsCod)"
" FROM crs_users,"
"crs_courses,"
"deg_degrees,"
"ctr_centers"
" WHERE crs_users.UsrCod=%ld"
" AND crs_users.Accepted='Y'" // Only if user accepted
" AND crs_users.CrsCod=crs_courses.CrsCod"
" AND crs_courses.DegCod=deg_degrees.DegCod"
" AND deg_degrees.CtrCod=ctr_centers.CtrCod"
" AND ctr_centers.InsCod=%ld",
UsrCod,InsCod) != 0);
(DB_QueryCOUNT ("can not check if a user belongs to an institution",
"SELECT COUNT(DISTINCT ctr_centers.InsCod)"
" FROM crs_users,"
"crs_courses,"
"deg_degrees,"
"ctr_centers"
" WHERE crs_users.UsrCod=%ld"
" AND crs_users.Accepted='Y'" // Only if user accepted
" AND crs_users.CrsCod=crs_courses.CrsCod"
" AND crs_courses.DegCod=deg_degrees.DegCod"
" AND deg_degrees.CtrCod=ctr_centers.CtrCod"
" AND ctr_centers.InsCod=%ld",
UsrCod,InsCod) != 0);
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
from database *****/
Gbl.Cache.NumUsrsWhoDontClaimToBelongToAnyCty.NumUsrs =
(unsigned) DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(UsrCod)"
" FROM usr_data"
" WHERE CtyCod<0");
Gbl.Cache.NumUsrsWhoDontClaimToBelongToAnyCty.NumUsrs = (unsigned)
DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(UsrCod)"
" FROM usr_data"
" WHERE CtyCod<0");
Gbl.Cache.NumUsrsWhoDontClaimToBelongToAnyCty.Valid = true;
FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_CTY,Hie_Lvl_CTY,-1L,
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
from database *****/
Gbl.Cache.NumUsrsWhoClaimToBelongToAnotherCty.NumUsrs =
(unsigned) DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(UsrCod)"
" FROM usr_data"
" WHERE CtyCod=0");
Gbl.Cache.NumUsrsWhoClaimToBelongToAnotherCty.NumUsrs = (unsigned)
DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(UsrCod)"
" FROM usr_data"
" WHERE CtyCod=0");
Gbl.Cache.NumUsrsWhoClaimToBelongToAnotherCty.Valid = true;
FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_CTY,Hie_Lvl_CTY,0,
FigCch_UNSIGNED,&Gbl.Cache.NumUsrsWhoClaimToBelongToAnotherCty.NumUsrs);
@ -4260,12 +4260,12 @@ unsigned Usr_GetNumUsrsWhoClaimToBelongToCty (struct Cty_Countr *Cty)
from database *****/
Gbl.Cache.NumUsrsWhoClaimToBelongToCty.CtyCod = Cty->CtyCod;
Gbl.Cache.NumUsrsWhoClaimToBelongToCty.NumUsrs =
Cty->NumUsrsWhoClaimToBelongToCty.NumUsrs =
(unsigned) DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(UsrCod)"
" FROM usr_data"
" WHERE CtyCod=%ld",
Cty->CtyCod);
Cty->NumUsrsWhoClaimToBelongToCty.NumUsrs = (unsigned)
DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(UsrCod)"
" FROM usr_data"
" WHERE CtyCod=%ld",
Cty->CtyCod);
Cty->NumUsrsWhoClaimToBelongToCty.Valid = true;
FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_CTY,Hie_Lvl_CTY,Gbl.Cache.NumUsrsWhoClaimToBelongToCty.CtyCod,
FigCch_UNSIGNED,&Gbl.Cache.NumUsrsWhoClaimToBelongToCty.NumUsrs);
@ -4317,12 +4317,12 @@ unsigned Usr_GetNumUsrsWhoClaimToBelongToIns (struct Ins_Instit *Ins)
from database *****/
Gbl.Cache.NumUsrsWhoClaimToBelongToIns.InsCod = Ins->InsCod;
Gbl.Cache.NumUsrsWhoClaimToBelongToIns.NumUsrs =
Ins->NumUsrsWhoClaimToBelongToIns.NumUsrs =
(unsigned) DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(UsrCod)"
" FROM usr_data"
" WHERE InsCod=%ld",
Ins->InsCod);
Ins->NumUsrsWhoClaimToBelongToIns.NumUsrs = (unsigned)
DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(UsrCod)"
" FROM usr_data"
" WHERE InsCod=%ld",
Ins->InsCod);
Ins->NumUsrsWhoClaimToBelongToIns.Valid = true;
FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_INS,Hie_Lvl_INS,Gbl.Cache.NumUsrsWhoClaimToBelongToIns.InsCod,
FigCch_UNSIGNED,&Gbl.Cache.NumUsrsWhoClaimToBelongToIns.NumUsrs);
@ -4374,12 +4374,12 @@ unsigned Usr_GetNumUsrsWhoClaimToBelongToCtr (struct Ctr_Center *Ctr)
from database *****/
Gbl.Cache.NumUsrsWhoClaimToBelongToCtr.CtrCod = Ctr->CtrCod;
Gbl.Cache.NumUsrsWhoClaimToBelongToCtr.NumUsrs =
Ctr->NumUsrsWhoClaimToBelongToCtr.NumUsrs =
(unsigned) DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(UsrCod)"
" FROM usr_data"
" WHERE CtrCod=%ld",
Ctr->CtrCod);
Ctr->NumUsrsWhoClaimToBelongToCtr.NumUsrs = (unsigned)
DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(UsrCod)"
" FROM usr_data"
" WHERE CtrCod=%ld",
Ctr->CtrCod);
FigCch_UpdateFigureIntoCache (FigCch_NUM_USRS_BELONG_CTR,Hie_Lvl_CTR,Gbl.Cache.NumUsrsWhoClaimToBelongToCtr.CtrCod,
FigCch_UNSIGNED,&Gbl.Cache.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)
{
/***** Trivial check: user's code should be > 0 *****/
if (UsrCod <= 0) // Wrong user's code
return false;
@ -9488,17 +9489,18 @@ unsigned Usr_GetNumUsrsInCrss (Hie_Lvl_Level_t Scope,long Cod,unsigned Roles)
{
case Hie_Lvl_SYS:
if (AnyUserInCourses) // Any user
NumUsrs =
(unsigned) DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(DISTINCT UsrCod)"
" FROM crs_users");
NumUsrs = (unsigned)
DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(DISTINCT UsrCod)"
" FROM crs_users");
else
NumUsrs =
(unsigned) DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(DISTINCT UsrCod)"
" FROM crs_users"
" WHERE Role%s",
SubQueryRoles);
NumUsrs = (unsigned)
DB_QueryCOUNT ("can not get number of users",
"SELECT COUNT(DISTINCT UsrCod)"
" FROM crs_users"
" WHERE Role"
"%s",
SubQueryRoles);
break;
case Hie_Lvl_CTY:
if (AnyUserInCourses) // Any user
@ -9694,13 +9696,13 @@ unsigned Usr_GetCachedNumUsrsNotBelongingToAnyCrs (void)
{
/***** Get current number of guests from database and update cache *****/
NumGsts = (unsigned)
DB_QueryCOUNT ("can not get number of users"
" who do not belong to any course",
"SELECT COUNT(*)"
" FROM usr_data"
" WHERE UsrCod NOT IN"
" (SELECT DISTINCT(UsrCod)"
" FROM crs_users)");
DB_QueryCOUNT ("can not get number of users"
" who do not belong to any course",
"SELECT COUNT(*)"
" FROM usr_data"
" WHERE UsrCod NOT IN"
" (SELECT DISTINCT(UsrCod)"
" FROM crs_users)");
FigCch_UpdateFigureIntoCache (FigCch_NUM_GSTS,Hie_Lvl_SYS,-1L,
FigCch_UNSIGNED,&NumGsts);
}