Version19.4

This commit is contained in:
Antonio Cañas Vargas 2019-09-17 01:37:07 +02:00
parent 9164c0c8a4
commit d21844b547
7 changed files with 258 additions and 293 deletions

View File

@ -598,9 +598,9 @@ CREATE TABLE IF NOT EXISTS forum_thread (
UNIQUE INDEX(FirstPstCod),
UNIQUE INDEX(LastPstCod));
--
-- Table games: stores the games
-- Table gam_games: stores the games
--
CREATE TABLE IF NOT EXISTS games (
CREATE TABLE IF NOT EXISTS gam_games (
GamCod INT NOT NULL AUTO_INCREMENT,
CrsCod INT NOT NULL DEFAULT -1,
Hidden ENUM('N','Y') NOT NULL DEFAULT 'N',
@ -611,25 +611,25 @@ CREATE TABLE IF NOT EXISTS games (
UNIQUE INDEX(GamCod),
INDEX(CrsCod));
--
-- Table gam_answers: stores the answers to the matches
-- Table mch_answers: stores the answers to the matches
--
CREATE TABLE IF NOT EXISTS gam_answers ("
CREATE TABLE IF NOT EXISTS mch_answers ("
MchCod INT NOT NULL,"
UsrCod INT NOT NULL,"
QstInd INT NOT NULL,"
AnsInd TINYINT NOT NULL,"
UNIQUE INDEX(MchCod,UsrCod,QstInd));
--
-- Table gam_grp: stores the groups associated to each match in a game
-- Table mch_groups: stores the groups associated to each match in a game
--
CREATE TABLE IF NOT EXISTS gam_grp (
CREATE TABLE IF NOT EXISTS mch_groups (
MchCod INT NOT NULL,
GrpCod INT NOT NULL,
UNIQUE INDEX(MchCod,GrpCod));
--
-- Table gam_matches: stores the matches (games instances) already played
-- Table mch_matches: stores the matches (games instances) already played
--
CREATE TABLE IF NOT EXISTS gam_matches (
CREATE TABLE IF NOT EXISTS mch_matches (
MchCod INT NOT NULL AUTO_INCREMENT,
GamCod INT NOT NULL,
UsrCod INT NOT NULL,
@ -644,16 +644,16 @@ CREATE TABLE IF NOT EXISTS gam_matches (
UNIQUE INDEX(MchCod),
INDEX(GamCod));
--
-- Table gam_mch_being_played: stores the current matches being played
-- Table mch_playing: stores the current matches being played
--
CREATE TABLE IF NOT EXISTS gam_mch_being_played (
CREATE TABLE IF NOT EXISTS mch_playing (
MchCod INT NOT NULL,
TS TIMESTAMP,
UNIQUE INDEX(MchCod));
--
-- Table gam_players: stores the current match players
-- Table mch_players: stores the current match players
--
CREATE TABLE IF NOT EXISTS gam_players (
CREATE TABLE IF NOT EXISTS mch_players (
MchCod INT NOT NULL,
UsrCod INT NOT NULL,
TS TIMESTAMP,
@ -668,9 +668,9 @@ CREATE TABLE IF NOT EXISTS gam_questions (
INDEX(GamCod),
INDEX(QstCod));
--
-- Table gam_time: stores the elapsed time in every question in every match played
-- Table mch_times: stores the elapsed time in every question in every match played
--
CREATE TABLE IF NOT EXISTS gam_time (
CREATE TABLE IF NOT EXISTS mch_times (
MchCod INT NOT NULL,
QstInd INT NOT NULL,
ElapsedTime TIME NOT NULL DEFAULT 0,

View File

@ -4373,25 +4373,6 @@ int swad__getGames (struct soap *soap,
}
/***** Query list of games *****/
/*
mysql> DESCRIBE games;
+-----------+-------------------------------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------------------------------------+------+-----+---------+----------------+
| GamCod | int(11) | NO | PRI | NULL | auto_increment |
| Scope | enum('Sys','Cty','Ins','Ctr','Deg','Crs') | NO | MUL | Sys | |
| Cod | int(11) | NO | | -1 | |
| Hidden | enum('N','Y') | NO | | N | |
| NumNotif | int(11) | NO | | 0 | |
| Roles | int(11) | NO | | 0 | |
| UsrCod | int(11) | NO | | NULL | |
| StartTime | datetime | NO | | NULL | |
| EndTime | datetime | NO | | NULL | |
| Title | varchar(2047) | NO | | NULL | |
| Txt | text | NO | | NULL | |
+-----------+-------------------------------------------+------+-----+---------+----------------+
11 rows in set (0.00 sec)
*/
NumRows =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get games",
"SELECT GamCod," // row[0]
@ -4400,16 +4381,16 @@ int swad__getGames (struct soap *soap,
"UNIX_TIMESTAMP(EndTime) AS ET," // row[3]
"Title," // row[4]
"Txt" // row[5]
" FROM att_events"
" WHERE Scope='%s' AND Cod=%ld"
" FROM gam_games"
" WHERE CrsCod=%ld"
" AND Hidden='N'"
" AND NOW() BETWEEN StartTime AND EndTime"
" AND (GamCod NOT IN (SELECT GamCod FROM gam_grp) OR"
" GamCod IN (SELECT gam_grp.GamCod FROM gam_grp,crs_grp_usr"
" AND (GamCod NOT IN (SELECT GamCod FROM mch_groups) OR"
" GamCod IN (SELECT mch_groups.GamCod FROM mch_groups,crs_grp_usr"
" WHERE crs_grp_usr.UsrCod=%ld"
" AND gam_grp.GrpCod=crs_grp_usr.GrpCod))"
" AND mch_groups.GrpCod=crs_grp_usr.GrpCod))"
" ORDER BY ST DESC,ET DESC,Title DESC",
Sco_GetDBStrFromScope (Hie_CRS),courseCode,
courseCode,
Gbl.Usrs.Me.UsrDat.UsrCod);
getGamesOut->gamesArray.__size =
@ -4520,8 +4501,8 @@ static void API_GetListGrpsInGameFromDB (long GamCod,char **ListGroups)
/***** Get list of groups *****/
NumGrps =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get groups of a game",
"SELECT GrpCod FROM gam_grp WHERE GamCod=%ld",
(unsigned) DB_QuerySELECT (&mysql_res,"can not get groups of a match",
"SELECT GrpCod FROM mch_groups WHERE GamCod=%ld",
GamCod);
if (NumGrps == 0)
*ListGroups = NULL;

View File

@ -459,11 +459,26 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - *
En OpenSWAD:
ps2pdf source.ps destination.pdf
*/
/*
can not remove the groups associated to matches of a game
Type of answer not valid in a game.
*/
#define Log_PLATFORM_VERSION "SWAD 19.3 (2019-09-15)"
#define Log_PLATFORM_VERSION "SWAD 19.4 (2019-09-17)"
#define CSS_FILE "swad19.3.css"
#define JS_FILE "swad18.130.2.js"
/*
Version 19.4: Sep 17, 2019 Changes in games ans matches tables. (244644 lines)
8 changes necessary in database:
RENAME TABLE gam_answers TO mch_answers;
RENAME TABLE gam_grp TO mch_groups;
RENAME TABLE gam_matches TO mch_matches;
RENAME TABLE gam_players TO mch_players;
RENAME TABLE gam_mch_being_played TO mch_playing;
RENAME TABLE gam_time TO mch_times;
RENAME TABLE games TO gam_games;
DROP TABLE gam_playing;
Version 19.3: Sep 15, 2019 Changes in match results. (244680 lines)
2 changes necessary in database:
ALTER TABLE gam_matches DROP COLUMN Showing;

View File

@ -1303,9 +1303,9 @@ mysql> DESCRIBE forum_thread;
"UNIQUE INDEX(LastPstCod))");
/***** Table games *****/
/***** Table gam_games *****/
/*
mysql> DESCRIBE games;
mysql> DESCRIBE gam_games;
+----------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------------+------+-----+---------+----------------+
@ -1319,7 +1319,7 @@ mysql> DESCRIBE games;
+----------+---------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)
*/
DB_CreateTable ("CREATE TABLE IF NOT EXISTS games ("
DB_CreateTable ("CREATE TABLE IF NOT EXISTS gam_games ("
"GamCod INT NOT NULL AUTO_INCREMENT,"
"CrsCod INT NOT NULL DEFAULT -1,"
"Hidden ENUM('N','Y') NOT NULL DEFAULT 'N',"
@ -1330,9 +1330,9 @@ mysql> DESCRIBE games;
"UNIQUE INDEX(GamCod),"
"INDEX(CrsCod))");
/***** Table gam_answers *****/
/***** Table mch_answers *****/
/*
mysql> DESCRIBE gam_answers;
mysql> DESCRIBE mch_answers;
+--------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+------------+------+-----+---------+-------+
@ -1343,16 +1343,16 @@ mysql> DESCRIBE gam_answers;
+--------+------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
*/
DB_CreateTable ("CREATE TABLE IF NOT EXISTS gam_answers ("
DB_CreateTable ("CREATE TABLE IF NOT EXISTS mch_answers ("
"MchCod INT NOT NULL,"
"UsrCod INT NOT NULL,"
"QstInd INT NOT NULL,"
"AnsInd TINYINT NOT NULL,"
"UNIQUE INDEX(MchCod,UsrCod,QstInd))");
/***** Table gam_grp *****/
/***** Table mch_groups *****/
/*
mysql> DESCRIBE gam_grp;
mysql> DESCRIBE mch_groups;
+--------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+---------+------+-----+---------+-------+
@ -1361,14 +1361,14 @@ mysql> DESCRIBE gam_grp;
+--------+---------+------+-----+---------+-------+
2 rows in set (0.01 sec)
*/
DB_CreateTable ("CREATE TABLE IF NOT EXISTS gam_grp ("
DB_CreateTable ("CREATE TABLE IF NOT EXISTS mch_groups ("
"MchCod INT NOT NULL,"
"GrpCod INT NOT NULL,"
"UNIQUE INDEX(MchCod,GrpCod))");
/***** Table gam_matches *****/
/***** Table mch_matches *****/
/*
mysql> DESCRIBE gam_matches;
mysql> DESCRIBE mch_matches;
+--------------+----------------------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+----------------------------------+------+-----+---------+----------------+
@ -1386,7 +1386,7 @@ mysql> DESCRIBE gam_matches;
+--------------+----------------------------------+------+-----+---------+----------------+
11 rows in set (0.00 sec)
*/
DB_CreateTable ("CREATE TABLE IF NOT EXISTS gam_matches ("
DB_CreateTable ("CREATE TABLE IF NOT EXISTS mch_matches ("
"MchCod INT NOT NULL AUTO_INCREMENT,"
"GamCod INT NOT NULL,"
"UsrCod INT NOT NULL,"
@ -1401,9 +1401,9 @@ mysql> DESCRIBE gam_matches;
"UNIQUE INDEX(MchCod),"
"INDEX(GamCod)");
/***** Table gam_mch_being_played *****/
/***** Table mch_playing *****/
/*
mysql> DESCRIBE gam_mch_being_played;
mysql> DESCRIBE mch_playing;
+--------+-----------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+--------+-----------+------+-----+-------------------+-----------------------------+
@ -1412,14 +1412,14 @@ mysql> DESCRIBE gam_mch_being_played;
+--------+-----------+------+-----+-------------------+-----------------------------+
2 rows in set (0.01 sec)
*/
DB_CreateTable ("CREATE TABLE IF NOT EXISTS gam_mch_being_played ("
DB_CreateTable ("CREATE TABLE IF NOT EXISTS mch_playing ("
"MchCod INT NOT NULL,"
"TS TIMESTAMP,"
"UNIQUE INDEX(MchCod))");
/***** Table gam_players *****/
/***** Table mch_players *****/
/*
mysql> DESCRIBE gam_players;
mysql> DESCRIBE mch_players;
+--------+-----------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+--------+-----------+------+-----+-------------------+-----------------------------+
@ -1429,7 +1429,7 @@ mysql> DESCRIBE gam_players;
+--------+-----------+------+-----+-------------------+-----------------------------+
3 rows in set (0.00 sec)
*/
DB_CreateTable ("CREATE TABLE IF NOT EXISTS gam_players ("
DB_CreateTable ("CREATE TABLE IF NOT EXISTS mch_players ("
"MchCod INT NOT NULL,"
"UsrCod INT NOT NULL,"
"TS TIMESTAMP,"
@ -1454,9 +1454,9 @@ mysql> DESCRIBE gam_questions;
"INDEX(GamCod),"
"INDEX(QstCod))");
/***** Table gam_time *****/
/***** Table mch_times *****/
/*
mysql> DESCRIBE gam_time;
mysql> DESCRIBE mch_times;
+-------------+---------+------+-----+----------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------+------+-----+----------+-------+
@ -1466,7 +1466,7 @@ mysql> DESCRIBE gam_time;
+-------------+---------+------+-----+----------+-------+
3 rows in set (0.00 sec)
*/
DB_CreateTable ("CREATE TABLE IF NOT EXISTS gam_time ("
DB_CreateTable ("CREATE TABLE IF NOT EXISTS mch_times ("
"MchCod INT NOT NULL,"
"QstInd INT NOT NULL,"
"ElapsedTime TIME NOT NULL DEFAULT 0,"

View File

@ -603,9 +603,9 @@ void Gam_GetListGames (void)
{
static const char *OrderBySubQuery[Gam_NUM_ORDERS] =
{
"StartTime DESC,EndTime DESC,games.Title DESC", // Gam_ORDER_BY_START_DATE
"EndTime DESC,StartTime DESC,games.Title DESC", // Gam_ORDER_BY_END_DATE
"games.Title DESC", // Gam_ORDER_BY_TITLE
"StartTime DESC,EndTime DESC,gam_games.Title DESC", // Gam_ORDER_BY_START_DATE
"EndTime DESC,StartTime DESC,gam_games.Title DESC", // Gam_ORDER_BY_END_DATE
"gam_games.Title DESC", // Gam_ORDER_BY_TITLE
};
MYSQL_RES *mysql_res;
MYSQL_ROW row;
@ -618,14 +618,14 @@ void Gam_GetListGames (void)
/***** Get list of games from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get games",
"SELECT games.GamCod,"
"MIN(gam_matches.StartTime) AS StartTime,"
"MAX(gam_matches.EndTime) AS EndTime"
" FROM games"
" LEFT JOIN gam_matches"
" ON games.GamCod=gam_matches.GamCod"
" WHERE games.CrsCod=%ld"
" GROUP BY games.GamCod"
"SELECT gam_games.GamCod,"
"MIN(mch_matches.StartTime) AS StartTime,"
"MAX(mch_matches.EndTime) AS EndTime"
" FROM gam_games"
" LEFT JOIN mch_matches"
" ON gam_games.GamCod=mch_matches.GamCod"
" WHERE gam_games.CrsCod=%ld"
" GROUP BY gam_games.GamCod"
" ORDER BY %s",
Gbl.Hierarchy.Crs.CrsCod,
OrderBySubQuery[Gbl.Games.SelectedOrder]);
@ -669,14 +669,14 @@ void Gam_GetDataOfGameByCod (struct Game *Game)
/***** Get data of game from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get game data",
"SELECT games.GamCod," // row[0]
"games.Hidden," // row[1]
"games.UsrCod," // row[2]
"games.Title" // row[3]
" FROM games"
" LEFT JOIN gam_matches"
" ON games.GamCod=gam_matches.GamCod"
" WHERE games.GamCod=%ld",
"SELECT gam_games.GamCod," // row[0]
"gam_games.Hidden," // row[1]
"gam_games.UsrCod," // row[2]
"gam_games.Title" // row[3]
" FROM gam_games"
" LEFT JOIN mch_matches"
" ON gam_games.GamCod=mch_matches.GamCod"
" WHERE gam_games.GamCod=%ld",
Game->GamCod);
if (NumRows) // Game found...
{
@ -750,7 +750,7 @@ void Gam_GetDataOfGameByCod (struct Game *Game)
NumRows = DB_QuerySELECT (&mysql_res,"can not get game data",
"SELECT UNIX_TIMESTAMP(MIN(StartTime))," // row[0]
"UNIX_TIMESTAMP(MAX(EndTime))" // row[1]
" FROM gam_matches"
" FROM mch_matches"
" WHERE GamCod=%ld",
Game->GamCod);
if (NumRows)
@ -803,7 +803,7 @@ static void Gam_GetGameTxtFromDB (long GamCod,char Txt[Cns_MAX_BYTES_TEXT + 1])
/***** Get text of game from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get game text",
"SELECT Txt FROM games WHERE GamCod=%ld",
"SELECT Txt FROM gam_games WHERE GamCod=%ld",
GamCod);
/***** The result of the query must have one row or none *****/
@ -904,18 +904,18 @@ void Gam_RemoveGame (void)
/***** Remove all the matches in this game *****/
/* Remove groups in matches of the game */
DB_QueryDELETE ("can not remove the groups associated to matches of a game",
"DELETE FROM gam_grp USING gam_grp,gam_matches"
" WHERE gam_matches.GrpCod=%ld"
" AND gam_matches.MchCod=gam_grp.MchCod",
"DELETE FROM mch_groups USING mch_groups,mch_matches"
" WHERE mch_matches.GrpCod=%ld"
" AND mch_matches.MchCod=mch_groups.MchCod",
Game.GamCod);
/* Remove matches of the game */
DB_QueryDELETE ("can not remove matches of a game",
"DELETE FROM gam_matches WHERE GamCod=%ld",
"DELETE FROM mch_matches WHERE GamCod=%ld",
Game.GamCod);
/***** Remove game *****/
DB_QueryDELETE ("can not remove game",
"DELETE FROM games WHERE GamCod=%ld",
"DELETE FROM gam_games WHERE GamCod=%ld",
Game.GamCod);
/***** Write message to show the change made *****/
@ -983,10 +983,10 @@ void Gam_ResetGame (void)
/***** Reset all the answers in this game *****/
DB_QueryUPDATE ("can not reset answers of a game",
"UPDATE gam_answers,gam_questions"
" SET gam_answers.NumUsrs=0"
"UPDATE mch_answers,gam_questions"
" SET mch_answers.NumUsrs=0"
" WHERE gam_questions.GamCod=%ld"
" AND gam_questions.QstCod=gam_answers.QstCod",
" AND gam_questions.QstCod=mch_answers.QstCod",
Game.GamCod);
/***** Write message to show the change made *****/
@ -1016,7 +1016,7 @@ void Gam_HideGame (void)
/***** Hide game *****/
DB_QueryUPDATE ("can not hide game",
"UPDATE games SET Hidden='Y' WHERE GamCod=%ld",
"UPDATE gam_games SET Hidden='Y' WHERE GamCod=%ld",
Game.GamCod);
/***** Show games again *****/
@ -1042,7 +1042,7 @@ void Gam_UnhideGame (void)
/***** Show game *****/
DB_QueryUPDATE ("can not show game",
"UPDATE games SET Hidden='N' WHERE GamCod=%ld",
"UPDATE gam_games SET Hidden='N' WHERE GamCod=%ld",
Game.GamCod);
/***** Show games again *****/
@ -1057,7 +1057,7 @@ static bool Gam_CheckIfSimilarGameExists (struct Game *Game)
{
/***** Get number of games with a field value from database *****/
return (DB_QueryCOUNT ("can not get similar games",
"SELECT COUNT(*) FROM games"
"SELECT COUNT(*) FROM gam_games"
" WHERE CrsCod=%ld AND Title='%s'"
" AND GamCod<>%ld",
Gbl.Hierarchy.Crs.CrsCod,Game->Title,
@ -1256,7 +1256,7 @@ static void Gam_CreateGame (struct Game *Game,const char *Txt)
/***** Create a new game *****/
Game->GamCod =
DB_QueryINSERTandReturnCode ("can not create new game",
"INSERT INTO games"
"INSERT INTO gam_games"
" (CrsCod,Hidden,UsrCod,Title,Txt)"
" VALUES"
" (%ld,'N',%ld,'%s','%s')",
@ -1280,7 +1280,7 @@ static void Gam_UpdateGame (struct Game *Game,const char *Txt)
/***** Update the data of the game *****/
DB_QueryUPDATE ("can not update game",
"UPDATE games"
"UPDATE gam_games"
" SET CrsCod=%ld,"
"Title='%s',"
"Txt='%s'"
@ -1302,7 +1302,7 @@ bool Gam_CheckIfMatchIsAssociatedToGrp (long MchCod,long GrpCod)
{
/***** Get if a match is associated to a group from database *****/
return (DB_QueryCOUNT ("can not check if a match is associated to a group",
"SELECT COUNT(*) FROM gam_grp"
"SELECT COUNT(*) FROM mch_groups"
" WHERE MchCod=%ld AND GrpCod=%ld",
MchCod,GrpCod) != 0);
}
@ -1314,10 +1314,10 @@ bool Gam_CheckIfMatchIsAssociatedToGrp (long MchCod,long GrpCod)
void Gam_RemoveGroup (long GrpCod)
{
/***** Remove group from all the games *****/
/***** Remove group from all the matches *****/
DB_QueryDELETE ("can not remove group"
" from the associations between games and groups",
"DELETE FROM gam_grp WHERE GrpCod=%ld",
" from the associations between matches and groups",
"DELETE FROM mch_groups WHERE GrpCod=%ld",
GrpCod);
}
@ -1328,12 +1328,12 @@ void Gam_RemoveGroup (long GrpCod)
void Gam_RemoveGroupsOfType (long GrpTypCod)
{
/***** Remove group from all the games *****/
/***** Remove group from all the matches *****/
DB_QueryDELETE ("can not remove groups of a type"
" from the associations between games and groups",
"DELETE FROM gam_grp USING crs_grp,gam_grp"
" from the associations between matches and groups",
"DELETE FROM mch_groups USING crs_grp,mch_groups"
" WHERE crs_grp.GrpTypCod=%ld"
" AND crs_grp.GrpCod=gam_grp.GrpCod",
" AND crs_grp.GrpCod=mch_groups.GrpCod",
GrpTypCod);
}
@ -1342,40 +1342,40 @@ void Gam_RemoveGroupsOfType (long GrpTypCod)
/************* (country, institution, centre, degree or course) **************/
/*****************************************************************************/
void Gam_RemoveGames (Hie_Level_t Scope,long Cod)
void Gam_RemoveGames (long CrsCod) // TODO: Function not used?????
{
/***** Remove all the answers in course games *****/
DB_QueryDELETE ("can not remove answers of games"
" in a place on the hierarchy"
"DELETE FROM gam_answers"
" USING games,gam_questions,gam_answers"
" WHERE games.Scope='%s' AND games.Cod=%ld"
" AND games.GamCod=gam_questions.GamCod"
" AND gam_questions.QstCod=gam_answers.QstCod",
Sco_GetDBStrFromScope (Scope),Cod);
" in a place on the hierarchy",
"DELETE FROM mch_answers"
" USING gam_games,gam_questions,mch_answers"
" WHERE gam_games.CrsCod=%ld"
" AND gam_games.GamCod=gam_questions.GamCod"
" AND gam_questions.QstCod=mch_answers.QstCod",
CrsCod);
/***** Remove all the questions in course games *****/
DB_QueryDELETE ("can not remove questions of games"
DB_QueryDELETE ("can not remove questions of gam_games"
" in a place on the hierarchy",
"DELETE FROM gam_questions"
" USING games,gam_questions"
" WHERE games.Scope='%s' AND games.Cod=%ld"
" AND games.GamCod=gam_questions.GamCod",
Sco_GetDBStrFromScope (Scope),Cod);
" USING gam_games,gam_questions"
" WHERE gam_games.CrsCod=%ld"
" AND gam_games.GamCod=gam_questions.GamCod",
CrsCod);
/***** Remove groups *****/
DB_QueryDELETE ("can not remove all the groups"
" associated to games of a course",
"DELETE FROM gam_grp"
" USING games,gam_grp"
" WHERE games.Scope='%s' AND games.Cod=%ld"
" AND games.GamCod=gam_grp.GamCod",
Sco_GetDBStrFromScope (Scope),Cod);
"DELETE FROM mch_groups"
" USING gam_games,mch_groups"
" WHERE gam_games.CrsCod=%ld"
" AND gam_games.GamCod=mch_groups.GamCod",
CrsCod);
/***** Remove course games *****/
DB_QueryDELETE ("can not remove all the games in a place on the hierarchy",
"DELETE FROM games WHERE Scope='%s' AND Cod=%ld",
Sco_GetDBStrFromScope (Scope),Cod);
"DELETE FROM gam_games WHERE CrsCod=%ld",
CrsCod);
}
/*****************************************************************************/
@ -1464,7 +1464,7 @@ static void Gam_RemAnswersOfAQuestion (long GamCod,unsigned QstInd)
{
/***** Remove answers *****/
DB_QueryDELETE ("can not remove the answers of a question",
"DELETE FROM gam_answers"
"DELETE FROM mch_answers"
" WHERE GamCod=%ld AND QstInd=%u",
GamCod,QstInd);
}
@ -2062,7 +2062,7 @@ void Gam_RemoveQst (void)
/* Change index of questions greater than this */
DB_QueryUPDATE ("can not update indexes of questions in table of answers",
"UPDATE gam_answers SET QstInd=QstInd-1"
"UPDATE mch_answers SET QstInd=QstInd-1"
" WHERE GamCod=%ld AND QstInd>%u",
Game.GamCod,QstInd);
DB_QueryUPDATE ("can not update indexes of questions",
@ -2269,62 +2269,52 @@ unsigned Gam_GetNumCoursesWithGames (Hie_Level_t Scope)
{
case Hie_SYS:
DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
"SELECT COUNT(DISTINCT Cod)"
" FROM games"
" WHERE Scope='%s'",
Sco_GetDBStrFromScope (Hie_CRS));
"SELECT COUNT(DISTINCT CrsCod)"
" FROM gam_games");
break;
case Hie_CTY:
DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
"SELECT COUNT(DISTINCT games.Cod)"
" FROM institutions,centres,degrees,courses,games"
"SELECT COUNT(DISTINCT gam_games.CrsCod)"
" FROM institutions,centres,degrees,courses,gam_games"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=games.Cod"
" AND games.Scope='%s'",
Gbl.Hierarchy.Ins.InsCod,
Sco_GetDBStrFromScope (Hie_CRS));
" AND courses.CrsCod=gam_games.CrsCod",
Gbl.Hierarchy.Ins.InsCod);
break;
case Hie_INS:
DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
"SELECT COUNT(DISTINCT games.Cod)"
" FROM centres,degrees,courses,games"
"SELECT COUNT(DISTINCT gam_games.CrsCod)"
" FROM centres,degrees,courses,gam_games"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=games.Cod"
" AND games.Scope='%s'",
Gbl.Hierarchy.Ins.InsCod,
Sco_GetDBStrFromScope (Hie_CRS));
" AND courses.CrsCod=gam_games.CrsCod",
Gbl.Hierarchy.Ins.InsCod);
break;
case Hie_CTR:
DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
" FROM degrees,courses,games"
"SELECT COUNT(DISTINCT gam_games.CrsCod)"
" FROM degrees,courses,gam_games"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=games.Cod"
" AND games.Scope='%s'",
Gbl.Hierarchy.Ctr.CtrCod,
Sco_GetDBStrFromScope (Hie_CRS));
" AND courses.CrsCod=gam_games.CrsCod",
Gbl.Hierarchy.Ctr.CtrCod);
break;
case Hie_DEG:
DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
"SELECT COUNT(DISTINCT games.Cod)"
" FROM courses,games"
"SELECT COUNT(DISTINCT gam_games.CrsCod)"
" FROM courses,gam_games"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=games.Cod"
" AND games.Scope='%s'",
Gbl.Hierarchy.Deg.DegCod,
Sco_GetDBStrFromScope (Hie_CRS));
" AND courses.CrsCod=gam_games.CrsCod",
Gbl.Hierarchy.Deg.DegCod);
break;
case Hie_CRS:
DB_QuerySELECT (&mysql_res,"can not get number of courses with games",
"SELECT COUNT(DISTINCT Cod)"
" FROM games"
" WHERE Scope='%s' AND Cod=%ld",
Sco_GetDBStrFromScope (Hie_CRS),
"SELECT COUNT(DISTINCT CrsCod)"
" FROM gam_games"
" WHERE CrsCod=%ld",
Gbl.Hierarchy.Crs.CrsCod);
break;
default:
@ -2360,63 +2350,51 @@ unsigned Gam_GetNumGames (Hie_Level_t Scope)
case Hie_SYS:
DB_QuerySELECT (&mysql_res,"can not get number of games",
"SELECT COUNT(*)"
" FROM games"
" WHERE Scope='%s'",
Sco_GetDBStrFromScope (Hie_CRS));
" FROM gam_games");
break;
case Hie_CTY:
DB_QuerySELECT (&mysql_res,"can not get number of games",
"SELECT COUNT(*)"
" FROM institutions,centres,degrees,courses,games"
" FROM institutions,centres,degrees,courses,gam_games"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=games.Cod"
" AND games.Scope='%s'",
Gbl.Hierarchy.Cty.CtyCod,
Sco_GetDBStrFromScope (Hie_CRS));
" AND courses.CrsCod=gam_games.CrsCod",
Gbl.Hierarchy.Cty.CtyCod);
break;
case Hie_INS:
DB_QuerySELECT (&mysql_res,"can not get number of games",
"SELECT COUNT(*)"
" FROM centres,degrees,courses,games"
" FROM centres,degrees,courses,gam_games"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=games.Cod"
" AND games.Scope='%s'",
Gbl.Hierarchy.Ins.InsCod,
Sco_GetDBStrFromScope (Hie_CRS));
" AND courses.CrsCod=gam_games.CrsCod",
Gbl.Hierarchy.Ins.InsCod);
break;
case Hie_CTR:
DB_QuerySELECT (&mysql_res,"can not get number of games",
"SELECT COUNT(*)"
" FROM degrees,courses,games"
" FROM degrees,courses,gam_games"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=games.Cod"
" AND games.Scope='%s'",
Gbl.Hierarchy.Ctr.CtrCod,
Sco_GetDBStrFromScope (Hie_CRS));
" AND courses.CrsCod=gam_games.CrsCod",
Gbl.Hierarchy.Ctr.CtrCod);
break;
case Hie_DEG:
DB_QuerySELECT (&mysql_res,"can not get number of games",
"SELECT COUNT(*)"
" FROM courses,games"
" FROM courses,gam_games"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=games.Cod"
" AND games.Scope='%s'",
Gbl.Hierarchy.Deg.DegCod,
Sco_GetDBStrFromScope (Hie_CRS));
" AND courses.CrsCod=gam_games.CrsCod",
Gbl.Hierarchy.Deg.DegCod);
break;
case Hie_CRS:
DB_QuerySELECT (&mysql_res,"can not get number of games",
"SELECT COUNT(*)"
" FROM games"
" WHERE games.Scope='%s'"
" AND CrsCod=%ld",
Sco_GetDBStrFromScope (Hie_CRS),
" FROM gam_games"
" WHERE CrsCod=%ld",
Gbl.Hierarchy.Crs.CrsCod);
break;
default:
@ -2452,79 +2430,69 @@ float Gam_GetNumQstsPerCrsGame (Hie_Level_t Scope)
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
" FROM games,gam_questions"
" WHERE games.Scope='%s'"
" AND games.GamCod=gam_questions.GamCod"
" GROUP BY gam_questions.GamCod) AS NumQstsTable",
Sco_GetDBStrFromScope (Hie_CRS));
" FROM gam_games,gam_questions"
" WHERE gam_games.GamCod=gam_questions.GamCod"
" GROUP BY gam_questions.GamCod) AS NumQstsTable");
break;
case Hie_CTY:
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
" FROM institutions,centres,degrees,courses,games,gam_questions"
" FROM institutions,centres,degrees,courses,gam_games,gam_questions"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=games.Cod"
" AND games.Scope='%s'"
" AND games.GamCod=gam_questions.GamCod"
" AND courses.CrsCod=gam_games.CrsCod"
" AND gam_games.GamCod=gam_questions.GamCod"
" GROUP BY gam_questions.GamCod) AS NumQstsTable",
Gbl.Hierarchy.Cty.CtyCod,
Sco_GetDBStrFromScope (Hie_CRS));
Gbl.Hierarchy.Cty.CtyCod);
break;
case Hie_INS:
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
" FROM centres,degrees,courses,games,gam_questions"
" FROM centres,degrees,courses,gam_games,gam_questions"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=games.Cod"
" AND games.Scope='%s'"
" AND games.GamCod=gam_questions.GamCod"
" AND courses.CrsCod=gam_games.CrsCod"
" AND gam_games.GamCod=gam_questions.GamCod"
" GROUP BY gam_questions.GamCod) AS NumQstsTable",
Gbl.Hierarchy.Ins.InsCod,
Sco_GetDBStrFromScope (Hie_CRS));
Gbl.Hierarchy.Ins.InsCod);
break;
case Hie_CTR:
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
" FROM degrees,courses,games,gam_questions"
" FROM degrees,courses,gam_games,gam_questions"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=games.Cod"
" AND games.Scope='%s'"
" AND games.GamCod=gam_questions.GamCod"
" AND courses.CrsCod=gam_games.CrsCod"
" AND gam_games.GamCod=gam_questions.GamCod"
" GROUP BY gam_questions.GamCod) AS NumQstsTable",
Gbl.Hierarchy.Ctr.CtrCod,
Sco_GetDBStrFromScope (Hie_CRS));
Gbl.Hierarchy.Ctr.CtrCod);
break;
case Hie_DEG:
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
" FROM courses,games,gam_questions"
" FROM courses,gam_games,gam_questions"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=games.Cod"
" AND games.Scope='%s'"
" AND games.GamCod=gam_questions.GamCod"
" AND courses.CrsCod=gam_games.CrsCod"
" AND gam_games.GamCod=gam_questions.GamCod"
" GROUP BY gam_questions.GamCod) AS NumQstsTable",
Gbl.Hierarchy.Deg.DegCod,
Sco_GetDBStrFromScope (Hie_CRS));
Gbl.Hierarchy.Deg.DegCod);
break;
case Hie_CRS:
DB_QuerySELECT (&mysql_res,"can not get number of questions per game",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(gam_questions.QstCod) AS NumQsts"
" FROM games,gam_questions"
" WHERE games.Scope='%s' AND games.Cod=%ld"
" AND games.GamCod=gam_questions.GamCod"
" FROM gam_games,gam_questions"
" WHERE gam_games.Cod=%ld"
" AND gam_games.GamCod=gam_questions.GamCod"
" GROUP BY gam_questions.GamCod) AS NumQstsTable",
Sco_GetDBStrFromScope (Hie_CRS),Gbl.Hierarchy.Crs.CrsCod);
Gbl.Hierarchy.Crs.CrsCod);
break;
default:
Lay_WrongScopeExit ();

View File

@ -105,7 +105,7 @@ void Gam_RecFormGame (void);
bool Gam_CheckIfMatchIsAssociatedToGrp (long MchCod,long GrpCod);
void Gam_RemoveGroup (long GrpCod);
void Gam_RemoveGroupsOfType (long GrpTypCod);
void Gam_RemoveGames (Hie_Level_t Scope,long Cod);
void Gam_RemoveGames (long CrsCod);
unsigned Gam_GetNumQstsGame (long GamCod);

View File

@ -205,13 +205,13 @@ void Mch_ListMatches (struct Game *Game,bool PutFormNewMatch)
{
if (asprintf (&SubQuery," AND"
"(MchCod NOT IN"
" (SELECT MchCod FROM gam_grp)"
" (SELECT MchCod FROM mch_groups)"
" OR"
" MchCod IN"
" (SELECT gam_grp.MchCod"
" FROM gam_grp,crs_grp_usr"
" (SELECT mch_groups.MchCod"
" FROM mch_groups,crs_grp_usr"
" WHERE crs_grp_usr.UsrCod=%ld"
" AND gam_grp.GrpCod=crs_grp_usr.GrpCod))",
" AND mch_groups.GrpCod=crs_grp_usr.GrpCod))",
Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
}
@ -232,7 +232,7 @@ void Mch_ListMatches (struct Game *Game,bool PutFormNewMatch)
"UNIX_TIMESTAMP(QstStartTime)," // row[ 8]
"ShowResults," // row[ 9]
"Showing" // row[10]
" FROM gam_matches"
" FROM mch_matches"
" WHERE GamCod=%ld%s"
" ORDER BY MchCod",
Game->GamCod,
@ -294,10 +294,10 @@ static void Mch_GetDataOfMatchByCod (struct Match *Match)
"UNIX_TIMESTAMP(QstStartTime)," // row[ 8]
"ShowResults," // row[ 9]
"Showing" // row[10]
" FROM gam_matches"
" FROM mch_matches"
" WHERE MchCod=%ld"
" AND GamCod IN" // Extra check
" (SELECT GamCod FROM games"
" (SELECT GamCod FROM gam_games"
" WHERE CrsCod='%ld')",
Match->MchCod,
Gbl.Hierarchy.Crs.CrsCod);
@ -527,9 +527,9 @@ static void Mch_GetAndWriteNamesOfGrpsAssociatedToMatch (struct Match *Match)
/***** Get groups associated to a match from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get groups of a match",
"SELECT crs_grp_types.GrpTypName,crs_grp.GrpName"
" FROM gam_grp,crs_grp,crs_grp_types"
" WHERE gam_grp.MchCod=%ld"
" AND gam_grp.GrpCod=crs_grp.GrpCod"
" FROM mch_groups,crs_grp,crs_grp_types"
" WHERE mch_groups.MchCod=%ld"
" AND mch_groups.GrpCod=crs_grp.GrpCod"
" AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod"
" ORDER BY crs_grp_types.GrpTypName,crs_grp.GrpName",
Match->MchCod);
@ -716,51 +716,51 @@ void Mch_RemoveMatchTch (void)
/***** Remove the match from all the tables *****/
/* Remove match players */
DB_QueryDELETE ("can not remove match players",
"DELETE FROM gam_players"
" USING gam_players,gam_matches,games"
" WHERE gam_players.MchCod=%ld"
" AND gam_players.MchCod=gam_matches.MchCod"
" AND gam_matches.GamCod=games.GamCod"
" AND games.CrsCod=%ld", // Extra check
"DELETE FROM mch_players"
" USING mch_players,mch_matches,gam_games"
" WHERE mch_players.MchCod=%ld"
" AND mch_players.MchCod=mch_matches.MchCod"
" AND mch_matches.GamCod=gam_games.GamCod"
" AND gam_games.CrsCod=%ld", // Extra check
Match.MchCod,Gbl.Hierarchy.Crs.CrsCod);
/* Remove match from list of matches being played */
DB_QueryDELETE ("can not remove match from matches being played",
"DELETE FROM gam_mch_being_played"
" USING gam_mch_being_played,gam_matches,games"
" WHERE gam_mch_being_played.MchCod=%ld"
" AND gam_mch_being_played.MchCod=gam_matches.MchCod"
" AND gam_matches.GamCod=games.GamCod"
" AND games.CrsCod=%ld", // Extra check
"DELETE FROM mch_playing"
" USING mch_playing,mch_matches,gam_games"
" WHERE mch_playing.MchCod=%ld"
" AND mch_playing.MchCod=mch_matches.MchCod"
" AND mch_matches.GamCod=gam_games.GamCod"
" AND gam_games.CrsCod=%ld", // Extra check
Match.MchCod,Gbl.Hierarchy.Crs.CrsCod);
/* Remove students' answers to match */
DB_QueryDELETE ("can not remove students' answers associated to a match",
"DELETE FROM gam_answers"
" USING gam_answers,gam_matches,games"
" WHERE gam_answers.MchCod=%ld"
" AND gam_answers.MchCod=gam_matches.MchCod"
" AND gam_matches.GamCod=games.GamCod"
" AND games.CrsCod=%ld", // Extra check
"DELETE FROM mch_answers"
" USING mch_answers,mch_matches,gam_games"
" WHERE mch_answers.MchCod=%ld"
" AND mch_answers.MchCod=mch_matches.MchCod"
" AND mch_matches.GamCod=gam_games.GamCod"
" AND gam_games.CrsCod=%ld", // Extra check
Match.MchCod,Gbl.Hierarchy.Crs.CrsCod);
/* Remove groups associated to the match */
DB_QueryDELETE ("can not remove the groups associated to a match",
"DELETE FROM gam_grp"
" USING gam_grp,gam_matches,games"
" WHERE gam_grp.MchCod=%ld"
" AND gam_grp.MchCod=gam_matches.MchCod"
" AND gam_matches.GamCod=games.GamCod"
" AND games.CrsCod=%ld", // Extra check
"DELETE FROM mch_groups"
" USING mch_groups,mch_matches,gam_games"
" WHERE mch_groups.MchCod=%ld"
" AND mch_groups.MchCod=mch_matches.MchCod"
" AND mch_matches.GamCod=gam_games.GamCod"
" AND gam_games.CrsCod=%ld", // Extra check
Match.MchCod,Gbl.Hierarchy.Crs.CrsCod);
/* Remove the match itself */
DB_QueryDELETE ("can not remove a match",
"DELETE FROM gam_matches"
" USING gam_matches,games"
" WHERE gam_matches.MchCod=%ld"
" AND gam_matches.GamCod=games.GamCod"
" AND games.CrsCod=%ld", // Extra check
"DELETE FROM mch_matches"
" USING mch_matches,gam_games"
" WHERE mch_matches.MchCod=%ld"
" AND mch_matches.GamCod=gam_games.GamCod"
" AND gam_games.CrsCod=%ld", // Extra check
Match.MchCod,Gbl.Hierarchy.Crs.CrsCod);
if (!mysql_affected_rows (&Gbl.mysql))
Lay_ShowErrorAndExit ("The match to be removed does not exist.");
@ -1004,7 +1004,7 @@ static long Mch_CreateMatch (long GamCod,char Title[Gam_MAX_BYTES_TITLE + 1])
/***** Insert this new match into database *****/
MchCod = DB_QueryINSERTandReturnCode ("can not create match",
"INSERT gam_matches"
"INSERT mch_matches"
" (GamCod,UsrCod,StartTime,EndTime,Title,ShowResults,"
"QstInd,QstCod,QstStartTime,Showing)"
" VALUES"
@ -1044,7 +1044,7 @@ static void Mch_CreateGrps (long MchCod)
NumGrpSel++)
/* Create group */
DB_QueryINSERT ("can not associate a group to a match",
"INSERT INTO gam_grp"
"INSERT INTO mch_groups"
" (MchCod,GrpCod)"
" VALUES"
" (%ld,%ld)",
@ -1059,16 +1059,16 @@ static void Mch_UpdateMatchStatusInDB (struct Match *Match)
{
/***** Update match status in database *****/
DB_QueryUPDATE ("can not update match being played",
"UPDATE gam_matches,games"
" SET gam_matches.EndTime=NOW(),"
"gam_matches.QstInd=%u,"
"gam_matches.QstCod=%ld,"
"gam_matches.QstStartTime=NOW(),"
"gam_matches.ShowResults='%c',"
"gam_matches.Showing='%s'"
" WHERE gam_matches.MchCod=%ld"
" AND gam_matches.GamCod=games.GamCod"
" AND games.CrsCod=%ld", // Extra check
"UPDATE mch_matches,gam_games"
" SET mch_matches.EndTime=NOW(),"
"mch_matches.QstInd=%u,"
"mch_matches.QstCod=%ld,"
"mch_matches.QstStartTime=NOW(),"
"mch_matches.ShowResults='%c',"
"mch_matches.Showing='%s'"
" WHERE mch_matches.MchCod=%ld"
" AND mch_matches.GamCod=gam_games.GamCod"
" AND gam_games.CrsCod=%ld", // Extra check
Match->Status.QstInd,Match->Status.QstCod,
Match->Status.ShowResults ? 'Y' : 'N',
Mch_ShowingStringsDB[Match->Status.Showing],
@ -1093,7 +1093,7 @@ static void Mch_UpdateElapsedTimeInQuestion (struct Match *Match)
Match->Status.QstInd > 0 &&
Match->Status.QstInd < Mch_AFTER_LAST_QUESTION)
DB_QueryINSERT ("can not update elapsed time in question",
"INSERT INTO gam_time (MchCod,QstInd,ElapsedTime)"
"INSERT INTO mch_times (MchCod,QstInd,ElapsedTime)"
" VALUES (%ld,%u,SEC_TO_TIME(%u))"
" ON DUPLICATE KEY"
" UPDATE ElapsedTime=ADDTIME(ElapsedTime,SEC_TO_TIME(%u))",
@ -1115,7 +1115,7 @@ static void Mch_GetElapsedTimeInQuestion (struct Match *Match,
/***** Query database *****/
NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get elapsed time",
"SELECT ElapsedTime"
" FROM gam_time"
" FROM mch_times"
" WHERE MchCod=%ld AND QstInd=%u",
Match->MchCod,Match->Status.QstInd);
@ -1139,7 +1139,7 @@ static void Mch_GetElapsedTimeInMatch (struct Match *Match,
/***** Query database *****/
NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get elapsed time",
"SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(ElapsedTime)))"
" FROM gam_time WHERE MchCod=%ld",
" FROM mch_times WHERE MchCod=%ld",
Match->MchCod);
/***** Get elapsed time from query result *****/
@ -1480,12 +1480,12 @@ static bool Mch_CheckIfIPlayThisMatchBasedOnGrps (long MchCod)
{
/***** Get if I can play a match from database *****/
return (DB_QueryCOUNT ("can not check if I can play a match",
"SELECT COUNT(*) FROM gam_matches"
"SELECT COUNT(*) FROM mch_matches"
" WHERE MchCod=%ld"
" AND (MchCod NOT IN (SELECT MchCod FROM gam_grp) OR"
" MchCod IN (SELECT gam_grp.MchCod FROM gam_grp,crs_grp_usr"
" AND (MchCod NOT IN (SELECT MchCod FROM mch_groups) OR"
" MchCod IN (SELECT mch_groups.MchCod FROM mch_groups,crs_grp_usr"
" WHERE crs_grp_usr.UsrCod=%ld"
" AND gam_grp.GrpCod=crs_grp_usr.GrpCod))",
" AND mch_groups.GrpCod=crs_grp_usr.GrpCod))",
MchCod,Gbl.Usrs.Me.UsrDat.UsrCod) != 0);
}
@ -2011,13 +2011,13 @@ static void Mch_RemoveOldPlayers (void)
{
/***** Delete matches not being played *****/
DB_QueryDELETE ("can not update matches as not being played",
"DELETE FROM gam_mch_being_played"
"DELETE FROM mch_playing"
" WHERE TS<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)",
Cfg_SECONDS_TO_REFRESH_GAME*3);
/***** Delete players who have left matches *****/
DB_QueryDELETE ("can not update match players",
"DELETE FROM gam_players"
"DELETE FROM mch_players"
" WHERE TS<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)",
Cfg_SECONDS_TO_REFRESH_GAME*3);
}
@ -2026,7 +2026,7 @@ static void Mch_UpdateMatchAsBeingPlayed (long MchCod)
{
/***** Insert match as being played *****/
DB_QueryREPLACE ("can not set match as being played",
"REPLACE gam_mch_being_played (MchCod) VALUE (%ld)",
"REPLACE mch_playing (MchCod) VALUE (%ld)",
MchCod);
}
@ -2034,13 +2034,13 @@ static void Mch_SetMatchAsNotBeingPlayed (long MchCod)
{
/***** Delete all match players ******/
DB_QueryDELETE ("can not update match players",
"DELETE FROM gam_players"
"DELETE FROM mch_players"
" WHERE MchCod=%ld",
MchCod);
/***** Delete match as being played ******/
DB_QueryDELETE ("can not set match as not being played",
"DELETE FROM gam_mch_being_played"
"DELETE FROM mch_playing"
" WHERE MchCod=%ld",
MchCod);
}
@ -2050,7 +2050,7 @@ static bool Mch_GetIfMatchIsBeingPlayed (long MchCod)
/***** Get if a match is being played or not *****/
return
(bool) (DB_QueryCOUNT ("can not get if match is being played",
"SELECT COUNT(*) FROM gam_mch_being_played"
"SELECT COUNT(*) FROM mch_playing"
" WHERE MchCod=%ld",
MchCod) != 0);
}
@ -2059,17 +2059,18 @@ static void Mch_RegisterMeAsPlayerInMatch (long MchCod)
{
/***** Insert me as match player *****/
DB_QueryREPLACE ("can not insert match player",
"REPLACE gam_players (MchCod,UsrCod) VALUES (%ld,%ld)",
"REPLACE mch_players (MchCod,UsrCod) VALUES (%ld,%ld)",
MchCod,Gbl.Usrs.Me.UsrDat.UsrCod);
}
static void Mch_GetNumPlayers (struct Match *Match)
{
/***** Get number of players who are playing a match *****/
Match->Status.NumPlayers = (unsigned) DB_QueryCOUNT ("can not get number of players",
"SELECT COUNT(*) FROM gam_players"
" WHERE MchCod=%ld",
Match->MchCod);
Match->Status.NumPlayers =
(unsigned) DB_QueryCOUNT ("can not get number of players",
"SELECT COUNT(*) FROM mch_players"
" WHERE MchCod=%ld",
Match->MchCod);
}
/*****************************************************************************/
@ -2179,7 +2180,7 @@ static int Mch_GetQstAnsFromDB (long MchCod,unsigned QstInd)
/***** Get student's answer *****/
NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get student's answer to a match question",
"SELECT AnsInd FROM gam_answers"
"SELECT AnsInd FROM mch_answers"
" WHERE MchCod=%ld AND UsrCod=%ld AND QstInd=%u",
MchCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
@ -2243,12 +2244,12 @@ void Mch_ReceiveQstAnsFromStd (void)
/***** Store student's answer *****/
if (PreviousStdAnsInd == (int) StdAnsInd)
DB_QueryDELETE ("can not register your answer to the match question",
"DELETE FROM gam_answers"
"DELETE FROM mch_answers"
" WHERE MchCod=%ld AND UsrCod=%ld AND QstInd=%u",
Match.MchCod,Gbl.Usrs.Me.UsrDat.UsrCod,QstInd);
else
DB_QueryREPLACE ("can not register your answer to the match question",
"REPLACE gam_answers"
"REPLACE mch_answers"
" (MchCod,UsrCod,QstInd,AnsInd)"
" VALUES"
" (%ld,%ld,%u,%u)",
@ -2287,7 +2288,7 @@ unsigned Mch_GetNumUsrsWhoHaveAnswerQst (long MchCod,unsigned QstInd)
a question in a match from database *****/
return
(unsigned) DB_QueryCOUNT ("can not get number of users who hasve answered a question",
"SELECT COUNT(*) FROM gam_answers"
"SELECT COUNT(*) FROM mch_answers"
" WHERE MchCod=%ld AND QstInd=%u",
MchCod,QstInd);
}
@ -2302,7 +2303,7 @@ static unsigned Mch_GetNumUsrsWhoHaveChosenAns (long MchCod,unsigned QstInd,unsi
an answer of a question from database *****/
return
(unsigned) DB_QueryCOUNT ("can not get number of users who have chosen an answer",
"SELECT COUNT(*) FROM gam_answers"
"SELECT COUNT(*) FROM mch_answers"
" WHERE MchCod=%ld AND QstInd=%u AND AnsInd=%u",
MchCod,QstInd,AnsInd);
}