Version 21.52.2: Nov 06, 2021 Query refactoring related to SELECT DISTINCT and UNION.

This commit is contained in:
acanas 2021-11-06 12:13:05 +01:00
parent 2e61500a79
commit e07963d8b1
42 changed files with 326 additions and 252 deletions

View File

@ -2916,8 +2916,9 @@ int swad__getAttendanceUsers (struct soap *soap,
// Event for one or more groups
// Subquery: list of users in groups of this attendance event...
// ...who have no entry in attendance list of users
sprintf (SubQuery,"SELECT DISTINCT grp_users.UsrCod AS UsrCod," // row[0]
"'N' AS Present" // row[1]
sprintf (SubQuery,"SELECT DISTINCT "
"grp_users.UsrCod AS UsrCod," // row[0]
"'N' AS Present" // row[1]
" FROM att_groups,"
"grp_groups,"
"grp_types,"
@ -4208,14 +4209,15 @@ static int API_GetTstQuestions (struct soap *soap,
Qst_AnswerType_t AnswerType;
/***** Get recent test questions from database *****/
// DISTINCTROW is necessary to not repeat questions
// DISTINCT is necessary to not repeat questions
NumRows = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get test questions",
"SELECT DISTINCTROW tst_questions.QstCod," // row[0]
"tst_questions.AnsType," // row[1]
"tst_questions.Shuffle," // row[2]
"tst_questions.Stem," // row[3]
"tst_questions.Feedback" // row[4]
"SELECT DISTINCT "
"tst_questions.QstCod," // row[0]
"tst_questions.AnsType," // row[1]
"tst_questions.Shuffle," // row[2]
"tst_questions.Stem," // row[3]
"tst_questions.Feedback" // row[4]
" FROM tst_questions,"
"tst_question_tags,"
"tst_tags"
@ -4567,7 +4569,7 @@ int swad__getTrivialQuestion (struct soap *soap,
Str_SetDecimalPointToUS (); // To print the floating point as a dot
NumRows = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get test questions",
"SELECT DISTINCTROW "
"SELECT DISTINCT "
"tst_questions.QstCod," // row[0]
"tst_questions.AnsType," // row[1]
"tst_questions.Shuffle," // row[2]
@ -6058,14 +6060,16 @@ int swad__getLastLocation (struct soap *soap,
if (DB_QueryEXISTS ("can not check if you can see user location",
"SELECT EXISTS"
"(SELECT *"
" FROM (SELECT DISTINCT deg_degrees.CtrCod"
" FROM (SELECT DISTINCT "
"deg_degrees.CtrCod"
" FROM crs_users,"
"crs_courses,"
"deg_degrees"
" WHERE crs_users.UsrCod=%ld"
" AND crs_users.CrsCod=crs_courses.CrsCod"
" AND crs_courses.DegCod=deg_degrees.DegCod) AS C1," // centers of my courses
"(SELECT DISTINCT deg_degrees.CtrCod"
"(SELECT DISTINCT "
"deg_degrees.CtrCod"
" FROM crs_users,"
"crs_courses,"
"deg_degrees"

View File

@ -182,7 +182,8 @@ unsigned ID_DB_GetUsrCodsFromUsrID (MYSQL_RES **mysql_res,
// or if password in database is empty (new user)
NumUsrs = (unsigned)
DB_QuerySELECT (mysql_res,"can not get user's codes",
"SELECT DISTINCT(usr_ids.UsrCod)"
"SELECT DISTINCT "
"usr_ids.UsrCod"
" FROM usr_ids,"
"usr_data"
" WHERE usr_ids.UsrID IN (%s)"
@ -198,10 +199,11 @@ unsigned ID_DB_GetUsrCodsFromUsrID (MYSQL_RES **mysql_res,
else
NumUsrs = (unsigned)
DB_QuerySELECT (mysql_res,"can not get user's codes",
"SELECT DISTINCT(UsrCod)"
"SELECT DISTINCT "
"UsrCod"
" FROM usr_ids"
" WHERE UsrID IN (%s)"
"%s",
"%s",
SubQueryAllUsrs,
OnlyConfirmedIDs ? " AND Confirmed='Y'" :
"");

View File

@ -464,7 +464,8 @@ unsigned Agd_DB_GetNumEvents (HieLvl_Level_t Scope)
return (unsigned)
DB_QueryCOUNT ("can not get number of events",
"SELECT COUNT(*)"
" FROM (SELECT DISTINCT crs_users.UsrCod"
" FROM (SELECT DISTINCT "
"crs_users.UsrCod"
" FROM ins_instits,"
"ctr_centers,"
"deg_degrees,"
@ -482,7 +483,8 @@ unsigned Agd_DB_GetNumEvents (HieLvl_Level_t Scope)
return (unsigned)
DB_QueryCOUNT ("can not get number of events",
"SELECT COUNT(*)"
" FROM (SELECT DISTINCT crs_users.UsrCod"
" FROM (SELECT DISTINCT "
"crs_users.UsrCod"
" FROM ctr_centers,"
"deg_degrees,"
"crs_courses,"
@ -498,7 +500,8 @@ unsigned Agd_DB_GetNumEvents (HieLvl_Level_t Scope)
return (unsigned)
DB_QueryCOUNT ("can not get number of events",
"SELECT COUNT(*)"
" FROM (SELECT DISTINCT crs_users.UsrCod"
" FROM (SELECT DISTINCT "
"crs_users.UsrCod"
" FROM deg_degrees,"
"crs_courses,"
"crs_users"
@ -512,7 +515,8 @@ unsigned Agd_DB_GetNumEvents (HieLvl_Level_t Scope)
return (unsigned)
DB_QueryCOUNT ("can not get number of events",
"SELECT COUNT(*)"
" FROM (SELECT DISTINCT crs_users.UsrCod"
" FROM (SELECT DISTINCT "
"crs_users.UsrCod"
" FROM crs_courses,"
"crs_users"
" WHERE crs_courses.DegCod=%ld"

View File

@ -484,7 +484,8 @@ unsigned Asg_DB_GetUsrsFromAssignmentExceptMe (MYSQL_RES **mysql_res,long AsgCod
" AND asg_assignments.CrsCod=crs_users.CrsCod"
" AND crs_users.UsrCod<>%ld)"
" UNION "
"(SELECT DISTINCT grp_users.UsrCod"
"(SELECT DISTINCT "
"grp_users.UsrCod"
" FROM asg_groups,"
"grp_users"
" WHERE asg_groups.AsgCod=%ld"

View File

@ -338,7 +338,8 @@ long Brw_DB_GetPublisherOfSubtree (const char *Path)
/***** Get all common files that are equal to full path (including filename)
or that are under that full path from database *****/
return DB_QuerySELECTCode ("can not get publishers of files",
"SELECT DISTINCT(PublisherUsrCod)"
"SELECT DISTINCT "
"PublisherUsrCod"
" FROM brw_files"
" WHERE FileBrowser=%u"
" AND Cod=%ld"

View File

@ -89,8 +89,9 @@ unsigned Ctr_DB_GetListOfCtrsInCurrentIns (MYSQL_RES **mysql_res)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get centers",
"SELECT DISTINCT CtrCod," // row[0]
"ShortName" // row[1]
"SELECT DISTINCT "
"CtrCod," // row[0]
"ShortName" // row[1]
" FROM ctr_centers"
" WHERE InsCod=%ld"
" ORDER BY ShortName",
@ -171,7 +172,8 @@ unsigned Ctr_DB_GetListOfCtrsFullWithNumUsrs (MYSQL_RES **mysql_res,
" FROM ctr_centers"
" WHERE InsCod=%ld"
" AND CtrCod NOT IN"
" (SELECT DISTINCT CtrCod"
" (SELECT DISTINCT "
"CtrCod"
" FROM usr_data))"
" ORDER BY %s",
InsCod,

View File

@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par
TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo.
*/
#define Log_PLATFORM_VERSION "SWAD 21.52.1 (2021-11-06)"
#define Log_PLATFORM_VERSION "SWAD 21.52.2 (2021-11-06)"
#define CSS_FILE "swad20.45.css"
#define JS_FILE "swad20.69.1.js"
/*
TODO: Rename CENTRE to CENTER in help wiki.
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
Version 21.52.2: Nov 06, 2021 Query refactoring related to SELECT DISTINCT and UNION. (321899 lines)
Version 21.52.1: Nov 06, 2021 Fixed database query in departments. (321828 lines)
Version 21.52: Nov 05, 2021 Changed SELECT COUNT to SELECT EXISTS in some queries. (321833 lines)
Version 21.51: Nov 04, 2021 Eliminated the limit of origin courses in messages. (321735 lines)

View File

@ -361,7 +361,7 @@ unsigned Con_DB_GetConnectedFromCurrentLocation (MYSQL_RES **mysql_res,Rol_Role_
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get list of connected users"
" who belong to this location",
"SELECT DISTINCTROW "
"SELECT DISTINCT "
"usr_connected.UsrCod," // row[0]
"usr_connected.LastCrsCod," // row[1]
"UNIX_TIMESTAMP()-"
@ -376,7 +376,7 @@ unsigned Con_DB_GetConnectedFromCurrentLocation (MYSQL_RES **mysql_res,Rol_Role_
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get list of connected users"
" who belong to this location",
"SELECT DISTINCTROW "
"SELECT DISTINCT "
"usr_connected.UsrCod," // row[0]
"usr_connected.LastCrsCod," // row[1]
"UNIX_TIMESTAMP()-"
@ -401,7 +401,7 @@ unsigned Con_DB_GetConnectedFromCurrentLocation (MYSQL_RES **mysql_res,Rol_Role_
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get list of connected users"
" who belong to this location",
"SELECT DISTINCTROW "
"SELECT DISTINCT "
"usr_connected.UsrCod," // row[0]
"usr_connected.LastCrsCod," // row[1]
"UNIX_TIMESTAMP()-"
@ -424,7 +424,7 @@ unsigned Con_DB_GetConnectedFromCurrentLocation (MYSQL_RES **mysql_res,Rol_Role_
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get list of connected users"
" who belong to this location",
"SELECT DISTINCTROW "
"SELECT DISTINCT "
"usr_connected.UsrCod," // row[0]
"usr_connected.LastCrsCod," // row[1]
"UNIX_TIMESTAMP()-"
@ -445,7 +445,7 @@ unsigned Con_DB_GetConnectedFromCurrentLocation (MYSQL_RES **mysql_res,Rol_Role_
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get list of connected users"
" who belong to this location",
"SELECT DISTINCTROW "
"SELECT DISTINCT "
"usr_connected.UsrCod," // row[0]
"usr_connected.LastCrsCod," // row[1]
"UNIX_TIMESTAMP()-"
@ -513,7 +513,8 @@ void Con_DB_RemoveOldConnected (void)
DB_QueryDELETE ("can not remove old users from list of connected users",
"DELETE FROM usr_connected"
" WHERE UsrCod NOT IN"
" (SELECT DISTINCT(UsrCod)"
" (SELECT DISTINCT "
"UsrCod"
" FROM ses_sessions)");
}

View File

@ -220,7 +220,8 @@ unsigned Cty_DB_GetCtysFull (MYSQL_RES **mysql_res)
"0 AS NumUsrs" // row[...]
" FROM cty_countrs"
" WHERE CtyCod NOT IN"
" (SELECT DISTINCT CtyCod"
" (SELECT DISTINCT "
"CtyCod"
" FROM usr_data))"
" ORDER BY %s",
SubQueryNam1,SubQueryWWW1,

View File

@ -279,7 +279,8 @@ unsigned Crs_DB_GetOldCrss (MYSQL_RES **mysql_res,unsigned long SecondsWithoutAc
" FROM crs_last"
" WHERE LastTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)"
" AND CrsCod NOT IN"
" (SELECT DISTINCT CrsCod"
" (SELECT DISTINCT "
"CrsCod"
" FROM crs_users)",
SecondsWithoutAccess);
}

View File

@ -435,7 +435,7 @@ unsigned Deg_DB_GetDegsWithStds (MYSQL_RES **mysql_res)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get degrees with students",
"SELECT DISTINCTROW "
"SELECT DISTINCT "
"deg_degrees.DegCod," // row[0]
"deg_degrees.CtrCod," // row[1]
"deg_degrees.DegTypCod," // row[2]

View File

@ -108,12 +108,13 @@ unsigned Dpt_DB_GetListDepartments (MYSQL_RES **mysql_res,
"0 AS NumTchs" // row[5]
" FROM dpt_departments"
" WHERE InsCod=%ld"
" AND DptCod NOT IN"
" (SELECT DISTINCT usr_data.DptCod"
" FROM usr_data,crs_users"
" WHERE crs_users.Role IN (%u,%u)"
" AND crs_users.UsrCod=usr_data.UsrCod))"
" ORDER BY %s",
" AND DptCod NOT IN"
" (SELECT DISTINCT "
"usr_data.DptCod"
" FROM usr_data,crs_users"
" WHERE crs_users.Role IN (%u,%u)"
" AND crs_users.UsrCod=usr_data.UsrCod))"
" ORDER BY %s",
InsCod,(unsigned) Rol_NET,(unsigned) Rol_TCH,
InsCod,(unsigned) Rol_NET,(unsigned) Rol_TCH,
OrderBySubQuery[SelectedOrder]);
@ -149,7 +150,8 @@ unsigned Dpt_DB_GetDataOfDepartmentByCod (MYSQL_RES **mysql_res,long DptCod)
" FROM dpt_departments"
" WHERE DptCod=%ld"
" AND DptCod NOT IN"
" (SELECT DISTINCT usr_data.DptCod"
" (SELECT DISTINCT "
"usr_data.DptCod"
" FROM usr_data,"
"crs_users"
" WHERE crs_users.Role=%u"

View File

@ -81,20 +81,19 @@ unsigned Dup_DB_GetUsrsSimilarTo (MYSQL_RES **mysql_res,const struct UsrData *Us
UsrDat->FrstName[0]) // Name and surname 1 not empty
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get similar users",
"SELECT DISTINCT UsrCod"
" FROM (SELECT DISTINCT UsrCod"
" FROM usr_ids"
" WHERE UsrID IN"
" (SELECT UsrID"
" FROM usr_ids"
" WHERE UsrCod=%ld)"
" UNION"
" SELECT UsrCod"
" FROM usr_data"
" WHERE Surname1='%s'"
" AND Surname2='%s'"
" AND FirstName='%s')"
" AS U",
"SELECT DISTINCT "
"UsrCod"
" FROM usr_ids"
" WHERE UsrID IN"
" (SELECT UsrID"
" FROM usr_ids"
" WHERE UsrCod=%ld)"
" UNION DISTINCT"
" SELECT UsrCod"
" FROM usr_data"
" WHERE Surname1='%s'"
" AND Surname2='%s'"
" AND FirstName='%s'",
UsrDat->UsrCod,
UsrDat->Surname1,
UsrDat->Surname2,
@ -102,7 +101,8 @@ unsigned Dup_DB_GetUsrsSimilarTo (MYSQL_RES **mysql_res,const struct UsrData *Us
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get similar users",
"SELECT DISTINCT UsrCod"
"SELECT DISTINCT "
"UsrCod"
" FROM usr_ids"
" WHERE UsrID IN"
" (SELECT UsrID"

View File

@ -668,7 +668,8 @@ unsigned Enr_DB_GetNumUsrsNotBelongingToAnyCrs (void)
"SELECT COUNT(*)"
" FROM usr_data"
" WHERE UsrCod NOT IN"
" (SELECT DISTINCT(UsrCod)"
" (SELECT DISTINCT "
"UsrCod"
" FROM crs_users)");
}

View File

@ -2234,7 +2234,8 @@ unsigned Exa_DB_GetAllUsrsWhoHaveMadeExam (MYSQL_RES **mysql_res,long ExaCod)
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get users in exam",
"SELECT users.UsrCod" // row[0]
" FROM (SELECT DISTINCT exa_prints.UsrCod AS UsrCod"
" FROM (SELECT DISTINCT "
"exa_prints.UsrCod AS UsrCod"
" FROM exa_prints,"
"exa_sessions,"
"exa_exams"

View File

@ -119,19 +119,24 @@ unsigned Fol_DB_GetUsrsToFollow (unsigned MaxUsrsToShow,
// Get only users with surname 1 and first name
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get users to follow",
"SELECT DISTINCT UsrCod FROM"
"SELECT DISTINCT "
"UsrCod"
" FROM"
" ("
/***** Likely known users *****/
"(SELECT DISTINCT UsrCod FROM"
"(SELECT DISTINCT "
"UsrCod"
" FROM"
" ("
// 1. Users followed by my followed
"("
"SELECT DISTINCT usr_follow.FollowedCod AS UsrCod"
" FROM usr_follow,"
"(SELECT FollowedCod"
" FROM usr_follow"
" WHERE FollowerCod=%ld) AS my_followed,"
" usr_data"
"SELECT DISTINCT "
"usr_follow.FollowedCod AS UsrCod"
" FROM usr_follow,"
"(SELECT FollowedCod"
" FROM usr_follow"
" WHERE FollowerCod=%ld) AS my_followed,"
" usr_data"
" WHERE usr_follow.FollowerCod=my_followed.FollowedCod"
" AND usr_follow.FollowedCod<>%ld"
" AND usr_follow.FollowedCod=usr_data.UsrCod"
@ -142,7 +147,8 @@ unsigned Fol_DB_GetUsrsToFollow (unsigned MaxUsrsToShow,
" UNION "
// 2. Users who share any course with me
"("
"SELECT DISTINCT crs_users.UsrCod"
"SELECT DISTINCT "
"crs_users.UsrCod"
" FROM crs_users,"
"(SELECT CrsCod"
" FROM crs_users"
@ -158,12 +164,13 @@ unsigned Fol_DB_GetUsrsToFollow (unsigned MaxUsrsToShow,
" UNION "
// 3. Users who share any course with me with another role
"("
"SELECT DISTINCT crs_users.UsrCod"
" FROM crs_users,"
"(SELECT CrsCod,Role"
" FROM crs_users"
" WHERE UsrCod=%ld) AS my_crs_role,"
" usr_data"
"SELECT DISTINCT "
"crs_users.UsrCod"
" FROM crs_users,"
"(SELECT CrsCod,Role"
" FROM crs_users"
" WHERE UsrCod=%ld) AS my_crs_role,"
" usr_data"
" WHERE crs_users.CrsCod=my_crs_role.CrsCod"
" AND crs_users.Role<>my_crs_role.Role"
" AND crs_users.UsrCod=usr_data.UsrCod"
@ -197,11 +204,11 @@ unsigned Fol_DB_GetUsrsToFollow (unsigned MaxUsrsToShow,
" AND usr_data.FirstName<>''" // First name not empty
"%s" // SubQuery4
// Do not select my followed
" AND usr_data.UsrCod NOT IN"
" (SELECT FollowedCod"
" FROM usr_follow"
" WHERE FollowerCod=%ld)"
" AND usr_data.UsrCod>=random_usr.RandomUsrCod" // random user code could not exists in table of users
" AND usr_data.UsrCod NOT IN"
" (SELECT FollowedCod"
" FROM usr_follow"
" WHERE FollowerCod=%ld)"
" AND usr_data.UsrCod>=random_usr.RandomUsrCod" // random user code could not exists in table of users
// Get only MaxUsrsToShow users
" LIMIT %u"
")"

View File

@ -374,7 +374,8 @@ unsigned For_DB_GetPublishersInThreadExceptMe (MYSQL_RES **mysql_res,long PstCod
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get publishers in thread",
"SELECT DISTINCT(UsrCod)"
"SELECT DISTINCT "
"UsrCod"
" FROM for_posts"
" WHERE ThrCod=(SELECT ThrCod"
" FROM for_posts"

View File

@ -743,7 +743,8 @@ unsigned Gam_DB_GetTstTagsPresentInAGame (MYSQL_RES **mysql_res,long GamCod)
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get tags present in a match result",
"SELECT tst_tags.TagTxt" // row[0]
" FROM (SELECT DISTINCT(tst_question_tags.TagCod)"
" FROM (SELECT DISTINCT "
"tst_question_tags.TagCod"
" FROM tst_question_tags,gam_questions"
" WHERE gam_questions.GamCod=%ld"
" AND gam_questions.QstCod=tst_question_tags.QstCod) AS TagsCods,"

View File

@ -300,7 +300,8 @@ unsigned Grp_DB_CountNumUsrsInNoGrpsOfType (Rol_Role_t Role,long GrpTypCod)
" WHERE CrsCod=%ld"
" AND Role=%u"
" AND UsrCod NOT IN"
" (SELECT DISTINCT grp_users.UsrCod"
" (SELECT DISTINCT "
"grp_users.UsrCod"
" FROM grp_groups,"
"grp_users"
" WHERE grp_groups.GrpTypCod=%ld"

View File

@ -65,7 +65,7 @@ unsigned Hie_DB_GetInsCtrDegAdminBy (MYSQL_RES **mysql_res,long UsrCod)
" FROM usr_admins"
" WHERE UsrCod=%ld"
" AND Scope='%s')"
" UNION "
" UNION "
"(SELECT %u AS S," // row[0]
"usr_admins.Cod," // row[1]
"ins_instits.FullName" // row[2]
@ -74,7 +74,7 @@ unsigned Hie_DB_GetInsCtrDegAdminBy (MYSQL_RES **mysql_res,long UsrCod)
" WHERE usr_admins.UsrCod=%ld"
" AND usr_admins.Scope='%s'"
" AND usr_admins.Cod=ins_instits.InsCod)"
" UNION "
" UNION "
"(SELECT %u AS S," // row[0]
"usr_admins.Cod," // row[1]
"ctr_centers.FullName" // row[2]
@ -83,7 +83,7 @@ unsigned Hie_DB_GetInsCtrDegAdminBy (MYSQL_RES **mysql_res,long UsrCod)
" WHERE usr_admins.UsrCod=%ld"
" AND usr_admins.Scope='%s'"
" AND usr_admins.Cod=ctr_centers.CtrCod)"
" UNION "
" UNION "
"(SELECT %u AS S," // row[0]
"usr_admins.Cod," // row[1]
"deg_degrees.FullName" // row[2]
@ -92,8 +92,8 @@ unsigned Hie_DB_GetInsCtrDegAdminBy (MYSQL_RES **mysql_res,long UsrCod)
" WHERE usr_admins.UsrCod=%ld"
" AND usr_admins.Scope='%s'"
" AND usr_admins.Cod=deg_degrees.DegCod)"
" ORDER BY S,"
"FullName",
" ORDER BY S,"
"FullName",
(unsigned) HieLvl_SYS,UsrCod,Sco_GetDBStrFromScope (HieLvl_SYS),
(unsigned) HieLvl_INS,UsrCod,Sco_GetDBStrFromScope (HieLvl_INS),
(unsigned) HieLvl_CTR,UsrCod,Sco_GetDBStrFromScope (HieLvl_CTR),

View File

@ -163,7 +163,7 @@ unsigned Hld_DB_GetListHolidays (MYSQL_RES **mysql_res,Hld_Order_t SelectedOrder
" WHERE hld_holidays.InsCod=%ld"
" AND hld_holidays.PlcCod=plc_places.PlcCod"
" AND plc_places.InsCod=%ld)"
" UNION "
" UNION "
"(SELECT HldCod," // row[0]
"PlcCod," // row[1]
"'' as Place," // row[2]
@ -174,10 +174,11 @@ unsigned Hld_DB_GetListHolidays (MYSQL_RES **mysql_res,Hld_Order_t SelectedOrder
" FROM hld_holidays"
" WHERE InsCod=%ld"
" AND PlcCod NOT IN"
"(SELECT DISTINCT PlcCod"
"(SELECT DISTINCT "
"PlcCod"
" FROM plc_places"
" WHERE InsCod=%ld))"
" ORDER BY %s",
" ORDER BY %s",
Gbl.Hierarchy.Ins.InsCod,
Gbl.Hierarchy.Ins.InsCod,
Gbl.Hierarchy.Ins.InsCod,
@ -205,7 +206,7 @@ unsigned Hld_DB_GetDataOfHolidayByCod (MYSQL_RES **mysql_res,long HldCod)
" AND hld_holidays.InsCod=%ld"
" AND hld_holidays.PlcCod=plc_places.PlcCod"
" AND plc_places.InsCod=%ld)"
" UNION "
" UNION "
"(SELECT PlcCod,"
"'' as Place,"
"HldTyp,"
@ -216,7 +217,8 @@ unsigned Hld_DB_GetDataOfHolidayByCod (MYSQL_RES **mysql_res,long HldCod)
" WHERE HldCod=%ld"
" AND InsCod=%ld"
" AND PlcCod NOT IN"
"(SELECT DISTINCT PlcCod"
"(SELECT DISTINCT "
"PlcCod"
" FROM plc_places"
" WHERE InsCod=%ld))",
HldCod,

View File

@ -96,7 +96,7 @@ unsigned Ind_DB_GetTableOfCourses (MYSQL_RES **mysql_res,
if (Indicators->DegTypCod > 0)
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get courses",
"SELECT DISTINCTROW "
"SELECT DISTINCT "
"deg_degrees.FullName," // row[0]
"crs_courses.FullName," // row[1]
"crs_courses.CrsCod," // row[2]
@ -119,7 +119,7 @@ unsigned Ind_DB_GetTableOfCourses (MYSQL_RES **mysql_res,
else
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get courses",
"SELECT DISTINCTROW "
"SELECT DISTINCT "
"deg_degrees.FullName," // row[0]
"crs_courses.FullName," // row[1]
"crs_courses.CrsCod," // row[2]
@ -171,7 +171,7 @@ unsigned Ind_DB_GetTableOfCourses (MYSQL_RES **mysql_res,
if (Indicators->DptCod >= 0) // 0 means another department
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get courses",
"SELECT DISTINCTROW "
"SELECT DISTINCT "
"deg_degrees.FullName," // row[0]
"crs_courses.FullName," // row[1]
"crs_courses.CrsCod," // row[2]
@ -217,7 +217,7 @@ unsigned Ind_DB_GetTableOfCourses (MYSQL_RES **mysql_res,
if (Indicators->DptCod >= 0) // 0 means another department
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get courses",
"SELECT DISTINCTROW "
"SELECT DISTINCT "
"deg_degrees.FullName," // row[0]
"crs_courses.FullName," // row[1]
"crs_courses.CrsCod," // row[2]
@ -259,7 +259,7 @@ unsigned Ind_DB_GetTableOfCourses (MYSQL_RES **mysql_res,
if (Indicators->DptCod >= 0) // 0 means another department
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get courses",
"SELECT DISTINCTROW "
"SELECT DISTINCT "
"deg_degrees.FullName," // row[0]
"crs_courses.FullName," // row[1]
"crs_courses.CrsCod," // row[2]
@ -297,7 +297,7 @@ unsigned Ind_DB_GetTableOfCourses (MYSQL_RES **mysql_res,
if (Indicators->DptCod >= 0) // 0 means another department
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get courses",
"SELECT DISTINCTROW "
"SELECT DISTINCT "
"deg_degrees.FullName," // row[0]
"crs_courses.FullName," // row[1]
"crs_courses.CrsCod," // row[2]
@ -335,7 +335,7 @@ unsigned Ind_DB_GetTableOfCourses (MYSQL_RES **mysql_res,
if (Indicators->DptCod >= 0) // 0 means another department
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get courses",
"SELECT DISTINCTROW "
"SELECT DISTINCT "
"deg_degrees.FullName," // row[0]
"crs_courses.FullName," // row[1]
"crs_courses.CrsCod," // row[2]

View File

@ -273,8 +273,9 @@ unsigned Ins_DB_GetInssInCtyOrderedByShrtName (MYSQL_RES **mysql_res,long CtyCod
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get institutions",
"SELECT DISTINCT InsCod," // row[0]
"ShortName" // row[1]
"SELECT DISTINCT "
"InsCod," // row[0]
"ShortName" // row[1]
" FROM ins_instits"
" WHERE CtyCod=%ld"
" ORDER BY ShortName",
@ -343,7 +344,8 @@ unsigned Ins_DB_GetFullListOfInssInCty (MYSQL_RES **mysql_res,long CtyCod)
" FROM ins_instits"
" WHERE CtyCod=%ld"
" AND InsCod NOT IN"
" (SELECT DISTINCT InsCod"
" (SELECT DISTINCT "
"InsCod"
" FROM usr_data))"
" ORDER BY %s",
CtyCod,

View File

@ -378,7 +378,7 @@ unsigned Mai_DB_GetMailDomains (MYSQL_RES **mysql_res)
" FROM ntf_mail_domains,"
"T1"
" WHERE ntf_mail_domains.Domain=T1.Domain COLLATE 'latin1_bin')"
" UNION "
" UNION "
"(SELECT MaiCod," // row[0]
"Domain," // row[1]
"Info," // row[2]
@ -387,7 +387,7 @@ unsigned Mai_DB_GetMailDomains (MYSQL_RES **mysql_res)
" WHERE Domain NOT IN"
" (SELECT Domain COLLATE 'latin1_bin'"
" FROM T2))"
" ORDER BY %s", // COLLATE necessary to avoid error in comparisons
" ORDER BY %s", // COLLATE necessary to avoid error in comparisons
OrderBySubQuery[Gbl.Mails.SelectedOrder]);
}

View File

@ -1017,7 +1017,8 @@ unsigned Mch_DB_GetUsrsWhoHavePlayedGam (MYSQL_RES **mysql_res,long GamCod)
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get users in game",
"SELECT users.UsrCod"
" FROM (SELECT DISTINCT mch_results.UsrCod AS UsrCod"
" FROM (SELECT DISTINCT "
"mch_results.UsrCod AS UsrCod"
" FROM mch_results,"
"mch_matches,"
"gam_games"

View File

@ -266,8 +266,9 @@ unsigned Msg_DB_GetDistinctCrssInMyRcvMsgs (MYSQL_RES **mysql_res)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get distinct courses in your messages",
"SELECT DISTINCT crs_courses.CrsCod," // row[0]
"crs_courses.ShortName" // row[1]
"SELECT DISTINCT "
"crs_courses.CrsCod," // row[0]
"crs_courses.ShortName" // row[1]
" FROM msg_rcv,"
"msg_snt,"
"crs_courses"
@ -286,8 +287,9 @@ unsigned Msg_DB_GetDistinctCrssInMySntMsgs (MYSQL_RES **mysql_res)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get distinct courses in your messages",
"SELECT DISTINCT crs_courses.CrsCod," // row[0]
"crs_courses.ShortName" // row[1]
"SELECT DISTINCT "
"crs_courses.CrsCod," // row[0]
"crs_courses.ShortName" // row[1]
" FROM msg_snt,"
"crs_courses"
" WHERE msg_snt.UsrCod=%ld"
@ -448,7 +450,7 @@ unsigned Msg_DB_GetSntOrRcvMsgs (MYSQL_RES **mysql_res,
" AND msg_rcv.MsgCod=msg_snt.MsgCod"
" AND msg_snt.CrsCod=%ld"
" AND msg_snt.UsrCod=usr_data.UsrCod%s)"
" UNION "
" UNION "
"(SELECT msg_rcv.MsgCod"
" FROM msg_rcv,"
"msg_snt_deleted,"
@ -470,7 +472,7 @@ unsigned Msg_DB_GetSntOrRcvMsgs (MYSQL_RES **mysql_res,
"%s"
" AND msg_rcv.MsgCod=msg_snt.MsgCod"
" AND msg_snt.CrsCod=%ld)"
" UNION "
" UNION "
"(SELECT msg_rcv.MsgCod"
" FROM msg_rcv,"
"msg_snt_deleted"
@ -486,7 +488,8 @@ unsigned Msg_DB_GetSntOrRcvMsgs (MYSQL_RES **mysql_res,
case Msg_SENT:
if (FilterFromToSubquery[0])
{
if (asprintf (&SubQuery,"(SELECT DISTINCT msg_snt.MsgCod"
if (asprintf (&SubQuery,"(SELECT DISTINCT "
"msg_snt.MsgCod"
" FROM msg_snt,"
"msg_rcv,"
"usr_data"
@ -494,9 +497,10 @@ unsigned Msg_DB_GetSntOrRcvMsgs (MYSQL_RES **mysql_res,
" AND msg_snt.CrsCod=%ld"
" AND msg_snt.MsgCod=msg_rcv.MsgCod"
" AND msg_rcv.UsrCod=usr_data.UsrCod"
"%s)"
" UNION "
"(SELECT DISTINCT msg_snt.MsgCod"
"%s)"
" UNION "
"(SELECT DISTINCT "
"msg_snt.MsgCod"
" FROM msg_snt,"
"msg_rcv_deleted,"
"usr_data"
@ -504,7 +508,7 @@ unsigned Msg_DB_GetSntOrRcvMsgs (MYSQL_RES **mysql_res,
" AND msg_snt.CrsCod=%ld"
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
" AND msg_rcv_deleted.UsrCod=usr_data.UsrCod"
"%s)",
"%s)",
UsrCod,Messages->FilterCrsCod,FilterFromToSubquery,
UsrCod,Messages->FilterCrsCod,FilterFromToSubquery) < 0)
Err_NotEnoughMemoryExit ();
@ -535,20 +539,20 @@ unsigned Msg_DB_GetSntOrRcvMsgs (MYSQL_RES **mysql_res,
"msg_snt,"
"usr_data"
" WHERE msg_rcv.UsrCod=%ld"
"%s"
"%s"
" AND msg_rcv.MsgCod=msg_snt.MsgCod"
" AND msg_snt.UsrCod=usr_data.UsrCod"
"%s)"
" UNION "
"%s)"
" UNION "
"(SELECT msg_rcv.MsgCod"
" FROM msg_rcv,"
"msg_snt_deleted,"
"usr_data"
" WHERE msg_rcv.UsrCod=%ld"
"%s"
"%s"
" AND msg_rcv.MsgCod=msg_snt_deleted.MsgCod"
" AND msg_snt_deleted.UsrCod=usr_data.UsrCod"
"%s)",
"%s)",
UsrCod,StrUnreadMsg,FilterFromToSubquery,
UsrCod,StrUnreadMsg,FilterFromToSubquery) < 0)
Err_NotEnoughMemoryExit ();
@ -839,7 +843,7 @@ unsigned Msg_DB_GetKnownRecipients (MYSQL_RES **mysql_res,long MsgCod)
"usr_data"
" WHERE msg_rcv.MsgCod=%ld"
" AND msg_rcv.UsrCod=usr_data.UsrCod)"
" UNION "
" UNION "
"(SELECT msg_rcv_deleted.UsrCod," // row[0]
"'Y'," // row[1]
"msg_rcv_deleted.Open," // row[2]
@ -1372,7 +1376,8 @@ void Msg_DB_MoveUnusedMsgsContentToDeleted (void)
" (SELECT MsgCod"
" FROM msg_snt)"
" AND MsgCod NOT IN"
" (SELECT DISTINCT MsgCod"
" (SELECT DISTINCT "
"MsgCod"
" FROM msg_rcv)");
/* Messages in msg_content_deleted older than a certain time
@ -1385,7 +1390,8 @@ void Msg_DB_MoveUnusedMsgsContentToDeleted (void)
" (SELECT MsgCod"
" FROM msg_snt)"
" AND MsgCod NOT IN"
" (SELECT DISTINCT MsgCod"
" (SELECT DISTINCT "
"MsgCod"
" FROM msg_rcv)");
}

View File

@ -451,7 +451,8 @@ unsigned Ntf_DB_GetUsrsWhoMustBeNotified (MYSQL_RES **mysql_res)
// !(Status & (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED))
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get users who must be notified",
"SELECT DISTINCT ToUsrCod"
"SELECT DISTINCT "
"ToUsrCod"
" FROM ntf_notifications"
" WHERE TimeNotif<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)"
" AND (Status & %u)<>0"

View File

@ -226,7 +226,8 @@ unsigned Pho_DB_QueryDegrees (MYSQL_RES **mysql_res,
long Pho_DB_GetADegWithStdsNotInTableOfComputedDegs (void)
{
return DB_QuerySELECTCode ("can not get degree",
"SELECT DISTINCT deg_degrees.DegCod"
"SELECT DISTINCT "
"deg_degrees.DegCod"
" FROM deg_degrees,"
"crs_courses,"
"crs_users"
@ -234,7 +235,8 @@ long Pho_DB_GetADegWithStdsNotInTableOfComputedDegs (void)
" AND crs_courses.CrsCod=crs_users.CrsCod"
" AND crs_users.Role=%u"
" AND deg_degrees.DegCod NOT IN"
" (SELECT DISTINCT DegCod"
" (SELECT DISTINCT "
"DegCod"
" FROM sta_degrees)"
" LIMIT 1",
(unsigned) Rol_STD);

View File

@ -107,7 +107,7 @@ unsigned Plc_DB_GetListPlaces (MYSQL_RES **mysql_res,Plc_Order_t SelectedOrder)
" AND plc_places.PlcCod=ctr_centers.PlcCod"
" AND ctr_centers.InsCod=%ld"
" GROUP BY plc_places.PlcCod)"
" UNION "
" UNION "
"(SELECT PlcCod,"
"ShortName,"
"FullName,"
@ -115,7 +115,8 @@ unsigned Plc_DB_GetListPlaces (MYSQL_RES **mysql_res,Plc_Order_t SelectedOrder)
" FROM plc_places"
" WHERE InsCod=%ld"
" AND PlcCod NOT IN"
" (SELECT DISTINCT PlcCod"
" (SELECT DISTINCT "
"PlcCod"
" FROM ctr_centers"
" WHERE InsCod=%ld))"
" ORDER BY %s",
@ -143,14 +144,15 @@ unsigned Plc_DB_GetDataOfPlaceByCod (MYSQL_RES **mysql_res,long PlcCod)
" AND plc_places.PlcCod=ctr_centers.PlcCod"
" AND ctr_centers.PlcCod=%ld"
" GROUP BY plc_places.PlcCod)"
" UNION "
" UNION "
"(SELECT ShortName," // row[0]
"FullName," // row[1]
"0" // row[2]
" FROM plc_places"
" WHERE PlcCod=%ld"
" AND PlcCod NOT IN"
" (SELECT DISTINCT PlcCod"
" (SELECT DISTINCT "
"PlcCod"
" FROM ctr_centers))",
PlcCod,
PlcCod,

View File

@ -302,7 +302,7 @@ unsigned Prf_DB_GetRankingFigure (MYSQL_RES **mysql_res,const char *FieldName)
case HieLvl_CTY:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get ranking",
"SELECT DISTINCTROW "
"SELECT DISTINCT "
"usr_figures.UsrCod," // row[0]
"usr_figures.%s" // row[1]
" FROM ins_instits,"
@ -331,7 +331,7 @@ unsigned Prf_DB_GetRankingFigure (MYSQL_RES **mysql_res,const char *FieldName)
case HieLvl_INS:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get ranking",
"SELECT DISTINCTROW "
"SELECT DISTINCT "
"usr_figures.UsrCod," // row[0]
"usr_figures.%s" // row[1]
" FROM ctr_centers,"
@ -358,7 +358,7 @@ unsigned Prf_DB_GetRankingFigure (MYSQL_RES **mysql_res,const char *FieldName)
case HieLvl_CTR:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get ranking",
"SELECT DISTINCTROW "
"SELECT DISTINCT "
"usr_figures.UsrCod," // row[0]
"usr_figures.%s" // row[1]
" FROM deg_degrees,"
@ -383,7 +383,7 @@ unsigned Prf_DB_GetRankingFigure (MYSQL_RES **mysql_res,const char *FieldName)
case HieLvl_DEG:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get ranking",
"SELECT DISTINCTROW "
"SELECT DISTINCT "
"usr_figures.UsrCod," // row[0]
"usr_figures.%s" // row[1]
" FROM crs_courses,"
@ -406,7 +406,7 @@ unsigned Prf_DB_GetRankingFigure (MYSQL_RES **mysql_res,const char *FieldName)
case HieLvl_CRS:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get ranking",
"SELECT DISTINCTROW "
"SELECT DISTINCT "
"usr_figures.UsrCod," // row[0]
"usr_figures.%s" // row[1]
" FROM crs_users,"
@ -456,7 +456,7 @@ unsigned Prf_DB_GetRankingClicksPerDay (MYSQL_RES **mysql_res)
case HieLvl_CTY:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get ranking",
"SELECT DISTINCTROW "
"SELECT DISTINCT "
"usr_figures.UsrCod," // row[0]
"usr_figures.NumClicks/(DATEDIFF(NOW(),"
"usr_figures.FirstClickTime)+1) AS NumClicksPerDay" // row[1]
@ -484,7 +484,7 @@ unsigned Prf_DB_GetRankingClicksPerDay (MYSQL_RES **mysql_res)
case HieLvl_INS:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get ranking",
"SELECT DISTINCTROW "
"SELECT DISTINCT "
"usr_figures.UsrCod," // row[0]
"usr_figures.NumClicks/(DATEDIFF(NOW(),"
"usr_figures.FirstClickTime)+1) AS NumClicksPerDay" // row[1]
@ -510,7 +510,7 @@ unsigned Prf_DB_GetRankingClicksPerDay (MYSQL_RES **mysql_res)
case HieLvl_CTR:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get ranking",
"SELECT DISTINCTROW "
"SELECT DISTINCT "
"usr_figures.UsrCod," // row[0]
"usr_figures.NumClicks/(DATEDIFF(NOW(),"
"usr_figures.FirstClickTime)+1) AS NumClicksPerDay" // row[1]
@ -534,7 +534,7 @@ unsigned Prf_DB_GetRankingClicksPerDay (MYSQL_RES **mysql_res)
case HieLvl_DEG:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get ranking",
"SELECT DISTINCTROW "
"SELECT DISTINCT "
"usr_figures.UsrCod," // row[0]
"usr_figures.NumClicks/(DATEDIFF(NOW(),"
"usr_figures.FirstClickTime)+1) AS NumClicksPerDay" // row[1]
@ -556,7 +556,7 @@ unsigned Prf_DB_GetRankingClicksPerDay (MYSQL_RES **mysql_res)
case HieLvl_CRS:
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get ranking",
"SELECT DISTINCTROW "
"SELECT DISTINCT "
"usr_figures.UsrCod," // row[0]
"usr_figures.NumClicks/(DATEDIFF(NOW(),"
"usr_figures.FirstClickTime)+1) AS NumClicksPerDay" // row[1]

View File

@ -435,11 +435,12 @@ unsigned Qst_DB_GetQstsForNewTestPrint (MYSQL_RES **mysql_res,
/* Begin query */
// Reject questions with any tag hidden
// Select only questions with tags
// DISTINCTROW is necessary to not repeat questions
// DISTINCT is necessary to not repeat questions
snprintf (Query,Qst_MAX_BYTES_QUERY_QUESTIONS + 1,
"SELECT DISTINCTROW tst_questions.QstCod," // row[0]
"tst_questions.AnsType," // row[1]
"tst_questions.Shuffle" // row[2]
"SELECT DISTINCT "
"tst_questions.QstCod," // row[0]
"tst_questions.AnsType," // row[1]
"tst_questions.Shuffle" // row[2]
" FROM tst_questions,tst_question_tags,tst_tags"
" WHERE tst_questions.CrsCod=%ld"
" AND tst_questions.QstCod NOT IN"

View File

@ -93,7 +93,7 @@ unsigned Rol_DB_GetRolesInAllCrss (MYSQL_RES **mysql_res,long UsrCod)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get user's roles in all courses",
"SELECT DISTINCT(Role)" // row[0]
"SELECT DISTINCT Role" // row[0]
" FROM crs_users"
" WHERE UsrCod=%ld",
UsrCod);

View File

@ -81,10 +81,10 @@ unsigned Sta_DB_GetHits (MYSQL_RES **mysql_res,
Str_Copy (SubQueryCountType,"COUNT(*)",sizeof (SubQueryCountType) - 1);
break;
case Sta_DISTINCT_USRS:
sprintf (SubQueryCountType,"COUNT(DISTINCT(%s.UsrCod))",LogTable);
sprintf (SubQueryCountType,"COUNT(DISTINCT %s.UsrCod)",LogTable);
break;
case Sta_CLICKS_PER_USR:
sprintf (SubQueryCountType,"COUNT(*)/GREATEST(COUNT(DISTINCT(%s.UsrCod)),1)+0.000000",LogTable);
sprintf (SubQueryCountType,"COUNT(*)/GREATEST(COUNT(DISTINCT %s.UsrCod),1)+0.000000",LogTable);
break;
case Sta_GENERATION_TIME:
sprintf (SubQueryCountType,"(AVG(%s.TimeToGenerate)/1E6)+0.000000",LogTable);

View File

@ -658,8 +658,9 @@ unsigned Svy_DB_GetUsrsFromSurveyExceptMe (MYSQL_RES **mysql_res,long SvyCod)
" AND svy_surveys.Cod=crs_users.CrsCod"
" AND crs_users.UsrCod<>%ld"
" AND (svy_surveys.Roles&(1<<crs_users.Role))<>0)"
" UNION "
"(SELECT DISTINCT grp_users.UsrCod"
" UNION "
"(SELECT DISTINCT "
"grp_users.UsrCod"
" FROM svy_groups,"
"grp_users,"
"svy_surveys,"

View File

@ -333,7 +333,8 @@ void Tag_DB_RemoveUnusedTagsFromCrs (long CrsCod)
"DELETE FROM tst_tags"
" WHERE CrsCod=%ld"
" AND TagCod NOT IN"
" (SELECT DISTINCT tst_question_tags.TagCod"
" (SELECT DISTINCT "
"tst_question_tags.TagCod"
" FROM tst_questions,"
"tst_question_tags"
" WHERE tst_questions.CrsCod=%ld"

View File

@ -376,7 +376,8 @@ unsigned Tst_DB_GetTagsPresentInAPrint (MYSQL_RES **mysql_res,long PrnCod)
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get tags present in a test",
"SELECT tst_tags.TagTxt" // row[0]
" FROM (SELECT DISTINCT(tst_question_tags.TagCod)"
" FROM (SELECT DISTINCT "
"tst_question_tags.TagCod"
" FROM tst_question_tags,"
"tst_exam_questions"
" WHERE tst_exam_questions.ExaCod=%ld"

View File

@ -1079,7 +1079,8 @@ unsigned Tml_DB_GetPublishersInNoteExceptMe (MYSQL_RES **mysql_res,long PubCod)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get publishers of a note",
"SELECT DISTINCT(PublisherCod)"
"SELECT DISTINCT "
"PublisherCod"
" FROM tml_pubs"
" WHERE NotCod=(SELECT NotCod"
" FROM tml_pubs"

View File

@ -125,8 +125,8 @@ unsigned Tmt_DB_GetTimeTable (MYSQL_RES **mysql_res,
"tmt_courses.ClassType," // row[4]
"tmt_courses.GrpCod," // row[5]
"tmt_courses.CrsCod" // row[6]
" FROM tmt_courses,"
"crs_users"
" FROM crs_users,"
"tmt_courses"
" WHERE crs_users.UsrCod=%ld"
" AND tmt_courses.GrpCod=-1"
" AND tmt_courses.CrsCod=crs_users.CrsCod"
@ -172,8 +172,8 @@ unsigned Tmt_DB_GetTimeTable (MYSQL_RES **mysql_res,
"tmt_courses.ClassType," // row[4]
"tmt_courses.GrpCod," // row[5]
"tmt_courses.CrsCod" // row[6]
" FROM tmt_courses,"
"crs_users"
" FROM crs_users,"
"tmt_courses"
" WHERE crs_users.UsrCod=%ld"
" AND tmt_courses.CrsCod=crs_users.CrsCod"
" UNION "

View File

@ -2945,7 +2945,8 @@ static void Usr_BuildQueryToGetUsrsLstCrs (char **Query,Rol_Role_t Role)
if (NumPositiveCods)
{
Str_Concat (*Query," AND (crs_users.UsrCod IN"
" (SELECT DISTINCT UsrCod"
" (SELECT DISTINCT "
"UsrCod"
" FROM grp_users"
" WHERE",
Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
@ -2979,7 +2980,8 @@ static void Usr_BuildQueryToGetUsrsLstCrs (char **Query,Rol_Role_t Role)
Str_Concat (*Query," AND (",Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
/* Select all students of the course who don't belong to any group of type GrpTypCod */
Str_Concat (*Query,"crs_users.UsrCod NOT IN"
" (SELECT DISTINCT grp_users.UsrCod"
" (SELECT DISTINCT "
"grp_users.UsrCod"
" FROM grp_groups,"
"grp_users"
" WHERE grp_groups.GrpTypCod='",
@ -3023,7 +3025,8 @@ void Usr_GetListUsrs (HieLvl_Level_t Scope,Rol_Role_t Role)
{
char *Query = NULL;
const char *QueryFields =
"DISTINCT usr_data.UsrCod,"
"DISTINCT "
"usr_data.UsrCod,"
"usr_data.EncryptedUsrCod,"
"usr_data.Password,"
"usr_data.Surname1,"
@ -3181,7 +3184,8 @@ void Usr_SearchListUsrs (Rol_Role_t Role)
char *Query = NULL;
char SubQueryRole[64];
const char *QueryFields =
"DISTINCT usr_data.UsrCod,"
"DISTINCT "
"usr_data.UsrCod,"
"usr_data.EncryptedUsrCod,"
"usr_data.Password,"
"usr_data.Surname1,"
@ -3581,7 +3585,8 @@ static void Usr_GetAdmsLst (HieLvl_Level_t Scope)
"SELECT %s"
" FROM usr_data"
" WHERE UsrCod IN "
"(SELECT DISTINCT UsrCod"
"(SELECT DISTINCT "
"UsrCod"
" FROM usr_admins)"
" ORDER BY Surname1,"
"Surname2,"
@ -3870,30 +3875,10 @@ void Usr_GetUnorderedStdsCodesInDeg (long DegCod)
{
char *Query = NULL;
/***** Get the students in a degree from database *****/
DB_BuildQuery (&Query,
"SELECT DISTINCT usr_data.UsrCod," // row[ 0]
"usr_data.EncryptedUsrCod," // row[ 1]
"usr_data.Password," // row[ 2]
"usr_data.Surname1," // row[ 3]
"usr_data.Surname2," // row[ 4]
"usr_data.FirstName," // row[ 5]
"usr_data.Sex," // row[ 6]
"usr_data.Photo," // row[ 7]
"usr_data.PhotoVisibility," // row[ 8]
"usr_data.CtyCod," // row[ 9]
"usr_data.InsCod" // row[10]
" FROM crs_courses,"
"crs_users,"
"usr_data"
" WHERE crs_courses.DegCod=%ld"
" AND crs_courses.CrsCod=crs_users.CrsCod"
" AND crs_users.Role=%u"
" AND crs_users.UsrCod=usr_data.UsrCod",
DegCod,
(unsigned) Rol_STD);
/***** Build query string *****/
Usr_DB_BuildQueryToGetUnorderedStdsCodesInDeg (DegCod,&Query);
/***** Get list of students from database *****/
/***** Get list of students *****/
Usr_GetListUsrsFromQuery (Query,Rol_STD,HieLvl_DEG);
/***** Free query string *****/
@ -3986,10 +3971,9 @@ static void Usr_GetListUsrsFromQuery (char *Query,Rol_Role_t Role,HieLvl_Level_t
/* Get user's photo visibility (row[8]) */
UsrInList->PhotoVisibility = Pri_GetVisibilityFromStr (row[8]);
/* Get user's country code (row[9]) */
UsrInList->CtyCod = Str_ConvertStrCodToLongCod (row[9]);
/* Get user's institution code (row[10]) */
/* Get user's country code (row[9])
and user's institution code (row[10]) */
UsrInList->CtyCod = Str_ConvertStrCodToLongCod (row[ 9]);
UsrInList->InsCod = Str_ConvertStrCodToLongCod (row[10]);
/* Get user's role and acceptance of enrolment in course(s)
@ -4025,9 +4009,9 @@ static void Usr_GetListUsrsFromQuery (char *Query,Rol_Role_t Role,HieLvl_Level_t
break;
}
break;
case Rol_GST: // Guests have no courses,...
// ...so they have not accepted...
// ...inscription in any course
case Rol_GST: // Guests have no courses,...
// ...so they have not accepted...
// ...inscription in any course
case Rol_DEG_ADM: // Any admin (degree, center, institution or system)
UsrInList->RoleInCurrentCrsDB = Rol_UNK;
UsrInList->Accepted = false;
@ -4462,7 +4446,7 @@ bool Usr_GetListMsgRecipientsWrittenExplicitelyBySender (bool WriteErrorMsgs)
Usr_DONT_GET_ROLE_IN_CURRENT_CRS);
/* Find if encrypted user's code is already in list */
if (!Usr_FindEncryptedUsrCodsInListOfSelectedEncryptedUsrCods (UsrDat.EnUsrCod,&Gbl.Usrs.Selected)) // If not in list ==> add it
if (!Usr_FindEncryptedUsrCodInListOfSelectedEncryptedUsrCods (UsrDat.EnUsrCod,&Gbl.Usrs.Selected)) // If not in list ==> add it
{
LengthUsrCod = strlen (UsrDat.EnUsrCod);
@ -4513,8 +4497,8 @@ bool Usr_GetListMsgRecipientsWrittenExplicitelyBySender (bool WriteErrorMsgs)
/*****************************************************************************/
// Returns true if EncryptedUsrCodToFind is in list
bool Usr_FindEncryptedUsrCodsInListOfSelectedEncryptedUsrCods (const char *EncryptedUsrCodToFind,
struct SelectedUsrs *SelectedUsrs)
bool Usr_FindEncryptedUsrCodInListOfSelectedEncryptedUsrCods (const char *EncryptedUsrCodToFind,
struct SelectedUsrs *SelectedUsrs)
{
const char *Ptr;
char EncryptedUsrCod[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1];
@ -4742,12 +4726,12 @@ void Usr_ShowFormsToSelectUsrListType (void (*FuncParams) (void *Args),void *Arg
/***** Select Set_USR_LIST_AS_CLASS_PHOTO *****/
HTM_DIV_Begin ("class=\"%s\"",
Gbl.Usrs.Me.ListType == Set_USR_LIST_AS_CLASS_PHOTO ? "PREF_ON" :
"PREF_OFF");
"PREF_OFF");
Set_FormToSelectUsrListType (FuncParams,Args,
Set_USR_LIST_AS_CLASS_PHOTO);
/* Number of columns in the class photo */
Frm_BeginFormAnchor (Gbl.Action.Act, // Repeat current action
Frm_BeginFormAnchor (Gbl.Action.Act, // Repeat current action
Usr_USER_LIST_SECTION_ID);
Grp_PutParamsCodGrps ();
Set_PutParamUsrListType (Set_USR_LIST_AS_CLASS_PHOTO);
@ -4761,12 +4745,12 @@ void Usr_ShowFormsToSelectUsrListType (void (*FuncParams) (void *Args),void *Arg
/***** Select Usr_LIST_AS_LISTING *****/
HTM_DIV_Begin ("class=\"%s\"",
Gbl.Usrs.Me.ListType == Set_USR_LIST_AS_LISTING ? "PREF_ON" :
"PREF_OFF");
"PREF_OFF");
Set_FormToSelectUsrListType (FuncParams,Args,
Set_USR_LIST_AS_LISTING);
/* See the photos in list? */
Frm_BeginFormAnchor (Gbl.Action.Act, // Repeat current action
Frm_BeginFormAnchor (Gbl.Action.Act, // Repeat current action
Usr_USER_LIST_SECTION_ID);
Grp_PutParamsCodGrps ();
Set_PutParamUsrListType (Set_USR_LIST_AS_LISTING);
@ -5066,8 +5050,8 @@ static Usr_Sex_t Usr_GetSexOfUsrsLst (Rol_Role_t Role)
unsigned Usr_GetColumnsForSelectUsrs (void)
{
return (Gbl.Usrs.Me.ListType == Set_USR_LIST_AS_CLASS_PHOTO) ? Gbl.Usrs.ClassPhoto.Cols :
(Gbl.Usrs.Listing.WithPhotos ? 1 + Usr_NUM_MAIN_FIELDS_DATA_USR :
Usr_NUM_MAIN_FIELDS_DATA_USR);
(Gbl.Usrs.Listing.WithPhotos ? 1 + Usr_NUM_MAIN_FIELDS_DATA_USR :
Usr_NUM_MAIN_FIELDS_DATA_USR);
}
/*****************************************************************************/
@ -5089,7 +5073,7 @@ static void Usr_PutCheckboxToSelectUser (Rol_Role_t Role,
CheckboxChecked = true;
else
/* Check if user is in lists of selected users */
CheckboxChecked = Usr_FindEncryptedUsrCodsInListOfSelectedEncryptedUsrCods (EncryptedUsrCod,SelectedUsrs);
CheckboxChecked = Usr_FindEncryptedUsrCodInListOfSelectedEncryptedUsrCods (EncryptedUsrCod,SelectedUsrs);
/***** Check box *****/
Usr_BuildParamName (&ParamName,Usr_ParamUsrCod[Role],SelectedUsrs->ParamSuffix);
@ -5449,8 +5433,8 @@ void Usr_ListAllDataGsts (void)
Usr_DONT_GET_ROLE_IN_CURRENT_CRS))
{
UsrDat.Accepted = false; // Guests have no courses,...
// ...so they have not accepted...
// ...inscription in any course
// ...so they have not accepted...
// ...inscription in any course
NumUsr++;
Usr_WriteRowGstAllData (&UsrDat);
@ -5489,9 +5473,9 @@ void Usr_ListAllDataStds (void)
extern const char *Txt_Date_of_birth;
extern const char *Txt_Group;
extern const char *Txt_RECORD_FIELD_VISIBILITY_RECORD[Rec_NUM_TYPES_VISIBILITY];
unsigned NumColumnsCommonCard;
unsigned NumColumnsCardAndGroups;
unsigned NumColumnsTotal;
unsigned NumColsCommonRecord;
unsigned NumColsRecordAndGroups;
unsigned NumColsTotal;
unsigned NumCol;
unsigned NumUsr;
char *GroupNames;
@ -5544,19 +5528,20 @@ void Usr_ListAllDataStds (void)
Rec_GetListRecordFieldsInCurrentCrs ();
/***** Set number of columns *****/
NumColumnsCommonCard = Usr_NUM_ALL_FIELDS_DATA_STD;
NumColsCommonRecord = Usr_NUM_ALL_FIELDS_DATA_STD;
if (Gbl.Scope.Current == HieLvl_CRS)
{
NumColumnsCardAndGroups = NumColumnsCommonCard + Gbl.Crs.Grps.GrpTypes.NumGrpTypes;
NumColumnsTotal = NumColumnsCardAndGroups + Gbl.Crs.Records.LstFields.Num;
NumColsRecordAndGroups = NumColsCommonRecord + Gbl.Crs.Grps.GrpTypes.NumGrpTypes;
NumColsTotal = NumColsRecordAndGroups + Gbl.Crs.Records.LstFields.Num;
}
else
NumColumnsTotal = NumColumnsCardAndGroups = NumColumnsCommonCard;
NumColsTotal = NumColsRecordAndGroups = NumColsCommonRecord;
/***** Allocate memory for the string with the list of group names where student belongs to *****/
if (Gbl.Scope.Current == HieLvl_CRS)
{
Length = (size_t) (Grp_MAX_BYTES_GROUP_NAME + 2) * (size_t) Gbl.Crs.Grps.GrpTypes.NumGrpsTotal;
Length = (size_t) (Grp_MAX_BYTES_GROUP_NAME + 2) *
(size_t) Gbl.Crs.Grps.GrpTypes.NumGrpsTotal;
if ((GroupNames = malloc (Length + 1)) == NULL)
Err_NotEnoughMemoryExit ();
}
@ -5567,7 +5552,7 @@ void Usr_ListAllDataStds (void)
if (!Gbl.Usrs.ClassPhoto.AllGroups)
{
HTM_TR_Begin (NULL);
HTM_TD_Begin ("colspan=\"%u\" class=\"TIT CM\"",NumColumnsTotal);
HTM_TD_Begin ("colspan=\"%u\" class=\"TIT CM\"",NumColsTotal);
Grp_WriteNamesOfSelectedGrps ();
HTM_TD_End ();
HTM_TR_End ();
@ -5580,7 +5565,7 @@ void Usr_ListAllDataStds (void)
/* 1. Columns for the data */
for (NumCol = (Gbl.Usrs.Listing.WithPhotos ? 0 :
1);
NumCol < NumColumnsCommonCard;
NumCol < NumColsCommonRecord;
NumCol++)
HTM_TH (1,1,"LM LIGHT_BLUE",FieldNames[NumCol]);
@ -5614,7 +5599,7 @@ void Usr_ListAllDataStds (void)
HTM_TR_Begin (NULL);
for (NumCol = 0;
NumCol < NumColumnsCardAndGroups;
NumCol < NumColsRecordAndGroups;
NumCol++)
if (NumCol != 1 || Gbl.Usrs.Listing.WithPhotos) // Skip photo column if I don't want it in listing
{
@ -5786,7 +5771,7 @@ void Usr_ListAllDataTchs (void)
(Gbl.Scope.Current == HieLvl_CTR ? Gbl.Hierarchy.Ctr.CtrCod :
(Gbl.Scope.Current == HieLvl_DEG ? Gbl.Hierarchy.Deg.DegCod :
(Gbl.Scope.Current == HieLvl_CRS ? Gbl.Hierarchy.Crs.CrsCod :
-1L))))),
-1L))))),
1 << Rol_NET |
1 << Rol_TCH);
@ -6007,12 +5992,12 @@ void Usr_ListDataAdms (void)
Mnu_ContextMenuBegin ();
if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)
{
Usr_PutLinkToSeeGuests (); // List guests
Usr_PutLinkToSeeGuests (); // List guests
Dup_PutLinkToListDupUsrs (); // List possible duplicate users
}
Enr_PutLinkToAdminOneUsr (ActReqMdfOneOth); // Admin one user
if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)
Enr_PutLinkToRemOldUsrs (); // Remove old users
Enr_PutLinkToRemOldUsrs (); // Remove old users
Mnu_ContextMenuEnd ();
break;
default:
@ -6170,7 +6155,7 @@ void Usr_SeeGuests (void)
Usr_PutLinkToSeeAdmins (); // List admins
Enr_PutLinkToAdminOneUsr (ActReqMdfOneOth); // Admin one user
if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)
Enr_PutLinkToRemOldUsrs (); // Remove old users
Enr_PutLinkToRemOldUsrs (); // Remove old users
Mnu_ContextMenuEnd ();
/***** Get and update type of list,
@ -6221,7 +6206,7 @@ void Usr_SeeGuests (void)
Lay_WriteHeaderClassPhoto (false,true,
(Gbl.Scope.Current == HieLvl_CTR ||
Gbl.Scope.Current == HieLvl_INS) ? Gbl.Hierarchy.Ins.InsCod :
-1L,
-1L,
-1L,
-1L);
@ -6764,7 +6749,8 @@ static void Usr_ShowOneListUsrsOption (Usr_ListUsrsOption_t ListUsrsAction,
HTM_INPUT_RADIO ("ListUsrsAction",false,
"value=\"%u\"%s",
(unsigned) ListUsrsAction,
ListUsrsAction == Gbl.Usrs.Selected.Option ? " checked=\"checked\"" : "");
ListUsrsAction == Gbl.Usrs.Selected.Option ? " checked=\"checked\"" :
"");
HTM_Txt (Label);
HTM_LABEL_End ();
HTM_LI_End ();
@ -7102,7 +7088,7 @@ void Usr_SeeGstClassPhotoPrn (void)
Lay_WriteHeaderClassPhoto (true,true,
(Gbl.Scope.Current == HieLvl_CTR ||
Gbl.Scope.Current == HieLvl_INS) ? Gbl.Hierarchy.Ins.InsCod :
-1L,
-1L,
-1L,-1L);
HTM_TABLE_BeginWide ();
Usr_DrawClassPhoto (Usr_CLASS_PHOTO_PRN,
@ -7146,12 +7132,12 @@ void Usr_SeeStdClassPhotoPrn (void)
Gbl.Scope.Current == HieLvl_DEG ||
Gbl.Scope.Current == HieLvl_CTR ||
Gbl.Scope.Current == HieLvl_INS) ? Gbl.Hierarchy.Ins.InsCod :
-1L,
-1L,
(Gbl.Scope.Current == HieLvl_CRS ||
Gbl.Scope.Current == HieLvl_DEG) ? Gbl.Hierarchy.Deg.DegCod :
-1L,
-1L,
Gbl.Scope.Current == HieLvl_CRS ? Gbl.Hierarchy.Crs.CrsCod :
-1L);
-1L);
HTM_TABLE_BeginWide ();
Usr_DrawClassPhoto (Usr_CLASS_PHOTO_PRN,
Rol_STD,&Gbl.Usrs.Selected,false);
@ -7207,7 +7193,7 @@ void Usr_SeeTchClassPhotoPrn (void)
(Gbl.Scope.Current == HieLvl_CTR ? Gbl.Hierarchy.Ctr.CtrCod :
(Gbl.Scope.Current == HieLvl_DEG ? Gbl.Hierarchy.Deg.DegCod :
(Gbl.Scope.Current == HieLvl_CRS ? Gbl.Hierarchy.Crs.CrsCod :
-1L))))),
-1L))))),
1 << Rol_NET |
1 << Rol_TCH);
@ -7219,12 +7205,12 @@ void Usr_SeeTchClassPhotoPrn (void)
Gbl.Scope.Current == HieLvl_DEG ||
Gbl.Scope.Current == HieLvl_CTR ||
Gbl.Scope.Current == HieLvl_INS) ? Gbl.Hierarchy.Ins.InsCod :
-1L,
-1L,
(Gbl.Scope.Current == HieLvl_CRS ||
Gbl.Scope.Current == HieLvl_DEG) ? Gbl.Hierarchy.Deg.DegCod :
-1L,
-1L,
Gbl.Scope.Current == HieLvl_CRS ? Gbl.Hierarchy.Crs.CrsCod :
-1L);
-1L);
HTM_TABLE_BeginWide ();
/* List teachers and non-editing teachers */
@ -7370,13 +7356,15 @@ void Usr_PutSelectorNumColsClassPhoto (void)
extern const char *Txt_columns;
unsigned Cols;
/***** Begin selector *****/
/***** Begin label *****/
HTM_LABEL_Begin ("class=\"%s\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
/***** Begin selector *****/
HTM_SELECT_Begin (HTM_SUBMIT_ON_CHANGE,
"name=\"ColsClassPhoto\"");
/***** Put a row in selector for every number from 1 to Usr_CLASS_PHOTO_COLS_MAX *****/
for (Cols = 1;
/***** Put a row in selector for every number of columns *****/
for (Cols = 1;
Cols <= Usr_CLASS_PHOTO_COLS_MAX;
Cols++)
HTM_OPTION (HTM_Type_UNSIGNED,&Cols,
@ -7385,7 +7373,10 @@ void Usr_PutSelectorNumColsClassPhoto (void)
/***** End selector *****/
HTM_SELECT_End ();
HTM_Txt (Txt_columns);
/***** End label *****/
HTM_LABEL_End ();
}
@ -7432,7 +7423,7 @@ void Usr_ShowWarningNoUsersFound (Rol_Role_t Role)
else if (Gbl.Usrs.ClassPhoto.AllGroups && // All groups selected
Role == Rol_TCH && // No teachers found
Gbl.Hierarchy.Level == HieLvl_CRS && // Course selected
Gbl.Hierarchy.Level == HieLvl_CRS && // Course selected
Gbl.Usrs.Me.Role.Logged >= Rol_DEG_ADM) // I am an administrator
/***** Show alert and button to enrol students *****/
Ale_ShowAlertAndButton (ActReqMdfOneTch,NULL,NULL,
@ -7519,7 +7510,19 @@ void Usr_WriteAuthor1Line (long UsrCod,bool Hidden)
void Usr_ShowTableCellWithUsrData (struct UsrData *UsrDat,unsigned NumRows)
{
Act_Action_t NextAction;
static const Act_Action_t NextAction[Rol_NUM_ROLES] =
{
[Rol_UNK ] = ActUnk,
[Rol_GST ] = ActUnk,
[Rol_USR ] = ActUnk,
[Rol_STD ] = ActSeeRecOneStd,
[Rol_NET ] = ActSeeRecOneTch,
[Rol_TCH ] = ActSeeRecOneTch,
[Rol_DEG_ADM] = ActUnk,
[Rol_CTR_ADM] = ActUnk,
[Rol_INS_ADM] = ActUnk,
[Rol_SYS_ADM] = ActUnk,
};
/***** Show user's photo *****/
if (NumRows)
@ -7539,27 +7542,13 @@ void Usr_ShowTableCellWithUsrData (struct UsrData *UsrDat,unsigned NumRows)
HTM_TD_Begin ("class=\"LT LINE_BOTTOM COLOR%u\"",Gbl.RowEvenOdd);
/* Action to go to user's record depending on role in course */
switch (UsrDat->Roles.InCurrentCrs)
{
case Rol_STD:
NextAction = ActSeeRecOneStd;
break;
case Rol_NET:
case Rol_TCH:
NextAction = ActSeeRecOneTch;
break;
default:
NextAction = ActUnk;
break;
}
if (NextAction == ActUnk)
if (NextAction[UsrDat->Roles.InCurrentCrs] == ActUnk)
/* Begin div */
HTM_DIV_Begin ("class=\"LT AUTHOR_TXT\"");
else
{
/* Begin form to go to user's record card */
Frm_BeginForm (NextAction);
Frm_BeginForm (NextAction[UsrDat->Roles.InCurrentCrs]);
Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
HTM_BUTTON_SUBMIT_Begin (UsrDat->FullName,"BT_LINK LT AUTHOR_TXT",NULL);
}
@ -7579,7 +7568,7 @@ void Usr_ShowTableCellWithUsrData (struct UsrData *UsrDat,unsigned NumRows)
HTM_Txt (UsrDat->FrstName);
}
if (NextAction == ActUnk)
if (NextAction[UsrDat->Roles.InCurrentCrs] == ActUnk)
/* End div */
HTM_DIV_End ();
else

View File

@ -368,8 +368,8 @@ void Usr_GetListsSelectedEncryptedUsrsCods (struct SelectedUsrs *SelectedUsrs);
bool Usr_GetListMsgRecipientsWrittenExplicitelyBySender (bool WriteErrorMsgs);
bool Usr_FindEncryptedUsrCodsInListOfSelectedEncryptedUsrCods (const char *EncryptedUsrCodToFind,
struct SelectedUsrs *SelectedUsrs);
bool Usr_FindEncryptedUsrCodInListOfSelectedEncryptedUsrCods (const char *EncryptedUsrCodToFind,
struct SelectedUsrs *SelectedUsrs);
bool Usr_CheckIfThereAreUsrsInListOfSelectedEncryptedUsrCods (struct SelectedUsrs *SelectedUsrs);
unsigned Usr_CountNumUsrsInListOfSelectedEncryptedUsrCods (struct SelectedUsrs *SelectedUsrs);
void Usr_FreeListsSelectedEncryptedUsrsCods (struct SelectedUsrs *SelectedUsrs);

View File

@ -205,6 +205,36 @@ bool Usr_DB_FindStrInUsrsNames (const char *Str)
Str);
}
/*****************************************************************************/
/****** Build query to get the user's codes of all students of a degree ******/
/*****************************************************************************/
void Usr_DB_BuildQueryToGetUnorderedStdsCodesInDeg (long DegCod,char **Query)
{
DB_BuildQuery (Query,
"SELECT DISTINCT "
"usr_data.UsrCod," // row[ 0]
"usr_data.EncryptedUsrCod," // row[ 1]
"usr_data.Password," // row[ 2]
"usr_data.Surname1," // row[ 3]
"usr_data.Surname2," // row[ 4]
"usr_data.FirstName," // row[ 5]
"usr_data.Sex," // row[ 6]
"usr_data.Photo," // row[ 7]
"usr_data.PhotoVisibility," // row[ 8]
"usr_data.CtyCod," // row[ 9]
"usr_data.InsCod" // row[10]
" FROM crs_courses,"
"crs_users,"
"usr_data"
" WHERE crs_courses.DegCod=%ld"
" AND crs_courses.CrsCod=crs_users.CrsCod"
" AND crs_users.Role=%u"
" AND crs_users.UsrCod=usr_data.UsrCod",
DegCod,
(unsigned) Rol_STD);
}
/*****************************************************************************/
/************** Get number of users who have chosen an option ****************/
/*****************************************************************************/
@ -316,7 +346,8 @@ unsigned Usr_DB_GetOldUsrs (MYSQL_RES **mysql_res,time_t SecondsWithoutAccess)
" FROM usr_last)"
") AS candidate_usrs"
" WHERE UsrCod NOT IN"
" (SELECT DISTINCT UsrCod"
" (SELECT DISTINCT "
"UsrCod"
" FROM crs_users)",
(unsigned long long) SecondsWithoutAccess);
}

View File

@ -68,6 +68,7 @@ void Usr_DB_UpdateMyLastWhatToSearch (void);
bool Usr_DB_ChkIfUsrCodExists (long UsrCod);
long Usr_DB_GetUsrCodFromEncryptedUsrCod (const char EncryptedUsrCod[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1]);
bool Usr_DB_FindStrInUsrsNames (const char *Str);
void Usr_DB_BuildQueryToGetUnorderedStdsCodesInDeg (long DegCod,char **Query);
unsigned Usr_DB_GetNumUsrsWhoChoseAnOption (const char *SubQuery);
unsigned Usr_DB_GetOldUsrs (MYSQL_RES **mysql_res,time_t SecondsWithoutAccess);