diff --git a/swad_centre.c b/swad_centre.c index c81ac3821..1a15d68f8 100644 --- a/swad_centre.c +++ b/swad_centre.c @@ -136,7 +136,8 @@ void Ctr_SeeCtrWithPendingDegs (void) " AND degrees.CtrCod=ctr_admin.CtrCod" " AND ctr_admin.UsrCod=%ld" " AND degrees.CtrCod=centres.CtrCod" - " GROUP BY degrees.CtrCod ORDER BY centres.ShortName", + " GROUP BY degrees.CtrCod" + " ORDER BY centres.ShortName", (unsigned) Deg_STATUS_BIT_PENDING, Gbl.Usrs.Me.UsrDat.UsrCod); break; @@ -147,7 +148,8 @@ void Ctr_SeeCtrWithPendingDegs (void) " FROM degrees,centres" " WHERE (degrees.Status & %u)<>0" " AND degrees.CtrCod=centres.CtrCod" - " GROUP BY degrees.CtrCod ORDER BY centres.ShortName", + " GROUP BY degrees.CtrCod" + " ORDER BY centres.ShortName", (unsigned) Deg_STATUS_BIT_PENDING); break; default: // Forbidden for other users diff --git a/swad_changelog.h b/swad_changelog.h index 0250324e5..ed548388a 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -597,11 +597,19 @@ TODO: DNI de un estudiante sale err TODO: BUG: Cuando un tipo de grupo sólo tiene un grupo, inscribirse es voluntario, el estudiante sólo puede pertenecer a un grupo, y se inscribe en él, debería poder desapuntarse. Ahora no puede. TODO: Salvador Romero Cortés: @acanas opción para editar posts + +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.41.5 (2021-03-03)" +#define Log_PLATFORM_VERSION "SWAD 20.42 (2021-03-04)" #define CSS_FILE "swad20.33.9.css" #define JS_FILE "swad20.6.2.js" /* + Version 20.42: Mar 04, 2021 Fixed bugs in GROUP BY, caused by upgrading MySQL 5 (order by default) to MySQL 8 (no order by default). (305624 lines) + 3 change necessary in database: +DROP TABLE IF EXISTS crs_usr_backup_delete_me; +DROP TABLE IF EXISTS crs_usr_old_backup_delete_me; +DROP TABLE IF EXISTS log_full; + Version 20.41.5: Mar 03, 2021 Code refactoring in timeline. (305569 lines) Version 20.41.4: Mar 03, 2021 Code refactoring in timeline publications. (305577 lines) Version 20.41.3: Mar 03, 2021 Code refactoring in timeline publications. (305580 lines) diff --git a/swad_degree.c b/swad_degree.c index cc5fe3fea..0eb402bb9 100644 --- a/swad_degree.c +++ b/swad_degree.c @@ -135,7 +135,8 @@ void Deg_SeeDegWithPendingCrss (void) " AND admin.Cod=courses.DegCod" " AND (courses.Status & %u)<>0" " AND courses.DegCod=degrees.DegCod" - " GROUP BY courses.DegCod ORDER BY degrees.ShortName", + " GROUP BY courses.DegCod" + " ORDER BY degrees.ShortName", Gbl.Usrs.Me.UsrDat.UsrCod, Sco_GetDBStrFromScope (Hie_Lvl_DEG), (unsigned) Crs_STATUS_BIT_PENDING); @@ -147,7 +148,8 @@ void Deg_SeeDegWithPendingCrss (void) " FROM courses,degrees" " WHERE (courses.Status & %u)<>0" " AND courses.DegCod=degrees.DegCod" - " GROUP BY courses.DegCod ORDER BY degrees.ShortName", + " GROUP BY courses.DegCod" + " ORDER BY degrees.ShortName", (unsigned) Crs_STATUS_BIT_PENDING); break; default: // Forbidden for other users diff --git a/swad_forum.c b/swad_forum.c index f15effbe3..528076cb7 100644 --- a/swad_forum.c +++ b/swad_forum.c @@ -621,20 +621,30 @@ static unsigned For_NumPstsInThrWithPstCod (long PstCod,long *ThrCod) MYSQL_ROW row; unsigned NumPsts; - /***** Get number of posts in the thread that holds a post from database *****/ - DB_QuerySELECT (&mysql_res,"can not get number of posts" - " in a thread of a forum", - "SELECT COUNT(PstCod),ThrCod FROM forum_post" - " WHERE ThrCod IN" - " (SELECT ThrCod FROM forum_post" - " WHERE PstCod=%ld) GROUP BY ThrCod;", - PstCod); + /***** Initialize default values *****/ + *ThrCod = -1L; + NumPsts = 0; - row = mysql_fetch_row (mysql_res); - if (sscanf (row[0],"%u",&NumPsts) != 1) - Lay_ShowErrorAndExit ("Error when getting number of posts in a thread of a forum."); - if (sscanf (row[1],"%ld",ThrCod) != 1) - Lay_ShowErrorAndExit ("Error when getting number of posts in a thread of a forum."); + /***** Trivial check: PstCod should be > 0 *****/ + if (PstCod <= 0) + return NumPsts; + + /***** Get number of posts in the thread that holds a post from database *****/ + if (DB_QuerySELECT (&mysql_res,"can not get number of posts in a thread", + "SELECT COUNT(PstCod)," // row[0] + "ThrCod" // row[1] + " FROM forum_post" + " WHERE ThrCod IN" + " (SELECT ThrCod FROM forum_post WHERE PstCod=%ld)" + " GROUP BY ThrCod;", + PstCod) == 1) // Result should have one row + { + row = mysql_fetch_row (mysql_res); + if (sscanf (row[0],"%u",&NumPsts) != 1) + Lay_ShowErrorAndExit ("Error when getting number of posts in a thread."); + if (sscanf (row[1],"%ld",ThrCod) != 1) + Lay_ShowErrorAndExit ("Error when getting number of posts in a thread."); + } DB_FreeMySQLResult (&mysql_res); return NumPsts; diff --git a/swad_institution.c b/swad_institution.c index d0e5e08a0..4acaa9c8d 100644 --- a/swad_institution.c +++ b/swad_institution.c @@ -139,7 +139,8 @@ void Ins_SeeInsWithPendingCtrs (void) " WHERE (centres.Status & %u)<>0" " AND centres.InsCod=ins_admin.InsCod AND ins_admin.UsrCod=%ld" " AND centres.InsCod=institutions.InsCod" - " GROUP BY centres.InsCod ORDER BY institutions.ShortName", + " GROUP BY centres.InsCod" + " ORDER BY institutions.ShortName", (unsigned) Ctr_STATUS_BIT_PENDING, Gbl.Usrs.Me.UsrDat.UsrCod); break; @@ -151,7 +152,8 @@ void Ins_SeeInsWithPendingCtrs (void) " FROM centres,institutions" " WHERE (centres.Status & %u)<>0" " AND centres.InsCod=institutions.InsCod" - " GROUP BY centres.InsCod ORDER BY institutions.ShortName", + " GROUP BY centres.InsCod" + " ORDER BY institutions.ShortName", (unsigned) Ctr_STATUS_BIT_PENDING); break; default: // Forbidden for other users diff --git a/swad_report.c b/swad_report.c index 99f6a7bcb..100f5b952 100644 --- a/swad_report.c +++ b/swad_report.c @@ -783,7 +783,8 @@ static void Rep_WriteSectionHitsPerAction (struct Rep_Report *Report) " FROM log" " WHERE ClickTime>=FROM_UNIXTIME(%ld)" " AND UsrCod=%ld" - " GROUP BY ActCod ORDER BY N DESC LIMIT %u", + " GROUP BY ActCod" + " ORDER BY N DESC LIMIT %u", (long) Report->UsrFigures.FirstClickTimeUTC, Gbl.Usrs.Me.UsrDat.UsrCod, Rep_MAX_ACTIONS); @@ -1240,7 +1241,8 @@ static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role, "COUNT(*) FROM log" " WHERE ClickTime>=FROM_UNIXTIME(%ld)" " AND UsrCod=%ld%s%s" - " GROUP BY Year DESC", + " GROUP BY Year" + " ORDER BY Year DESC", (long) Report->UsrFigures.FirstClickTimeUTC, Gbl.Usrs.Me.UsrDat.UsrCod, SubQueryCrs, diff --git a/swad_statistic.c b/swad_statistic.c index d0c879c7a..b48632970 100644 --- a/swad_statistic.c +++ b/swad_statistic.c @@ -1260,83 +1260,116 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse) switch (Stats.ClicksGroupedBy) { case Sta_CLICKS_CRS_DETAILED_LIST: - Str_Concat (Query," ORDER BY F",Sta_MAX_BYTES_QUERY_ACCESS); + Str_Concat (Query," ORDER BY F", + Sta_MAX_BYTES_QUERY_ACCESS); break; case Sta_CLICKS_CRS_PER_USR: - sprintf (QueryAux," GROUP BY %s.UsrCod ORDER BY Num DESC",LogTable); + sprintf (QueryAux," GROUP BY %s.UsrCod" + " ORDER BY Num DESC", + LogTable); Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS); break; case Sta_CLICKS_CRS_PER_DAY: case Sta_CLICKS_GBL_PER_DAY: - Str_Concat (Query," GROUP BY Day DESC",Sta_MAX_BYTES_QUERY_ACCESS); + Str_Concat (Query," GROUP BY Day" + " ORDER BY Day DESC", + Sta_MAX_BYTES_QUERY_ACCESS); break; case Sta_CLICKS_CRS_PER_DAY_AND_HOUR: case Sta_CLICKS_GBL_PER_DAY_AND_HOUR: - Str_Concat (Query," GROUP BY Day DESC,Hour",Sta_MAX_BYTES_QUERY_ACCESS); + Str_Concat (Query," GROUP BY Day,Hour" + " ORDER BY Day DESC,Hour", + Sta_MAX_BYTES_QUERY_ACCESS); break; case Sta_CLICKS_CRS_PER_WEEK: case Sta_CLICKS_GBL_PER_WEEK: - Str_Concat (Query," GROUP BY Week DESC",Sta_MAX_BYTES_QUERY_ACCESS); + Str_Concat (Query," GROUP BY Week" + " ORDER BY Week DESC", + Sta_MAX_BYTES_QUERY_ACCESS); break; case Sta_CLICKS_CRS_PER_MONTH: case Sta_CLICKS_GBL_PER_MONTH: - Str_Concat (Query," GROUP BY Month DESC",Sta_MAX_BYTES_QUERY_ACCESS); + Str_Concat (Query," GROUP BY Month" + " ORDER BY Month DESC", + Sta_MAX_BYTES_QUERY_ACCESS); break; case Sta_CLICKS_CRS_PER_YEAR: case Sta_CLICKS_GBL_PER_YEAR: - Str_Concat (Query," GROUP BY Year DESC",Sta_MAX_BYTES_QUERY_ACCESS); + Str_Concat (Query," GROUP BY Year" + " ORDER BY Year DESC", + Sta_MAX_BYTES_QUERY_ACCESS); break; case Sta_CLICKS_CRS_PER_HOUR: case Sta_CLICKS_GBL_PER_HOUR: - Str_Concat (Query," GROUP BY Hour",Sta_MAX_BYTES_QUERY_ACCESS); + Str_Concat (Query," GROUP BY Hour" + " ORDER BY Hour", + Sta_MAX_BYTES_QUERY_ACCESS); break; case Sta_CLICKS_CRS_PER_MINUTE: case Sta_CLICKS_GBL_PER_MINUTE: - Str_Concat (Query," GROUP BY Minute",Sta_MAX_BYTES_QUERY_ACCESS); + Str_Concat (Query," GROUP BY Minute" + " ORDER BY Minute", + Sta_MAX_BYTES_QUERY_ACCESS); break; case Sta_CLICKS_CRS_PER_ACTION: case Sta_CLICKS_GBL_PER_ACTION: - sprintf (QueryAux," GROUP BY %s.ActCod ORDER BY Num DESC",LogTable); + sprintf (QueryAux," GROUP BY %s.ActCod" + " ORDER BY Num DESC", + LogTable); Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS); break; case Sta_CLICKS_GBL_PER_PLUGIN: - Str_Concat (Query," GROUP BY log_ws.PlgCod ORDER BY Num DESC", + Str_Concat (Query," GROUP BY log_ws.PlgCod" + " ORDER BY Num DESC", Sta_MAX_BYTES_QUERY_ACCESS); break; case Sta_CLICKS_GBL_PER_API_FUNCTION: - Str_Concat (Query," GROUP BY log_ws.FunCod ORDER BY Num DESC", + Str_Concat (Query," GROUP BY log_ws.FunCod" + " ORDER BY Num DESC", Sta_MAX_BYTES_QUERY_ACCESS); break; case Sta_CLICKS_GBL_PER_BANNER: - Str_Concat (Query," GROUP BY log_banners.BanCod ORDER BY Num DESC", + Str_Concat (Query," GROUP BY log_banners.BanCod" + " ORDER BY Num DESC", Sta_MAX_BYTES_QUERY_ACCESS); break; case Sta_CLICKS_GBL_PER_COUNTRY: - sprintf (QueryAux," GROUP BY %s.CtyCod ORDER BY Num DESC",LogTable); + sprintf (QueryAux," GROUP BY %s.CtyCod" + " ORDER BY Num DESC", + LogTable); Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS); break; case Sta_CLICKS_GBL_PER_INSTITUTION: - sprintf (QueryAux," GROUP BY %s.InsCod ORDER BY Num DESC",LogTable); + sprintf (QueryAux," GROUP BY %s.InsCod" + " ORDER BY Num DESC", + LogTable); Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS); break; case Sta_CLICKS_GBL_PER_CENTRE: - sprintf (QueryAux," GROUP BY %s.CtrCod ORDER BY Num DESC",LogTable); + sprintf (QueryAux," GROUP BY %s.CtrCod" + " ORDER BY Num DESC", + LogTable); Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS); break; case Sta_CLICKS_GBL_PER_DEGREE: - sprintf (QueryAux," GROUP BY %s.DegCod ORDER BY Num DESC",LogTable); + sprintf (QueryAux," GROUP BY %s.DegCod" + " ORDER BY Num DESC", + LogTable); Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS); break; case Sta_CLICKS_GBL_PER_COURSE: - sprintf (QueryAux," GROUP BY %s.CrsCod ORDER BY Num DESC",LogTable); + sprintf (QueryAux," GROUP BY %s.CrsCod" + " ORDER BY Num DESC", + LogTable); Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS); break; } /***** Write query for debug *****/ /* if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM) - Ale_ShowFixedAlert (Ale_INFO,Query); + Ale_ShowAlert (Ale_INFO,Query); */ + /***** Make the query *****/ NumRows = DB_QuerySELECT (&mysql_res,"can not get clicks", "%s",