mirror of
https://github.com/acanas/swad-core.git
synced 2024-06-15 13:14:04 +02:00
Version 20.60: Apr 07, 2021 Optimizations in database selects.
This commit is contained in:
parent
0f34fec7bd
commit
1b7350757a
|
@ -686,14 +686,14 @@ static bool API_GetSomeUsrDataFromUsrCod (struct UsrData *UsrDat,long CrsCod)
|
||||||
UsrDat->Roles.InCurrentCrs.Valid = true;
|
UsrDat->Roles.InCurrentCrs.Valid = true;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UsrDat->Roles.InCurrentCrs.Role = Rol_UNK;
|
UsrDat->Roles.InCurrentCrs.Role = Rol_UNK;
|
||||||
UsrDat->Roles.InCurrentCrs.Valid = false;
|
UsrDat->Roles.InCurrentCrs.Valid = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
// MAX(Role) == NULL if user does not belong to any course
|
// MAX(Role) == NULL if user does not belong to any course
|
||||||
{
|
{
|
||||||
UsrDat->Roles.InCurrentCrs.Role = Rol_UNK;
|
UsrDat->Roles.InCurrentCrs.Role = Rol_UNK;
|
||||||
UsrDat->Roles.InCurrentCrs.Valid = true;
|
UsrDat->Roles.InCurrentCrs.Valid = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3672,7 +3672,7 @@ int swad__sendMessage (struct soap *soap,
|
||||||
{
|
{
|
||||||
/***** Check if the original message was really received by me *****/
|
/***** Check if the original message was really received by me *****/
|
||||||
if (DB_QuerySELECTUnsigned ("can not check original message",
|
if (DB_QuerySELECTUnsigned ("can not check original message",
|
||||||
"SELECT SUM(N)" // row[0]
|
"SELECT SUM(N)"
|
||||||
" FROM (SELECT COUNT(*) AS N"
|
" FROM (SELECT COUNT(*) AS N"
|
||||||
" FROM msg_rcv"
|
" FROM msg_rcv"
|
||||||
" WHERE UsrCod=%ld"
|
" WHERE UsrCod=%ld"
|
||||||
|
|
|
@ -600,13 +600,14 @@ TODO: Salvador Romero Cort
|
||||||
|
|
||||||
TODO: FIX BUG, URGENT! En las fechas como parámetro Dat_WriteParamsIniEndDates(), por ejemplo al cambiar el color de la gráfica de accesos por día y hora, no se respeta la zona horaria.
|
TODO: FIX BUG, URGENT! En las fechas como parámetro Dat_WriteParamsIniEndDates(), por ejemplo al cambiar el color de la gráfica de accesos por día y hora, no se respeta la zona horaria.
|
||||||
*/
|
*/
|
||||||
#define Log_PLATFORM_VERSION "SWAD 20.59 (2021-04-06)"
|
#define Log_PLATFORM_VERSION "SWAD 20.60 (2021-04-07)"
|
||||||
#define CSS_FILE "swad20.45.css"
|
#define CSS_FILE "swad20.45.css"
|
||||||
#define JS_FILE "swad20.6.2.js"
|
#define JS_FILE "swad20.6.2.js"
|
||||||
/*
|
/*
|
||||||
TODO: Rename CENTRE to CENTER in help wiki.
|
TODO: Rename CENTRE to CENTER in help wiki.
|
||||||
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
||||||
|
|
||||||
|
Version 20.60: Apr 07, 2021 Optimizations in database selects. (308790 lines)
|
||||||
Version 20.59: Apr 06, 2021 Optimizations in database selects. (308903 lines)
|
Version 20.59: Apr 06, 2021 Optimizations in database selects. (308903 lines)
|
||||||
Version 20.58: Apr 06, 2021 Optimizations in database selects. (308989 lines)
|
Version 20.58: Apr 06, 2021 Optimizations in database selects. (308989 lines)
|
||||||
Version 20.57: Apr 05, 2021 Optimizations in database selects. (309041 lines)
|
Version 20.57: Apr 05, 2021 Optimizations in database selects. (309041 lines)
|
||||||
|
|
72
swad_exam.c
72
swad_exam.c
|
@ -1769,8 +1769,6 @@ unsigned Exa_GetParamQstInd (void)
|
||||||
|
|
||||||
long Exa_GetQstCodFromQstInd (long ExaCod,unsigned QstInd)
|
long Exa_GetQstCodFromQstInd (long ExaCod,unsigned QstInd)
|
||||||
{
|
{
|
||||||
MYSQL_RES *mysql_res;
|
|
||||||
MYSQL_ROW row;
|
|
||||||
long QstCod;
|
long QstCod;
|
||||||
|
|
||||||
/***** Get question code of the question to be moved up *****/
|
/***** Get question code of the question to be moved up *****/
|
||||||
|
@ -1784,14 +1782,6 @@ long Exa_GetQstCodFromQstInd (long ExaCod,unsigned QstInd)
|
||||||
if (QstCod <= 0)
|
if (QstCod <= 0)
|
||||||
Lay_ShowErrorAndExit ("Error: wrong question index.");
|
Lay_ShowErrorAndExit ("Error: wrong question index.");
|
||||||
|
|
||||||
/***** Get question code (row[0]) *****/
|
|
||||||
row = mysql_fetch_row (mysql_res);
|
|
||||||
if ((QstCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
|
|
||||||
Lay_ShowErrorAndExit ("Error: wrong question code.");
|
|
||||||
|
|
||||||
/***** Free structure that stores the query result *****/
|
|
||||||
DB_FreeMySQLResult (&mysql_res);
|
|
||||||
|
|
||||||
return QstCod;
|
return QstCod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1803,67 +1793,39 @@ long Exa_GetQstCodFromQstInd (long ExaCod,unsigned QstInd)
|
||||||
|
|
||||||
unsigned Exa_GetPrevQuestionIndexInExam (long ExaCod,unsigned QstInd)
|
unsigned Exa_GetPrevQuestionIndexInExam (long ExaCod,unsigned QstInd)
|
||||||
{
|
{
|
||||||
MYSQL_RES *mysql_res;
|
|
||||||
MYSQL_ROW row;
|
|
||||||
unsigned PrevQstInd = 0;
|
|
||||||
|
|
||||||
/***** Get previous question index in an exam from database *****/
|
/***** Get previous question index in an exam from database *****/
|
||||||
// Although indexes are always continuous...
|
// Although indexes are always continuous...
|
||||||
// ...this implementation works even with non continuous indexes
|
// ...this implementation works even with non continuous indexes
|
||||||
if (!DB_QuerySELECT (&mysql_res,"can not get previous question index",
|
return DB_QuerySELECTUnsigned ("can not get previous question index",
|
||||||
"SELECT MAX(QstInd)" // row[0]
|
"SELECT MAX(QstInd)" // row[0]
|
||||||
" FROM exa_set_questions"
|
" FROM exa_set_questions"
|
||||||
" WHERE ExaCod=%ld"
|
" WHERE ExaCod=%ld"
|
||||||
" AND QstInd<%u",
|
" AND QstInd<%u",
|
||||||
ExaCod,
|
ExaCod,
|
||||||
QstInd))
|
QstInd);
|
||||||
Lay_ShowErrorAndExit ("Error: previous question index not found.");
|
|
||||||
|
|
||||||
/***** Get previous question index (row[0]) *****/
|
|
||||||
row = mysql_fetch_row (mysql_res);
|
|
||||||
if (row)
|
|
||||||
if (row[0])
|
|
||||||
if (sscanf (row[0],"%u",&PrevQstInd) != 1)
|
|
||||||
Lay_ShowErrorAndExit ("Error when getting previous question index.");
|
|
||||||
|
|
||||||
/***** Free structure that stores the query result *****/
|
|
||||||
DB_FreeMySQLResult (&mysql_res);
|
|
||||||
|
|
||||||
return PrevQstInd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/************* Get next question index to a given index in an exam ************/
|
/************* Get next question index to a given index in an exam ************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
// Input question index can be 0, 1, 2, 3... n-1
|
// Input question index can be 0, 1, 2, 3... n-1
|
||||||
// Return question index will be 1, 2, 3... n if next question exists, or 0 if no next question
|
// Return question index will be 1, 2, 3... n if next question exists, or big number if no next question
|
||||||
|
|
||||||
unsigned Exa_GetNextQuestionIndexInExam (long ExaCod,unsigned QstInd)
|
unsigned Exa_GetNextQuestionIndexInExam (long ExaCod,unsigned QstInd)
|
||||||
{
|
{
|
||||||
MYSQL_RES *mysql_res;
|
unsigned NextQstInd;
|
||||||
MYSQL_ROW row;
|
|
||||||
unsigned NextQstInd = ExaSes_AFTER_LAST_QUESTION; // End of questions has been reached
|
|
||||||
|
|
||||||
/***** Get next question index in an exam from database *****/
|
/***** Get next question index in an exam from database *****/
|
||||||
// Although indexes are always continuous...
|
// Although indexes are always continuous...
|
||||||
// ...this implementation works even with non continuous indexes
|
// ...this implementation works even with non continuous indexes
|
||||||
if (!DB_QuerySELECT (&mysql_res,"can not get next question index",
|
NextQstInd = DB_QuerySELECTUnsigned ("can not get next question index",
|
||||||
"SELECT MIN(QstInd)" // row[0]
|
"SELECT MIN(QstInd)"
|
||||||
" FROM exa_set_questions"
|
" FROM exa_set_questions"
|
||||||
" WHERE ExaCod=%ld"
|
" WHERE ExaCod=%ld"
|
||||||
" AND QstInd>%u",
|
" AND QstInd>%u",
|
||||||
ExaCod,QstInd))
|
ExaCod,QstInd);
|
||||||
Lay_ShowErrorAndExit ("Error: next question index not found.");
|
if (NextQstInd == 0)
|
||||||
|
NextQstInd = ExaSes_AFTER_LAST_QUESTION; // End of questions has been reached
|
||||||
/***** Get next question index (row[0]) *****/
|
|
||||||
row = mysql_fetch_row (mysql_res);
|
|
||||||
if (row)
|
|
||||||
if (row[0])
|
|
||||||
if (sscanf (row[0],"%u",&NextQstInd) != 1)
|
|
||||||
Lay_ShowErrorAndExit ("Error when getting next question index.");
|
|
||||||
|
|
||||||
/***** Free structure that stores the query result *****/
|
|
||||||
DB_FreeMySQLResult (&mysql_res);
|
|
||||||
|
|
||||||
return NextQstInd;
|
return NextQstInd;
|
||||||
}
|
}
|
||||||
|
|
|
@ -822,25 +822,12 @@ static long ExaSet_GetSetCodFromSetInd (long ExaCod,unsigned SetInd)
|
||||||
|
|
||||||
static unsigned ExaSet_GetMaxSetIndexInExam (long ExaCod)
|
static unsigned ExaSet_GetMaxSetIndexInExam (long ExaCod)
|
||||||
{
|
{
|
||||||
MYSQL_RES *mysql_res;
|
|
||||||
MYSQL_ROW row;
|
|
||||||
unsigned SetInd = 0;
|
|
||||||
|
|
||||||
/***** Get maximum set index in an exam from database *****/
|
/***** Get maximum set index in an exam from database *****/
|
||||||
DB_QuerySELECT (&mysql_res,"can not get max set index",
|
return DB_QuerySELECTUnsigned ("can not get max set index",
|
||||||
"SELECT MAX(SetInd)" // row[0]
|
"SELECT MAX(SetInd)"
|
||||||
" FROM exa_sets"
|
" FROM exa_sets"
|
||||||
" WHERE ExaCod=%ld",
|
" WHERE ExaCod=%ld",
|
||||||
ExaCod);
|
ExaCod);
|
||||||
row = mysql_fetch_row (mysql_res);
|
|
||||||
if (row[0]) // There are sets
|
|
||||||
if (sscanf (row[0],"%u",&SetInd) != 1)
|
|
||||||
Lay_ShowErrorAndExit ("Error when getting max set index.");
|
|
||||||
|
|
||||||
/***** Free structure that stores the query result *****/
|
|
||||||
DB_FreeMySQLResult (&mysql_res);
|
|
||||||
|
|
||||||
return SetInd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -851,66 +838,40 @@ static unsigned ExaSet_GetMaxSetIndexInExam (long ExaCod)
|
||||||
|
|
||||||
static unsigned ExaSet_GetPrevSetIndexInExam (long ExaCod,unsigned SetInd)
|
static unsigned ExaSet_GetPrevSetIndexInExam (long ExaCod,unsigned SetInd)
|
||||||
{
|
{
|
||||||
MYSQL_RES *mysql_res;
|
|
||||||
MYSQL_ROW row;
|
|
||||||
unsigned PrevSetInd = 0;
|
|
||||||
|
|
||||||
/***** Get previous set index in an exam from database *****/
|
/***** Get previous set index in an exam from database *****/
|
||||||
// Although indexes are always continuous...
|
// Although indexes are always continuous...
|
||||||
// ...this implementation works even with non continuous indexes
|
// ...this implementation works even with non continuous indexes
|
||||||
if (!DB_QuerySELECT (&mysql_res,"can not get previous set index",
|
return DB_QuerySELECTUnsigned ("can not get previous set index",
|
||||||
"SELECT MAX(SetInd)" // row[0]
|
"SELECT MAX(SetInd)"
|
||||||
" FROM exa_sets"
|
" FROM exa_sets"
|
||||||
" WHERE ExaCod=%ld"
|
" WHERE ExaCod=%ld"
|
||||||
" AND SetInd<%u",
|
" AND SetInd<%u",
|
||||||
ExaCod,SetInd))
|
ExaCod,
|
||||||
Lay_ShowErrorAndExit ("Error: previous set index not found.");
|
SetInd);
|
||||||
|
|
||||||
/***** Get previous set index (row[0]) *****/
|
|
||||||
row = mysql_fetch_row (mysql_res);
|
|
||||||
if (row)
|
|
||||||
if (row[0])
|
|
||||||
if (sscanf (row[0],"%u",&PrevSetInd) != 1)
|
|
||||||
Lay_ShowErrorAndExit ("Error when getting previous set index.");
|
|
||||||
|
|
||||||
/***** Free structure that stores the query result *****/
|
|
||||||
DB_FreeMySQLResult (&mysql_res);
|
|
||||||
|
|
||||||
return PrevSetInd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/*************** Get next set index to a given index in an exam **************/
|
/*************** Get next set index to a given index in an exam **************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
// Input set index can be 0, 1, 2, 3... n-1
|
// Input set index can be 0, 1, 2, 3... n-1
|
||||||
// Return set index will be 1, 2, 3... n if next set exists, or 0 if no next set
|
// Return set index will be 1, 2, 3... n if next set exists, or big number if no next set
|
||||||
|
|
||||||
static unsigned ExaSet_GetNextSetIndexInExam (long ExaCod,unsigned SetInd)
|
static unsigned ExaSet_GetNextSetIndexInExam (long ExaCod,unsigned SetInd)
|
||||||
{
|
{
|
||||||
MYSQL_RES *mysql_res;
|
unsigned NextSetInd;
|
||||||
MYSQL_ROW row;
|
|
||||||
unsigned NextSetInd = ExaSes_AFTER_LAST_QUESTION; // End of sets has been reached
|
|
||||||
|
|
||||||
/***** Get next set index in an exam from database *****/
|
/***** Get next set index in an exam from database *****/
|
||||||
// Although indexes are always continuous...
|
// Although indexes are always continuous...
|
||||||
// ...this implementation works even with non continuous indexes
|
// ...this implementation works even with non continuous indexes
|
||||||
if (!DB_QuerySELECT (&mysql_res,"can not get next set index",
|
NextSetInd = DB_QuerySELECTUnsigned ("can not get next set index",
|
||||||
"SELECT MIN(SetInd)" // row[0]
|
"SELECT MIN(SetInd)"
|
||||||
" FROM exa_sets"
|
" FROM exa_sets"
|
||||||
" WHERE ExaCod=%ld"
|
" WHERE ExaCod=%ld"
|
||||||
" AND SetInd>%u",
|
" AND SetInd>%u",
|
||||||
ExaCod,SetInd))
|
ExaCod,
|
||||||
Lay_ShowErrorAndExit ("Error: next set index not found.");
|
SetInd);
|
||||||
|
if (NextSetInd == 0)
|
||||||
/***** Get next set index (row[0]) *****/
|
NextSetInd = ExaSes_AFTER_LAST_QUESTION; // End of sets has been reached
|
||||||
row = mysql_fetch_row (mysql_res);
|
|
||||||
if (row)
|
|
||||||
if (row[0])
|
|
||||||
if (sscanf (row[0],"%u",&NextSetInd) != 1)
|
|
||||||
Lay_ShowErrorAndExit ("Error when getting next set index.");
|
|
||||||
|
|
||||||
/***** Free structure that stores the query result *****/
|
|
||||||
DB_FreeMySQLResult (&mysql_res);
|
|
||||||
|
|
||||||
return NextSetInd;
|
return NextSetInd;
|
||||||
}
|
}
|
||||||
|
|
116
swad_game.c
116
swad_game.c
|
@ -1843,33 +1843,18 @@ static void Gam_RemAnswersOfAQuestion (long GamCod,unsigned QstInd)
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/************ Get question index given game and code of question *************/
|
/************ Get question index given game and code of question *************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
// Return 0 is question is not present in game
|
||||||
|
|
||||||
static unsigned Gam_GetQstIndFromQstCod (long GamCod,long QstCod)
|
static unsigned Gam_GetQstIndFromQstCod (long GamCod,long QstCod)
|
||||||
{
|
{
|
||||||
MYSQL_RES *mysql_res;
|
|
||||||
MYSQL_ROW row;
|
|
||||||
unsigned QstInd = 0; // Return 0 is question is not present in game
|
|
||||||
|
|
||||||
/***** Get question index in a game given the question code *****/
|
/***** Get question index in a game given the question code *****/
|
||||||
if (DB_QuerySELECT (&mysql_res,"can not get question index",
|
return DB_QuerySELECTUnsigned ("can not get question index",
|
||||||
"SELECT QstInd" // row[0]
|
"SELECT QstInd"
|
||||||
" FROM gam_questions"
|
" FROM gam_questions"
|
||||||
" WHERE GamCod=%ld"
|
" WHERE GamCod=%ld"
|
||||||
" AND QstCod=%ld",
|
" AND QstCod=%ld",
|
||||||
GamCod,
|
GamCod,
|
||||||
QstCod))
|
QstCod);
|
||||||
{
|
|
||||||
/***** Get question code (row[0]) *****/
|
|
||||||
row = mysql_fetch_row (mysql_res);
|
|
||||||
QstInd = Str_ConvertStrToUnsigned (row[0]);
|
|
||||||
if (QstInd == 0)
|
|
||||||
Lay_ShowErrorAndExit ("Error: wrong question index.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/***** Free structure that stores the query result *****/
|
|
||||||
DB_FreeMySQLResult (&mysql_res);
|
|
||||||
|
|
||||||
return QstInd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -1902,25 +1887,12 @@ long Gam_GetQstCodFromQstInd (long GamCod,unsigned QstInd)
|
||||||
|
|
||||||
static unsigned Gam_GetMaxQuestionIndexInGame (long GamCod)
|
static unsigned Gam_GetMaxQuestionIndexInGame (long GamCod)
|
||||||
{
|
{
|
||||||
MYSQL_RES *mysql_res;
|
|
||||||
MYSQL_ROW row;
|
|
||||||
unsigned QstInd = 0;
|
|
||||||
|
|
||||||
/***** Get maximum question index in a game from database *****/
|
/***** Get maximum question index in a game from database *****/
|
||||||
DB_QuerySELECT (&mysql_res,"can not get last question index",
|
return DB_QuerySELECTUnsigned ("can not get last question index",
|
||||||
"SELECT MAX(QstInd)" // row[0]
|
"SELECT MAX(QstInd)"
|
||||||
" FROM gam_questions"
|
" FROM gam_questions"
|
||||||
" WHERE GamCod=%ld",
|
" WHERE GamCod=%ld",
|
||||||
GamCod);
|
GamCod);
|
||||||
row = mysql_fetch_row (mysql_res);
|
|
||||||
if (row[0]) // There are questions
|
|
||||||
if (sscanf (row[0],"%u",&QstInd) != 1)
|
|
||||||
Lay_ShowErrorAndExit ("Error when getting last question index.");
|
|
||||||
|
|
||||||
/***** Free structure that stores the query result *****/
|
|
||||||
DB_FreeMySQLResult (&mysql_res);
|
|
||||||
|
|
||||||
return QstInd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -1931,33 +1903,16 @@ static unsigned Gam_GetMaxQuestionIndexInGame (long GamCod)
|
||||||
|
|
||||||
unsigned Gam_GetPrevQuestionIndexInGame (long GamCod,unsigned QstInd)
|
unsigned Gam_GetPrevQuestionIndexInGame (long GamCod,unsigned QstInd)
|
||||||
{
|
{
|
||||||
MYSQL_RES *mysql_res;
|
|
||||||
MYSQL_ROW row;
|
|
||||||
unsigned PrevQstInd = 0;
|
|
||||||
|
|
||||||
/***** Get previous question index in a game from database *****/
|
/***** Get previous question index in a game from database *****/
|
||||||
// Although indexes are always continuous...
|
// Although indexes are always continuous...
|
||||||
// ...this implementation works even with non continuous indexes
|
// ...this implementation works even with non continuous indexes
|
||||||
if (!DB_QuerySELECT (&mysql_res,"can not get previous question index",
|
return DB_QuerySELECTUnsigned ("can not get previous question index",
|
||||||
"SELECT MAX(QstInd)" // row[0]
|
"SELECT MAX(QstInd)"
|
||||||
" FROM gam_questions"
|
" FROM gam_questions"
|
||||||
" WHERE GamCod=%ld"
|
" WHERE GamCod=%ld"
|
||||||
" AND QstInd<%u",
|
" AND QstInd<%u",
|
||||||
GamCod,
|
GamCod,
|
||||||
QstInd))
|
QstInd);
|
||||||
Lay_ShowErrorAndExit ("Error: previous question index not found.");
|
|
||||||
|
|
||||||
/***** Get previous question index (row[0]) *****/
|
|
||||||
row = mysql_fetch_row (mysql_res);
|
|
||||||
if (row)
|
|
||||||
if (row[0])
|
|
||||||
if (sscanf (row[0],"%u",&PrevQstInd) != 1)
|
|
||||||
Lay_ShowErrorAndExit ("Error when getting previous question index.");
|
|
||||||
|
|
||||||
/***** Free structure that stores the query result *****/
|
|
||||||
DB_FreeMySQLResult (&mysql_res);
|
|
||||||
|
|
||||||
return PrevQstInd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -1968,31 +1923,20 @@ unsigned Gam_GetPrevQuestionIndexInGame (long GamCod,unsigned QstInd)
|
||||||
|
|
||||||
unsigned Gam_GetNextQuestionIndexInGame (long GamCod,unsigned QstInd)
|
unsigned Gam_GetNextQuestionIndexInGame (long GamCod,unsigned QstInd)
|
||||||
{
|
{
|
||||||
MYSQL_RES *mysql_res;
|
unsigned NextQstInd;
|
||||||
MYSQL_ROW row;
|
|
||||||
unsigned NextQstInd = Mch_AFTER_LAST_QUESTION; // End of questions has been reached
|
|
||||||
|
|
||||||
/***** Get next question index in a game from database *****/
|
/***** Get next question index in a game from database *****/
|
||||||
// Although indexes are always continuous...
|
// Although indexes are always continuous...
|
||||||
// ...this implementation works even with non continuous indexes
|
// ...this implementation works even with non continuous indexes
|
||||||
if (!DB_QuerySELECT (&mysql_res,"can not get next question index",
|
NextQstInd = DB_QuerySELECTUnsigned ("can not get next question index",
|
||||||
"SELECT MIN(QstInd)" // row[0]
|
"SELECT MIN(QstInd)"
|
||||||
" FROM gam_questions"
|
" FROM gam_questions"
|
||||||
" WHERE GamCod=%ld"
|
" WHERE GamCod=%ld"
|
||||||
" AND QstInd>%u",
|
" AND QstInd>%u",
|
||||||
GamCod,
|
GamCod,
|
||||||
QstInd))
|
QstInd);
|
||||||
Lay_ShowErrorAndExit ("Error: next question index not found.");
|
if (NextQstInd == 0)
|
||||||
|
NextQstInd = Mch_AFTER_LAST_QUESTION; // End of questions has been reached
|
||||||
/***** Get next question index (row[0]) *****/
|
|
||||||
row = mysql_fetch_row (mysql_res);
|
|
||||||
if (row)
|
|
||||||
if (row[0])
|
|
||||||
if (sscanf (row[0],"%u",&NextQstInd) != 1)
|
|
||||||
Lay_ShowErrorAndExit ("Error when getting next question index.");
|
|
||||||
|
|
||||||
/***** Free structure that stores the query result *****/
|
|
||||||
DB_FreeMySQLResult (&mysql_res);
|
|
||||||
|
|
||||||
return NextQstInd;
|
return NextQstInd;
|
||||||
}
|
}
|
||||||
|
|
30
swad_match.c
30
swad_match.c
|
@ -3494,7 +3494,7 @@ static void Mch_ShowMatchScore (const struct Mch_Match *Match)
|
||||||
double Range;
|
double Range;
|
||||||
double NumRowsPerScorePoint;
|
double NumRowsPerScorePoint;
|
||||||
double Score;
|
double Score;
|
||||||
unsigned MaxUsrs = 0;
|
unsigned MaxUsrs;
|
||||||
unsigned NumUsrs;
|
unsigned NumUsrs;
|
||||||
unsigned NumRowForThisScore;
|
unsigned NumRowForThisScore;
|
||||||
unsigned NumRow;
|
unsigned NumRow;
|
||||||
|
@ -3507,26 +3507,14 @@ static void Mch_ShowMatchScore (const struct Mch_Match *Match)
|
||||||
NumRowsPerScorePoint = (double) Mch_NUM_ROWS_SCORE / Range;
|
NumRowsPerScorePoint = (double) Mch_NUM_ROWS_SCORE / Range;
|
||||||
|
|
||||||
/***** Get maximum number of users *****/
|
/***** Get maximum number of users *****/
|
||||||
if (DB_QuerySELECT (&mysql_res,"can not get max users",
|
MaxUsrs = DB_QuerySELECTUnsigned ("can not get max users",
|
||||||
"SELECT MAX(NumUsrs)" // row[0]
|
"SELECT MAX(NumUsrs)"
|
||||||
" FROM (SELECT COUNT(*) AS NumUsrs"
|
" FROM (SELECT COUNT(*) AS NumUsrs"
|
||||||
" FROM mch_results"
|
" FROM mch_results"
|
||||||
" WHERE MchCod=%ld"
|
" WHERE MchCod=%ld"
|
||||||
" GROUP BY Score"
|
" GROUP BY Score"
|
||||||
" ORDER BY Score) AS Scores",
|
" ORDER BY Score) AS Scores",
|
||||||
Match->MchCod))
|
Match->MchCod);
|
||||||
{
|
|
||||||
row = mysql_fetch_row (mysql_res);
|
|
||||||
|
|
||||||
/* Get maximum number of users (row[0]) *****/
|
|
||||||
if (row)
|
|
||||||
if (row[0])
|
|
||||||
if (sscanf (row[0],"%u",&MaxUsrs) != 1)
|
|
||||||
MaxUsrs = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Free structure that stores the query result */
|
|
||||||
DB_FreeMySQLResult (&mysql_res);
|
|
||||||
|
|
||||||
/***** Get scores from database *****/
|
/***** Get scores from database *****/
|
||||||
NumScores = (unsigned)
|
NumScores = (unsigned)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user