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).

This commit is contained in:
acanas 2021-03-04 13:43:06 +01:00
parent 07181b2e4d
commit c36eb26162
7 changed files with 100 additions and 41 deletions

View File

@ -136,7 +136,8 @@ void Ctr_SeeCtrWithPendingDegs (void)
" AND degrees.CtrCod=ctr_admin.CtrCod" " AND degrees.CtrCod=ctr_admin.CtrCod"
" AND ctr_admin.UsrCod=%ld" " AND ctr_admin.UsrCod=%ld"
" AND degrees.CtrCod=centres.CtrCod" " 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, (unsigned) Deg_STATUS_BIT_PENDING,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod);
break; break;
@ -147,7 +148,8 @@ void Ctr_SeeCtrWithPendingDegs (void)
" FROM degrees,centres" " FROM degrees,centres"
" WHERE (degrees.Status & %u)<>0" " WHERE (degrees.Status & %u)<>0"
" AND degrees.CtrCod=centres.CtrCod" " 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); (unsigned) Deg_STATUS_BIT_PENDING);
break; break;
default: // Forbidden for other users default: // Forbidden for other users

View File

@ -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: 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: 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 CSS_FILE "swad20.33.9.css"
#define JS_FILE "swad20.6.2.js" #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.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.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) Version 20.41.3: Mar 03, 2021 Code refactoring in timeline publications. (305580 lines)

View File

@ -135,7 +135,8 @@ void Deg_SeeDegWithPendingCrss (void)
" AND admin.Cod=courses.DegCod" " AND admin.Cod=courses.DegCod"
" AND (courses.Status & %u)<>0" " AND (courses.Status & %u)<>0"
" AND courses.DegCod=degrees.DegCod" " 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, Gbl.Usrs.Me.UsrDat.UsrCod,
Sco_GetDBStrFromScope (Hie_Lvl_DEG), Sco_GetDBStrFromScope (Hie_Lvl_DEG),
(unsigned) Crs_STATUS_BIT_PENDING); (unsigned) Crs_STATUS_BIT_PENDING);
@ -147,7 +148,8 @@ void Deg_SeeDegWithPendingCrss (void)
" FROM courses,degrees" " FROM courses,degrees"
" WHERE (courses.Status & %u)<>0" " WHERE (courses.Status & %u)<>0"
" AND courses.DegCod=degrees.DegCod" " 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); (unsigned) Crs_STATUS_BIT_PENDING);
break; break;
default: // Forbidden for other users default: // Forbidden for other users

View File

@ -621,20 +621,30 @@ static unsigned For_NumPstsInThrWithPstCod (long PstCod,long *ThrCod)
MYSQL_ROW row; MYSQL_ROW row;
unsigned NumPsts; unsigned NumPsts;
/***** Get number of posts in the thread that holds a post from database *****/ /***** Initialize default values *****/
DB_QuerySELECT (&mysql_res,"can not get number of posts" *ThrCod = -1L;
" in a thread of a forum", NumPsts = 0;
"SELECT COUNT(PstCod),ThrCod FROM forum_post"
" WHERE ThrCod IN"
" (SELECT ThrCod FROM forum_post"
" WHERE PstCod=%ld) GROUP BY ThrCod;",
PstCod);
row = mysql_fetch_row (mysql_res); /***** Trivial check: PstCod should be > 0 *****/
if (sscanf (row[0],"%u",&NumPsts) != 1) if (PstCod <= 0)
Lay_ShowErrorAndExit ("Error when getting number of posts in a thread of a forum."); return NumPsts;
if (sscanf (row[1],"%ld",ThrCod) != 1)
Lay_ShowErrorAndExit ("Error when getting number of posts in a thread of a forum."); /***** 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); DB_FreeMySQLResult (&mysql_res);
return NumPsts; return NumPsts;

View File

@ -139,7 +139,8 @@ void Ins_SeeInsWithPendingCtrs (void)
" WHERE (centres.Status & %u)<>0" " WHERE (centres.Status & %u)<>0"
" AND centres.InsCod=ins_admin.InsCod AND ins_admin.UsrCod=%ld" " AND centres.InsCod=ins_admin.InsCod AND ins_admin.UsrCod=%ld"
" AND centres.InsCod=institutions.InsCod" " 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, (unsigned) Ctr_STATUS_BIT_PENDING,
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod);
break; break;
@ -151,7 +152,8 @@ void Ins_SeeInsWithPendingCtrs (void)
" FROM centres,institutions" " FROM centres,institutions"
" WHERE (centres.Status & %u)<>0" " WHERE (centres.Status & %u)<>0"
" AND centres.InsCod=institutions.InsCod" " 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); (unsigned) Ctr_STATUS_BIT_PENDING);
break; break;
default: // Forbidden for other users default: // Forbidden for other users

View File

@ -783,7 +783,8 @@ static void Rep_WriteSectionHitsPerAction (struct Rep_Report *Report)
" FROM log" " FROM log"
" WHERE ClickTime>=FROM_UNIXTIME(%ld)" " WHERE ClickTime>=FROM_UNIXTIME(%ld)"
" AND UsrCod=%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, (long) Report->UsrFigures.FirstClickTimeUTC,
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Rep_MAX_ACTIONS); Rep_MAX_ACTIONS);
@ -1240,7 +1241,8 @@ static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role,
"COUNT(*) FROM log" "COUNT(*) FROM log"
" WHERE ClickTime>=FROM_UNIXTIME(%ld)" " WHERE ClickTime>=FROM_UNIXTIME(%ld)"
" AND UsrCod=%ld%s%s" " AND UsrCod=%ld%s%s"
" GROUP BY Year DESC", " GROUP BY Year"
" ORDER BY Year DESC",
(long) Report->UsrFigures.FirstClickTimeUTC, (long) Report->UsrFigures.FirstClickTimeUTC,
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
SubQueryCrs, SubQueryCrs,

View File

@ -1260,83 +1260,116 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse)
switch (Stats.ClicksGroupedBy) switch (Stats.ClicksGroupedBy)
{ {
case Sta_CLICKS_CRS_DETAILED_LIST: 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; break;
case Sta_CLICKS_CRS_PER_USR: 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); Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS);
break; break;
case Sta_CLICKS_CRS_PER_DAY: case Sta_CLICKS_CRS_PER_DAY:
case Sta_CLICKS_GBL_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; break;
case Sta_CLICKS_CRS_PER_DAY_AND_HOUR: case Sta_CLICKS_CRS_PER_DAY_AND_HOUR:
case Sta_CLICKS_GBL_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; break;
case Sta_CLICKS_CRS_PER_WEEK: case Sta_CLICKS_CRS_PER_WEEK:
case Sta_CLICKS_GBL_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; break;
case Sta_CLICKS_CRS_PER_MONTH: case Sta_CLICKS_CRS_PER_MONTH:
case Sta_CLICKS_GBL_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; break;
case Sta_CLICKS_CRS_PER_YEAR: case Sta_CLICKS_CRS_PER_YEAR:
case Sta_CLICKS_GBL_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; break;
case Sta_CLICKS_CRS_PER_HOUR: case Sta_CLICKS_CRS_PER_HOUR:
case Sta_CLICKS_GBL_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; break;
case Sta_CLICKS_CRS_PER_MINUTE: case Sta_CLICKS_CRS_PER_MINUTE:
case Sta_CLICKS_GBL_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; break;
case Sta_CLICKS_CRS_PER_ACTION: case Sta_CLICKS_CRS_PER_ACTION:
case Sta_CLICKS_GBL_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); Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS);
break; break;
case Sta_CLICKS_GBL_PER_PLUGIN: 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); Sta_MAX_BYTES_QUERY_ACCESS);
break; break;
case Sta_CLICKS_GBL_PER_API_FUNCTION: 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); Sta_MAX_BYTES_QUERY_ACCESS);
break; break;
case Sta_CLICKS_GBL_PER_BANNER: 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); Sta_MAX_BYTES_QUERY_ACCESS);
break; break;
case Sta_CLICKS_GBL_PER_COUNTRY: 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); Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS);
break; break;
case Sta_CLICKS_GBL_PER_INSTITUTION: 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); Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS);
break; break;
case Sta_CLICKS_GBL_PER_CENTRE: 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); Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS);
break; break;
case Sta_CLICKS_GBL_PER_DEGREE: 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); Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS);
break; break;
case Sta_CLICKS_GBL_PER_COURSE: 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); Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS);
break; break;
} }
/***** Write query for debug *****/ /***** Write query for debug *****/
/* /*
if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM) if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)
Ale_ShowFixedAlert (Ale_INFO,Query); Ale_ShowAlert (Ale_INFO,Query);
*/ */
/***** Make the query *****/ /***** Make the query *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get clicks", NumRows = DB_QuerySELECT (&mysql_res,"can not get clicks",
"%s", "%s",