Version 18.11.15

This commit is contained in:
Antonio Cañas Vargas 2018-11-02 01:23:05 +01:00
parent a86d7ce36d
commit 5673416716
5 changed files with 674 additions and 575 deletions

View File

@ -355,10 +355,11 @@ En OpenSWAD:
ps2pdf source.ps destination.pdf ps2pdf source.ps destination.pdf
*/ */
#define Log_PLATFORM_VERSION "SWAD 18.11.14 (2018-11-01)" #define Log_PLATFORM_VERSION "SWAD 18.11.15 (2018-11-02)"
#define CSS_FILE "swad18.4.css" #define CSS_FILE "swad18.4.css"
#define JS_FILE "swad17.17.1.js" #define JS_FILE "swad17.17.1.js"
/* /*
Version 18.11.15: Nov 02, 2018 Joining building and performing query into one function. (236312 lines)
Version 18.11.14: Nov 01, 2018 Joining building and performing query into one function. (236211 lines) Version 18.11.14: Nov 01, 2018 Joining building and performing query into one function. (236211 lines)
Version 18.11.13: Nov 01, 2018 Joining building and performing query into one function. (236011 lines) Version 18.11.13: Nov 01, 2018 Joining building and performing query into one function. (236011 lines)
Version 18.11.12: Nov 01, 2018 Joining building and performing query into one function. (235965 lines) Version 18.11.12: Nov 01, 2018 Joining building and performing query into one function. (235965 lines)

View File

@ -923,7 +923,7 @@ void Svy_GetListSurveys (void)
else else
SubQuery[Sco_SCOPE_CRS][0] = '\0'; SubQuery[Sco_SCOPE_CRS][0] = '\0';
/* Build query */ /* Make query */
if (SubQueryFilled) if (SubQueryFilled)
{ {
switch (Gbl.Svys.SelectedOrder) switch (Gbl.Svys.SelectedOrder)
@ -936,7 +936,8 @@ void Svy_GetListSurveys (void)
break; break;
} }
DB_BuildQuery ("SELECT SvyCod FROM surveys" NumRows = DB_QuerySELECT (&mysql_res,"can not get surveys",
"SELECT SvyCod FROM surveys"
" WHERE %s%s%s%s%s%s" " WHERE %s%s%s%s%s%s"
" ORDER BY %s", " ORDER BY %s",
SubQuery[Sco_SCOPE_SYS], SubQuery[Sco_SCOPE_SYS],
@ -948,10 +949,10 @@ void Svy_GetListSurveys (void)
OrderBySubQuery); OrderBySubQuery);
} }
else else
{
Lay_ShowErrorAndExit ("Can not get list of surveys."); Lay_ShowErrorAndExit ("Can not get list of surveys.");
NumRows = 0; // Not reached. Initialized to avoid warning
/* Make query */ }
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get surveys");
if (NumRows) // Surveys found... if (NumRows) // Surveys found...
{ {
@ -1158,8 +1159,9 @@ void Svy_GetDataOfSurveyByCod (struct Survey *Svy)
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows; unsigned long NumRows;
/***** Build query *****/ /***** Get data of survey from database *****/
DB_BuildQuery ("SELECT SvyCod,Scope,Cod,Hidden,Roles,UsrCod," NumRows = DB_QuerySELECT (&mysql_res,"can not get survey data",
"SELECT SvyCod,Scope,Cod,Hidden,Roles,UsrCod,"
"UNIX_TIMESTAMP(StartTime)," "UNIX_TIMESTAMP(StartTime),"
"UNIX_TIMESTAMP(EndTime)," "UNIX_TIMESTAMP(EndTime),"
"NOW() BETWEEN StartTime AND EndTime," "NOW() BETWEEN StartTime AND EndTime,"
@ -1168,9 +1170,6 @@ void Svy_GetDataOfSurveyByCod (struct Survey *Svy)
" WHERE SvyCod=%ld", " WHERE SvyCod=%ld",
Svy->SvyCod); Svy->SvyCod);
/***** Get data of survey from database *****/
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get survey data");
if (NumRows) // Survey found... if (NumRows) // Survey found...
{ {
/* Get row */ /* Get row */
@ -1389,8 +1388,9 @@ static void Svy_GetSurveyTxtFromDB (long SvyCod,char Txt[Cns_MAX_BYTES_TEXT + 1]
unsigned long NumRows; unsigned long NumRows;
/***** Get text of survey from database *****/ /***** Get text of survey from database *****/
DB_BuildQuery ("SELECT Txt FROM surveys WHERE SvyCod=%ld",SvyCod); NumRows = DB_QuerySELECT (&mysql_res,"can not get survey text",
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get survey text"); "SELECT Txt FROM surveys WHERE SvyCod=%ld",
SvyCod);
/***** The result of the query must have one row or none *****/ /***** The result of the query must have one row or none *****/
if (NumRows == 1) if (NumRows == 1)
@ -2417,14 +2417,15 @@ static void Svy_GetAndWriteNamesOfGrpsAssociatedToSvy (struct Survey *Svy)
unsigned long NumRows; unsigned long NumRows;
/***** Get groups associated to a survey from database *****/ /***** Get groups associated to a survey from database *****/
DB_BuildQuery ("SELECT crs_grp_types.GrpTypName,crs_grp.GrpName" NumRows = DB_QuerySELECT (&mysql_res,"can not get groups of a survey",
"SELECT crs_grp_types.GrpTypName,crs_grp.GrpName"
" FROM svy_grp,crs_grp,crs_grp_types" " FROM svy_grp,crs_grp,crs_grp_types"
" WHERE svy_grp.SvyCod=%ld" " WHERE svy_grp.SvyCod=%ld"
" AND svy_grp.GrpCod=crs_grp.GrpCod" " AND svy_grp.GrpCod=crs_grp.GrpCod"
" AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod" " AND crs_grp.GrpTypCod=crs_grp_types.GrpTypCod"
" ORDER BY crs_grp_types.GrpTypName,crs_grp.GrpName", " ORDER BY crs_grp_types.GrpTypName,"
"crs_grp.GrpName",
Svy->SvyCod); Svy->SvyCod);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get groups of a survey");
/***** Write heading *****/ /***** Write heading *****/
fprintf (Gbl.F.Out,"<div class=\"%s\">%s: ", fprintf (Gbl.F.Out,"<div class=\"%s\">%s: ",
@ -2609,10 +2610,10 @@ static void Svy_ShowFormEditOneQst (long SvyCod,struct SurveyQuestion *SvyQst,
{ {
/***** Get the type of answer and the stem from the database *****/ /***** Get the type of answer and the stem from the database *****/
/* Get the question from database */ /* Get the question from database */
DB_BuildQuery ("SELECT QstInd,AnsType,Stem FROM svy_questions" DB_QuerySELECT (&mysql_res,"can not get a question",
"SELECT QstInd,AnsType,Stem FROM svy_questions"
" WHERE QstCod=%ld AND SvyCod=%ld", " WHERE QstCod=%ld AND SvyCod=%ld",
SvyQst->QstCod,SvyCod); SvyQst->QstCod,SvyCod);
DB_QuerySELECT_new (&mysql_res,"can not get a question");
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -2856,10 +2857,10 @@ static unsigned Svy_GetAnswersQst (long QstCod,MYSQL_RES **mysql_res)
unsigned long NumRows; unsigned long NumRows;
/***** Get answers of a question from database *****/ /***** Get answers of a question from database *****/
DB_BuildQuery ("SELECT AnsInd,NumUsrs,Answer FROM svy_answers" NumRows = DB_QuerySELECT (mysql_res,"can not get answers of a question",
"SELECT AnsInd,NumUsrs,Answer FROM svy_answers"
" WHERE QstCod=%ld ORDER BY AnsInd", " WHERE QstCod=%ld ORDER BY AnsInd",
QstCod); QstCod);
NumRows = DB_QuerySELECT_new (mysql_res,"can not get answers of a question");
/***** Count number of rows of result *****/ /***** Count number of rows of result *****/
if (NumRows == 0) if (NumRows == 0)
@ -3095,8 +3096,10 @@ static unsigned Svy_GetQstIndFromQstCod (long QstCod)
unsigned QstInd = 0; unsigned QstInd = 0;
/***** Get number of surveys with a field value from database *****/ /***** Get number of surveys with a field value from database *****/
DB_BuildQuery ("SELECT QstInd FROM svy_questions WHERE QstCod=%ld",QstCod); NumRows = DB_QuerySELECT (&mysql_res,"can not get question index",
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get question index"); "SELECT QstInd FROM svy_questions"
" WHERE QstCod=%ld",
QstCod);
/***** Get number of users *****/ /***** Get number of users *****/
if (NumRows) if (NumRows)
@ -3125,9 +3128,9 @@ static unsigned Svy_GetNextQuestionIndexInSvy (long SvyCod)
unsigned QstInd = 0; unsigned QstInd = 0;
/***** Get number of surveys with a field value from database *****/ /***** Get number of surveys with a field value from database *****/
DB_BuildQuery ("SELECT MAX(QstInd) FROM svy_questions WHERE SvyCod=%ld", DB_QuerySELECT (&mysql_res,"can not get last question index",
"SELECT MAX(QstInd) FROM svy_questions WHERE SvyCod=%ld",
SvyCod); SvyCod);
DB_QuerySELECT_new (&mysql_res,"can not get last question index");
/***** Get number of users *****/ /***** Get number of users *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3169,11 +3172,11 @@ static void Svy_ListSvyQuestions (struct Survey *Svy,
bool PutFormAnswerSurvey = Svy->Status.ICanAnswer && !Editing; bool PutFormAnswerSurvey = Svy->Status.ICanAnswer && !Editing;
/***** Get data of questions from database *****/ /***** Get data of questions from database *****/
DB_BuildQuery ("SELECT QstCod,QstInd,AnsType,Stem" NumQsts = (unsigned) DB_QuerySELECT (&mysql_res,"can not get data of a question",
"SELECT QstCod,QstInd,AnsType,Stem"
" FROM svy_questions" " FROM svy_questions"
" WHERE SvyCod=%ld ORDER BY QstInd", " WHERE SvyCod=%ld ORDER BY QstInd",
Svy->SvyCod); Svy->SvyCod);
NumQsts = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get data of a question");
/***** Start box *****/ /***** Start box *****/
Gbl.Svys.SvyCodToEdit = Svy->SvyCod; Gbl.Svys.SvyCodToEdit = Svy->SvyCod;
@ -3663,11 +3666,12 @@ static void Svy_ReceiveAndStoreUserAnswersToASurvey (long SvyCod)
unsigned AnsInd; unsigned AnsInd;
/***** Get questions of this survey from database *****/ /***** Get questions of this survey from database *****/
DB_BuildQuery ("SELECT QstCod FROM svy_questions" NumQsts = (unsigned) DB_QuerySELECT (&mysql_res,"can not get questions"
" of a survey",
"SELECT QstCod FROM svy_questions"
" WHERE SvyCod=%ld ORDER BY QstCod", " WHERE SvyCod=%ld ORDER BY QstCod",
SvyCod); SvyCod);
if ((NumQsts = (unsigned) DB_QuerySELECT_new (&mysql_res, if (NumQsts)
"can not get questions of a survey")))
{ {
// This survey has questions // This survey has questions
/***** Get questions *****/ /***** Get questions *****/
@ -3778,13 +3782,17 @@ unsigned Svy_GetNumCoursesWithCrsSurveys (Sco_Scope_t Scope)
switch (Scope) switch (Scope)
{ {
case Sco_SCOPE_SYS: case Sco_SCOPE_SYS:
DB_BuildQuery ("SELECT COUNT(DISTINCT Cod)" DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with surveys",
"SELECT COUNT(DISTINCT Cod)"
" FROM surveys" " FROM surveys"
" WHERE Scope='%s'", " WHERE Scope='%s'",
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
DB_BuildQuery ("SELECT COUNT(DISTINCT surveys.Cod)" DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with surveys",
"SELECT COUNT(DISTINCT surveys.Cod)"
" FROM institutions,centres,degrees,courses,surveys" " FROM institutions,centres,degrees,courses,surveys"
" WHERE institutions.CtyCod=%ld" " WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod" " AND institutions.InsCod=centres.InsCod"
@ -3796,7 +3804,9 @@ unsigned Svy_GetNumCoursesWithCrsSurveys (Sco_Scope_t Scope)
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT COUNT(DISTINCT surveys.Cod)" DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with surveys",
"SELECT COUNT(DISTINCT surveys.Cod)"
" FROM centres,degrees,courses,surveys" " FROM centres,degrees,courses,surveys"
" WHERE centres.InsCod=%ld" " WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod" " AND centres.CtrCod=degrees.CtrCod"
@ -3807,7 +3817,9 @@ unsigned Svy_GetNumCoursesWithCrsSurveys (Sco_Scope_t Scope)
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
DB_BuildQuery ("SELECT COUNT(DISTINCT surveys.Cod)" DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with surveys",
"SELECT COUNT(DISTINCT surveys.Cod)"
" FROM degrees,courses,surveys" " FROM degrees,courses,surveys"
" WHERE degrees.CtrCod=%ld" " WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod" " AND degrees.DegCod=courses.DegCod"
@ -3817,7 +3829,9 @@ unsigned Svy_GetNumCoursesWithCrsSurveys (Sco_Scope_t Scope)
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
DB_BuildQuery ("SELECT COUNT(DISTINCT surveys.Cod)" DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with surveys",
"SELECT COUNT(DISTINCT surveys.Cod)"
" FROM courses,surveys" " FROM courses,surveys"
" WHERE courses.DegCod=%ld" " WHERE courses.DegCod=%ld"
" AND courses.CrsCod=surveys.Cod" " AND courses.CrsCod=surveys.Cod"
@ -3826,7 +3840,9 @@ unsigned Svy_GetNumCoursesWithCrsSurveys (Sco_Scope_t Scope)
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT COUNT(DISTINCT Cod)" DB_QuerySELECT (&mysql_res,"can not get number of courses"
" with surveys",
"SELECT COUNT(DISTINCT Cod)"
" FROM surveys" " FROM surveys"
" WHERE Scope='%s' AND Cod=%ld", " WHERE Scope='%s' AND Cod=%ld",
Sco_ScopeDB[Sco_SCOPE_CRS], Sco_ScopeDB[Sco_SCOPE_CRS],
@ -3836,7 +3852,6 @@ unsigned Svy_GetNumCoursesWithCrsSurveys (Sco_Scope_t Scope)
Lay_WrongScopeExit (); Lay_WrongScopeExit ();
break; break;
} }
DB_QuerySELECT_new (&mysql_res,"can not get number of courses with surveys");
/***** Get number of surveys *****/ /***** Get number of surveys *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3866,13 +3881,15 @@ unsigned Svy_GetNumCrsSurveys (Sco_Scope_t Scope,unsigned *NumNotif)
switch (Scope) switch (Scope)
{ {
case Sco_SCOPE_SYS: case Sco_SCOPE_SYS:
DB_BuildQuery ("SELECT COUNT(*),SUM(NumNotif)" DB_QuerySELECT (&mysql_res,"can not get number of surveys",
"SELECT COUNT(*),SUM(NumNotif)"
" FROM surveys" " FROM surveys"
" WHERE Scope='%s'", " WHERE Scope='%s'",
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
DB_BuildQuery ("SELECT COUNT(*),SUM(surveys.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get number of surveys",
"SELECT COUNT(*),SUM(surveys.NumNotif)"
" FROM institutions,centres,degrees,courses,surveys" " FROM institutions,centres,degrees,courses,surveys"
" WHERE institutions.CtyCod=%ld" " WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod" " AND institutions.InsCod=centres.InsCod"
@ -3884,7 +3901,8 @@ unsigned Svy_GetNumCrsSurveys (Sco_Scope_t Scope,unsigned *NumNotif)
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT COUNT(*),SUM(surveys.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get number of surveys",
"SELECT COUNT(*),SUM(surveys.NumNotif)"
" FROM centres,degrees,courses,surveys" " FROM centres,degrees,courses,surveys"
" WHERE centres.InsCod=%ld" " WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod" " AND centres.CtrCod=degrees.CtrCod"
@ -3895,7 +3913,8 @@ unsigned Svy_GetNumCrsSurveys (Sco_Scope_t Scope,unsigned *NumNotif)
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
DB_BuildQuery ("SELECT COUNT(*),SUM(surveys.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get number of surveys",
"SELECT COUNT(*),SUM(surveys.NumNotif)"
" FROM degrees,courses,surveys" " FROM degrees,courses,surveys"
" WHERE degrees.CtrCod=%ld" " WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod" " AND degrees.DegCod=courses.DegCod"
@ -3905,7 +3924,8 @@ unsigned Svy_GetNumCrsSurveys (Sco_Scope_t Scope,unsigned *NumNotif)
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
DB_BuildQuery ("SELECT COUNT(*),SUM(surveys.NumNotif)" DB_QuerySELECT (&mysql_res,"can not get number of surveys",
"SELECT COUNT(*),SUM(surveys.NumNotif)"
" FROM courses,surveys" " FROM courses,surveys"
" WHERE courses.DegCod=%ld" " WHERE courses.DegCod=%ld"
" AND courses.CrsCod=surveys.Cod" " AND courses.CrsCod=surveys.Cod"
@ -3914,7 +3934,8 @@ unsigned Svy_GetNumCrsSurveys (Sco_Scope_t Scope,unsigned *NumNotif)
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT COUNT(*),SUM(NumNotif)" DB_QuerySELECT (&mysql_res,"can not get number of surveys",
"SELECT COUNT(*),SUM(NumNotif)"
" FROM surveys" " FROM surveys"
" WHERE surveys.Scope='%s'" " WHERE surveys.Scope='%s'"
" AND CrsCod=%ld", " AND CrsCod=%ld",
@ -3925,7 +3946,6 @@ unsigned Svy_GetNumCrsSurveys (Sco_Scope_t Scope,unsigned *NumNotif)
Lay_WrongScopeExit (); Lay_WrongScopeExit ();
break; break;
} }
DB_QuerySELECT_new (&mysql_res,"can not get number of surveys");
/***** Get number of surveys *****/ /***** Get number of surveys *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3962,7 +3982,9 @@ float Svy_GetNumQstsPerCrsSurvey (Sco_Scope_t Scope)
switch (Scope) switch (Scope)
{ {
case Sco_SCOPE_SYS: case Sco_SCOPE_SYS:
DB_BuildQuery ("SELECT AVG(NumQsts) FROM" DB_QuerySELECT (&mysql_res,"can not get number of questions"
" per survey",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts" " (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM surveys,svy_questions" " FROM surveys,svy_questions"
" WHERE surveys.Scope='%s'" " WHERE surveys.Scope='%s'"
@ -3971,7 +3993,9 @@ float Svy_GetNumQstsPerCrsSurvey (Sco_Scope_t Scope)
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CTY: case Sco_SCOPE_CTY:
DB_BuildQuery ("SELECT AVG(NumQsts) FROM" DB_QuerySELECT (&mysql_res,"can not get number of questions"
" per survey",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts" " (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM institutions,centres,degrees,courses,surveys,svy_questions" " FROM institutions,centres,degrees,courses,surveys,svy_questions"
" WHERE institutions.CtyCod=%ld" " WHERE institutions.CtyCod=%ld"
@ -3986,7 +4010,9 @@ float Svy_GetNumQstsPerCrsSurvey (Sco_Scope_t Scope)
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_INS: case Sco_SCOPE_INS:
DB_BuildQuery ("SELECT AVG(NumQsts) FROM" DB_QuerySELECT (&mysql_res,"can not get number of questions"
" per survey",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts" " (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM centres,degrees,courses,surveys,svy_questions" " FROM centres,degrees,courses,surveys,svy_questions"
" WHERE centres.InsCod=%ld" " WHERE centres.InsCod=%ld"
@ -4000,7 +4026,9 @@ float Svy_GetNumQstsPerCrsSurvey (Sco_Scope_t Scope)
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CTR: case Sco_SCOPE_CTR:
DB_BuildQuery ("SELECT AVG(NumQsts) FROM" DB_QuerySELECT (&mysql_res,"can not get number of questions"
" per survey",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts" " (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM degrees,courses,surveys,svy_questions" " FROM degrees,courses,surveys,svy_questions"
" WHERE degrees.CtrCod=%ld" " WHERE degrees.CtrCod=%ld"
@ -4013,7 +4041,9 @@ float Svy_GetNumQstsPerCrsSurvey (Sco_Scope_t Scope)
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_DEG: case Sco_SCOPE_DEG:
DB_BuildQuery ("SELECT AVG(NumQsts) FROM" DB_QuerySELECT (&mysql_res,"can not get number of questions"
" per survey",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts" " (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM courses,surveys,svy_questions" " FROM courses,surveys,svy_questions"
" WHERE courses.DegCod=%ld" " WHERE courses.DegCod=%ld"
@ -4025,7 +4055,9 @@ float Svy_GetNumQstsPerCrsSurvey (Sco_Scope_t Scope)
Sco_ScopeDB[Sco_SCOPE_CRS]); Sco_ScopeDB[Sco_SCOPE_CRS]);
break; break;
case Sco_SCOPE_CRS: case Sco_SCOPE_CRS:
DB_BuildQuery ("SELECT AVG(NumQsts) FROM" DB_QuerySELECT (&mysql_res,"can not get number of questions"
" per survey",
"SELECT AVG(NumQsts) FROM"
" (SELECT COUNT(svy_questions.QstCod) AS NumQsts" " (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM surveys,svy_questions" " FROM surveys,svy_questions"
" WHERE surveys.Scope='%s' AND surveys.Cod=%ld" " WHERE surveys.Scope='%s' AND surveys.Cod=%ld"
@ -4037,7 +4069,6 @@ float Svy_GetNumQstsPerCrsSurvey (Sco_Scope_t Scope)
Lay_WrongScopeExit (); Lay_WrongScopeExit ();
break; break;
} }
DB_QuerySELECT_new (&mysql_res,"can not get number of questions per survey");
/***** Get number of courses *****/ /***** Get number of courses *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);

View File

@ -730,12 +730,14 @@ static bool TsI_CheckIfQuestionExistsInDB (void)
unsigned i; unsigned i;
/***** Check if stem exists *****/ /***** Check if stem exists *****/
DB_BuildQuery ("SELECT QstCod FROM tst_questions" NumQstsWithThisStem =
(unsigned) DB_QuerySELECT (&mysql_res_qst,"can not check"
" if a question exists",
"SELECT QstCod FROM tst_questions"
" WHERE CrsCod=%ld AND AnsType='%s' AND Stem='%s'", " WHERE CrsCod=%ld AND AnsType='%s' AND Stem='%s'",
Gbl.CurrentCrs.Crs.CrsCod, Gbl.CurrentCrs.Crs.CrsCod,
Tst_StrAnswerTypesDB[Gbl.Test.AnswerType], Tst_StrAnswerTypesDB[Gbl.Test.AnswerType],
Gbl.Test.Stem.Text); Gbl.Test.Stem.Text);
NumQstsWithThisStem = (unsigned) DB_QuerySELECT_new (&mysql_res_qst,"can not check if a question exists");
if (NumQstsWithThisStem) // There are questions in database with the same stem that the one of this question if (NumQstsWithThisStem) // There are questions in database with the same stem that the one of this question
{ {
@ -750,10 +752,12 @@ static bool TsI_CheckIfQuestionExistsInDB (void)
Lay_ShowErrorAndExit ("Wrong code of question."); Lay_ShowErrorAndExit ("Wrong code of question.");
/* Get answers from this question */ /* Get answers from this question */
DB_BuildQuery ("SELECT Answer FROM tst_answers" NumOptsExistingQstInDB =
(unsigned) DB_QuerySELECT (&mysql_res_ans,"can not get the answer"
" of a question",
"SELECT Answer FROM tst_answers"
" WHERE QstCod=%ld ORDER BY AnsInd", " WHERE QstCod=%ld ORDER BY AnsInd",
QstCod); QstCod);
NumOptsExistingQstInDB = (unsigned) DB_QuerySELECT_new (&mysql_res_ans,"can not get the answer of a question");
switch (Gbl.Test.AnswerType) switch (Gbl.Test.AnswerType)
{ {

View File

@ -657,8 +657,8 @@ static void TT_FillTimeTableFromDB (long UsrCod)
extern const char *Txt_Incomplete_timetable_for_lack_of_space; extern const char *Txt_Incomplete_timetable_for_lack_of_space;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows = 0; // Initialized to avoid warning
unsigned long NumRow; unsigned long NumRow;
unsigned long NumRows;
unsigned Weekday; unsigned Weekday;
unsigned Interval; unsigned Interval;
unsigned i; // To iterate through intervals unsigned i; // To iterate through intervals
@ -682,8 +682,8 @@ static void TT_FillTimeTableFromDB (long UsrCod)
switch (Gbl.CurrentCrs.Grps.WhichGrps) switch (Gbl.CurrentCrs.Grps.WhichGrps)
{ {
case Grp_ONLY_MY_GROUPS: case Grp_ONLY_MY_GROUPS:
DB_BuildQuery ("SELECT " NumRows = DB_QuerySELECT (&mysql_res,"can not get timetable",
"timetable_crs.Weekday," "SELECT timetable_crs.Weekday,"
"TIME_TO_SEC(timetable_crs.StartTime) AS S," "TIME_TO_SEC(timetable_crs.StartTime) AS S,"
"TIME_TO_SEC(timetable_crs.Duration) AS D," "TIME_TO_SEC(timetable_crs.Duration) AS D,"
"timetable_crs.Place," "timetable_crs.Place,"
@ -696,8 +696,7 @@ static void TT_FillTimeTableFromDB (long UsrCod)
" AND timetable_crs.GrpCod=-1" " AND timetable_crs.GrpCod=-1"
" AND timetable_crs.CrsCod=crs_usr.CrsCod" " AND timetable_crs.CrsCod=crs_usr.CrsCod"
" UNION DISTINCT " " UNION DISTINCT "
"SELECT " "SELECT timetable_crs.Weekday,"
"timetable_crs.Weekday,"
"TIME_TO_SEC(timetable_crs.StartTime) AS S," "TIME_TO_SEC(timetable_crs.StartTime) AS S,"
"TIME_TO_SEC(timetable_crs.Duration) AS D," "TIME_TO_SEC(timetable_crs.Duration) AS D,"
"timetable_crs.Place," "timetable_crs.Place,"
@ -709,8 +708,7 @@ static void TT_FillTimeTableFromDB (long UsrCod)
" WHERE crs_grp_usr.UsrCod=%ld" " WHERE crs_grp_usr.UsrCod=%ld"
" AND timetable_crs.GrpCod=crs_grp_usr.GrpCod" " AND timetable_crs.GrpCod=crs_grp_usr.GrpCod"
" UNION " " UNION "
"SELECT " "SELECT Weekday,"
"Weekday,"
"TIME_TO_SEC(StartTime) AS S," "TIME_TO_SEC(StartTime) AS S,"
"TIME_TO_SEC(Duration) AS D," "TIME_TO_SEC(Duration) AS D,"
"Place," "Place,"
@ -725,8 +723,8 @@ static void TT_FillTimeTableFromDB (long UsrCod)
UsrCod,UsrCod,UsrCod); UsrCod,UsrCod,UsrCod);
break; break;
case Grp_ALL_GROUPS: case Grp_ALL_GROUPS:
DB_BuildQuery ("SELECT " NumRows = DB_QuerySELECT (&mysql_res,"can not get timetable",
"timetable_crs.Weekday," "SELECT timetable_crs.Weekday,"
"TIME_TO_SEC(timetable_crs.StartTime) AS S," "TIME_TO_SEC(timetable_crs.StartTime) AS S,"
"TIME_TO_SEC(timetable_crs.Duration) AS D," "TIME_TO_SEC(timetable_crs.Duration) AS D,"
"timetable_crs.Place," "timetable_crs.Place,"
@ -738,8 +736,7 @@ static void TT_FillTimeTableFromDB (long UsrCod)
" WHERE crs_usr.UsrCod=%ld" " WHERE crs_usr.UsrCod=%ld"
" AND timetable_crs.CrsCod=crs_usr.CrsCod" " AND timetable_crs.CrsCod=crs_usr.CrsCod"
" UNION " " UNION "
"SELECT " "SELECT Weekday,"
"Weekday,"
"TIME_TO_SEC(StartTime) AS S," "TIME_TO_SEC(StartTime) AS S,"
"TIME_TO_SEC(Duration) AS D," "TIME_TO_SEC(Duration) AS D,"
"Place," "Place,"
@ -759,8 +756,8 @@ static void TT_FillTimeTableFromDB (long UsrCod)
if (Gbl.CurrentCrs.Grps.WhichGrps == Grp_ALL_GROUPS || if (Gbl.CurrentCrs.Grps.WhichGrps == Grp_ALL_GROUPS ||
Gbl.Action.Act == ActEdiCrsTT || Gbl.Action.Act == ActEdiCrsTT ||
Gbl.Action.Act == ActChgCrsTT) // If we are editing, all groups are shown Gbl.Action.Act == ActChgCrsTT) // If we are editing, all groups are shown
DB_BuildQuery ("SELECT " NumRows = DB_QuerySELECT (&mysql_res,"can not get timetable",
"Weekday," "SELECT Weekday,"
"TIME_TO_SEC(StartTime) AS S," "TIME_TO_SEC(StartTime) AS S,"
"TIME_TO_SEC(Duration) AS D," "TIME_TO_SEC(Duration) AS D,"
"Place," "Place,"
@ -773,8 +770,8 @@ static void TT_FillTimeTableFromDB (long UsrCod)
"GroupName,GrpCod,Place,D DESC", "GroupName,GrpCod,Place,D DESC",
Gbl.CurrentCrs.Crs.CrsCod); Gbl.CurrentCrs.Crs.CrsCod);
else else
DB_BuildQuery ("SELECT " NumRows = DB_QuerySELECT (&mysql_res,"can not get timetable",
"timetable_crs.Weekday," "SELECT timetable_crs.Weekday,"
"TIME_TO_SEC(timetable_crs.StartTime) AS S," "TIME_TO_SEC(timetable_crs.StartTime) AS S,"
"TIME_TO_SEC(timetable_crs.Duration) AS D," "TIME_TO_SEC(timetable_crs.Duration) AS D,"
"timetable_crs.Place," "timetable_crs.Place,"
@ -803,8 +800,8 @@ static void TT_FillTimeTableFromDB (long UsrCod)
Gbl.CurrentCrs.Crs.CrsCod,UsrCod); Gbl.CurrentCrs.Crs.CrsCod,UsrCod);
break; break;
case TT_TUTORING_TIMETABLE: case TT_TUTORING_TIMETABLE:
DB_BuildQuery ("SELECT " NumRows = DB_QuerySELECT (&mysql_res,"can not get timetable",
"Weekday," "SELECT Weekday,"
"TIME_TO_SEC(StartTime) AS S," "TIME_TO_SEC(StartTime) AS S,"
"TIME_TO_SEC(Duration) AS D," "TIME_TO_SEC(Duration) AS D,"
"Place" "Place"
@ -814,7 +811,6 @@ static void TT_FillTimeTableFromDB (long UsrCod)
UsrCod); UsrCod);
break; break;
} }
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get timetable");
/***** If viewing (not editing) ==> /***** If viewing (not editing) ==>
calculate range of hours and resolution *****/ calculate range of hours and resolution *****/

View File

@ -288,8 +288,9 @@ static int Svc_GetPlgCodFromAppKey (const char *appKey)
Gbl.WebService.PlgCod = -1L; Gbl.WebService.PlgCod = -1L;
/***** Get number of plugins with a IP address *****/ /***** Get number of plugins with a IP address *****/
DB_BuildQuery ("SELECT PlgCod FROM plugins WHERE AppKey='%s'",appKey); if (DB_QuerySELECT (&mysql_res,"can not check application key",
if (DB_QuerySELECT_new (&mysql_res,"can not check application key")) // Session found in table of sessions "SELECT PlgCod FROM plugins WHERE AppKey='%s'",
appKey)) // Session found in table of sessions
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -381,8 +382,9 @@ static int Svc_CheckWSKey (char WSKey[Svc_BYTES_WS_KEY + 1])
Gbl.WebService.PlgCod = -1L; Gbl.WebService.PlgCod = -1L;
/***** Check that key does not exist in database *****/ /***** Check that key does not exist in database *****/
DB_BuildQuery ("SELECT UsrCod,PlgCod FROM ws_keys WHERE WSKey='%s'",WSKey); if (DB_QuerySELECT (&mysql_res,"can not get existence of key",
if (DB_QuerySELECT_new (&mysql_res,"can not get existence of key")) // Session found in table of sessions "SELECT UsrCod,PlgCod FROM ws_keys WHERE WSKey='%s'",
WSKey)) // Session found in table of sessions
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -504,9 +506,9 @@ static int Svc_GetCurrentDegCodFromCurrentCrsCod (void)
Gbl.CurrentDeg.Deg.DegCod = -1L; Gbl.CurrentDeg.Deg.DegCod = -1L;
/***** Check that key does not exist in database *****/ /***** Check that key does not exist in database *****/
DB_BuildQuery ("SELECT DegCod FROM courses WHERE CrsCod=%ld", if (DB_QuerySELECT (&mysql_res,"can not get the degree of a course",
Gbl.CurrentCrs.Crs.CrsCod); "SELECT DegCod FROM courses WHERE CrsCod=%ld",
if (DB_QuerySELECT_new (&mysql_res,"can not get the degree of a course")) // Course found in table of courses Gbl.CurrentCrs.Crs.CrsCod)) // Course found in table of courses
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -534,13 +536,10 @@ static bool Svc_GetSomeUsrDataFromUsrCod (struct UsrData *UsrDat,long CrsCod)
return false; return false;
/***** Get some user's data *****/ /***** Get some user's data *****/
/* Query database */ if (DB_QuerySELECT (&mysql_res,"can not get user's data",
DB_BuildQuery ("SELECT Surname1,Surname2,FirstName,Photo,DATE_FORMAT(Birthday,'%%Y%%m%%d')" "SELECT Surname1,Surname2,FirstName,Photo,DATE_FORMAT(Birthday,'%%Y%%m%%d')"
" FROM usr_data WHERE UsrCod=%ld", " FROM usr_data WHERE UsrCod=%ld",
UsrDat->UsrCod); UsrDat->UsrCod) != 1)
/* Check number of rows in result */
if (DB_QuerySELECT_new (&mysql_res,"can not get user's data") != 1)
return false; return false;
/* Read some user's data */ /* Read some user's data */
@ -575,10 +574,10 @@ static bool Svc_GetSomeUsrDataFromUsrCod (struct UsrData *UsrDat,long CrsCod)
if (CrsCod > 0) if (CrsCod > 0)
{ {
/* Get the role in the given course */ /* Get the role in the given course */
DB_BuildQuery ("SELECT Role FROM crs_usr" if (DB_QuerySELECT (&mysql_res,"can not get user's role",
"SELECT Role FROM crs_usr"
" WHERE CrsCod=%ld AND UsrCod=%ld", " WHERE CrsCod=%ld AND UsrCod=%ld",
CrsCod,UsrDat->UsrCod); CrsCod,UsrDat->UsrCod)) // User belongs to course
if (DB_QuerySELECT_new (&mysql_res,"can not get user's role")) // User belongs to course
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
if (row[0]) if (row[0])
@ -606,10 +605,10 @@ static bool Svc_GetSomeUsrDataFromUsrCod (struct UsrData *UsrDat,long CrsCod)
else else
{ {
/* Get the maximum role in any course */ /* Get the maximum role in any course */
DB_BuildQuery ("SELECT MAX(Role)" if (DB_QuerySELECT (&mysql_res,"can not get user's role",
"SELECT MAX(Role)"
" FROM crs_usr WHERE UsrCod=%ld", " FROM crs_usr WHERE UsrCod=%ld",
UsrDat->UsrCod); UsrDat->UsrCod) == 1)
if (DB_QuerySELECT_new (&mysql_res,"can not get user's role") == 1)
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
if (row[0]) if (row[0])
@ -827,7 +826,9 @@ int swad__loginByUserPasswordKey (struct soap *soap,
Str_RemoveLeadingArrobas (UsrIDNickOrEmail); Str_RemoveLeadingArrobas (UsrIDNickOrEmail);
/* User has typed a nickname */ /* User has typed a nickname */
DB_BuildQuery ("SELECT usr_nicknames.UsrCod" NumRows =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get user's data",
"SELECT usr_nicknames.UsrCod"
" FROM usr_nicknames,usr_data" " FROM usr_nicknames,usr_data"
" WHERE usr_nicknames.Nickname='%s'" " WHERE usr_nicknames.Nickname='%s'"
" AND usr_nicknames.UsrCod=usr_data.UsrCod" " AND usr_nicknames.UsrCod=usr_data.UsrCod"
@ -838,7 +839,9 @@ int swad__loginByUserPasswordKey (struct soap *soap,
{ {
/* User has typed an email */ /* User has typed an email */
// TODO: Get only if email confirmed? // TODO: Get only if email confirmed?
DB_BuildQuery ("SELECT usr_emails.UsrCod" NumRows =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get user's data",
"SELECT usr_emails.UsrCod"
" FROM usr_emails,usr_data" " FROM usr_emails,usr_data"
" WHERE usr_emails.E_mail='%s'" " WHERE usr_emails.E_mail='%s'"
" AND usr_emails.UsrCod=usr_data.UsrCod" " AND usr_emails.UsrCod=usr_data.UsrCod"
@ -854,7 +857,10 @@ int swad__loginByUserPasswordKey (struct soap *soap,
{ {
/* User has typed a valid user's ID (existing or not) */ /* User has typed a valid user's ID (existing or not) */
// TODO: Get only if ID confirmed? // TODO: Get only if ID confirmed?
DB_BuildQuery ("SELECT usr_IDs.UsrCod FROM usr_IDs,usr_data" NumRows =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get user's data",
"SELECT usr_IDs.UsrCod"
" FROM usr_IDs,usr_data"
" WHERE usr_IDs.UsrID='%s'" " WHERE usr_IDs.UsrID='%s'"
" AND usr_IDs.UsrCod=usr_data.UsrCod" " AND usr_IDs.UsrCod=usr_data.UsrCod"
" AND usr_data.Password='%s'", " AND usr_data.Password='%s'",
@ -867,7 +873,7 @@ int swad__loginByUserPasswordKey (struct soap *soap,
} }
/***** Get user's data from database *****/ /***** Get user's data from database *****/
if ((NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get user's data")) == 1) // User found in table of users' data if (NumRows == 1) // User found in table of users' data
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1002,10 +1008,12 @@ int swad__loginBySessionKey (struct soap *soap,
// Now, we know that sessionID is a valid session identifier // Now, we know that sessionID is a valid session identifier
/***** Query data of the session from database *****/ /***** Query data of the session from database *****/
DB_BuildQuery ("SELECT UsrCod,DegCod,CrsCod FROM sessions" NumRows =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get session data",
"SELECT UsrCod,DegCod,CrsCod FROM sessions"
" WHERE SessionId='%s'", " WHERE SessionId='%s'",
sessionID); sessionID);
if ((NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get session data")) == 1) // Session found in table of sessions if (NumRows == 1) // Session found in table of sessions
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1116,14 +1124,20 @@ int swad__getNewPassword (struct soap *soap,
Str_RemoveLeadingArrobas (UsrIDNickOrEmail); Str_RemoveLeadingArrobas (UsrIDNickOrEmail);
/* User has typed a nickname */ /* User has typed a nickname */
DB_BuildQuery ("SELECT UsrCod FROM usr_nicknames WHERE Nickname='%s'", NumRows =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get user's data",
"SELECT UsrCod FROM usr_nicknames"
" WHERE Nickname='%s'",
UsrIDNickOrEmail); UsrIDNickOrEmail);
} }
else if (Mai_CheckIfEmailIsValid (Gbl.Usrs.Me.UsrIdLogin)) // 2: It's an email else if (Mai_CheckIfEmailIsValid (Gbl.Usrs.Me.UsrIdLogin)) // 2: It's an email
{ {
/* User has typed an email */ /* User has typed an email */
// TODO: Get only if email confirmed? // TODO: Get only if email confirmed?
DB_BuildQuery ("SELECT UsrCod FROM usr_emails WHERE E_mail='%s'", NumRows =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get user's data",
"SELECT UsrCod FROM usr_emails"
" WHERE E_mail='%s'",
UsrIDNickOrEmail); UsrIDNickOrEmail);
} }
else // 3: It's not a nickname nor email else // 3: It's not a nickname nor email
@ -1135,7 +1149,10 @@ int swad__getNewPassword (struct soap *soap,
{ {
/* User has typed a valid user's ID (existing or not) */ /* User has typed a valid user's ID (existing or not) */
// TODO: Get only if ID confirmed? // TODO: Get only if ID confirmed?
DB_BuildQuery ("SELECT UsrCod FROM usr_IDs WHERE UsrID='%s'", NumRows =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get user's data",
"SELECT UsrCod FROM usr_IDs"
" WHERE UsrID='%s'",
UsrIDNickOrEmail); UsrIDNickOrEmail);
} }
else // String is not a valid user's nickname, email or ID else // String is not a valid user's nickname, email or ID
@ -1145,7 +1162,7 @@ int swad__getNewPassword (struct soap *soap,
} }
/***** Get user's data from database *****/ /***** Get user's data from database *****/
if ((NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get user's data")) == 1) // One unique user found in table of users' data if (NumRows == 1) // One unique user found in table of users' data
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1204,11 +1221,17 @@ int swad__getCourses (struct soap *soap,
Gbl.Usrs.Me.Role.Logged = Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role; Gbl.Usrs.Me.Role.Logged = Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role;
/***** Query my courses from database *****/ /***** Query my courses from database *****/
DB_BuildQuery ("SELECT courses.CrsCod,courses.ShortName,courses.FullName,crs_usr.Role FROM crs_usr,courses" NumRows =
" WHERE crs_usr.UsrCod=%ld AND crs_usr.CrsCod=courses.CrsCod" (unsigned) DB_QuerySELECT (&mysql_res,"can not get user's courses",
"SELECT courses.CrsCod,"
"courses.ShortName,"
"courses.FullName,"
"crs_usr.Role"
" FROM crs_usr,courses"
" WHERE crs_usr.UsrCod=%ld"
" AND crs_usr.CrsCod=courses.CrsCod"
" ORDER BY courses.FullName", " ORDER BY courses.FullName",
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod);
NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get user's courses");
getCoursesOut->numCourses = (int) NumRows; getCoursesOut->numCourses = (int) NumRows;
getCoursesOut->coursesArray.__size = (int) NumRows; getCoursesOut->coursesArray.__size = (int) NumRows;
@ -1667,12 +1690,17 @@ int swad__getGroupTypes (struct soap *soap,
"Requester must belong to course"); "Requester must belong to course");
/***** Query group types in a course from database *****/ /***** Query group types in a course from database *****/
DB_BuildQuery ("SELECT GrpTypCod,GrpTypName,Mandatory,Multiple,UNIX_TIMESTAMP(OpenTime)" NumRows =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get group types",
"SELECT GrpTypCod,"
"GrpTypName,"
"Mandatory,"
"Multiple,"
"UNIX_TIMESTAMP(OpenTime)"
" FROM crs_grp_types" " FROM crs_grp_types"
" WHERE CrsCod=%d" " WHERE CrsCod=%d"
" ORDER BY GrpTypName", " ORDER BY GrpTypName",
courseCode); courseCode);
NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get group types");
getGroupTypesOut->numGroupTypes = (int) NumRows; getGroupTypesOut->numGroupTypes = (int) NumRows;
getGroupTypesOut->groupTypesArray.__size = (int) NumRows; getGroupTypesOut->groupTypesArray.__size = (int) NumRows;
@ -1775,15 +1803,21 @@ int swad__getGroups (struct soap *soap,
"Requester must belong to course"); "Requester must belong to course");
/***** Query groups in a course from database *****/ /***** Query groups in a course from database *****/
DB_BuildQuery ("SELECT crs_grp_types.GrpTypCod,crs_grp_types.GrpTypName," NumRows =
"crs_grp.GrpCod,crs_grp.GrpName," (unsigned) DB_QuerySELECT (&mysql_res,"can not get user's groups",
"crs_grp.MaxStudents,crs_grp.Open,crs_grp.FileZones" "SELECT crs_grp_types.GrpTypCod,"
"crs_grp_types.GrpTypName,"
"crs_grp.GrpCod,"
"crs_grp.GrpName,"
"crs_grp.MaxStudents,"
"crs_grp.Open,"
"crs_grp.FileZones"
" FROM crs_grp_types,crs_grp" " FROM crs_grp_types,crs_grp"
" WHERE crs_grp_types.CrsCod=%d" " WHERE crs_grp_types.CrsCod=%d"
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
" ORDER BY crs_grp_types.GrpTypName,crs_grp.GrpName", " ORDER BY crs_grp_types.GrpTypName,"
"crs_grp.GrpName",
courseCode); courseCode);
NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get user's groups");
getGroupsOut->numGroups = (int) NumRows; getGroupsOut->numGroups = (int) NumRows;
getGroupsOut->groupsArray.__size = (int) NumRows; getGroupsOut->groupsArray.__size = (int) NumRows;
@ -1861,7 +1895,8 @@ int swad__sendMyGroups (struct soap *soap,
unsigned NumGrp; unsigned NumGrp;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned NumRow,NumRows; unsigned NumRow;
unsigned NumRows;
long GrpCod; long GrpCod;
unsigned MaxStudents; unsigned MaxStudents;
@ -1936,15 +1971,20 @@ int swad__sendMyGroups (struct soap *soap,
Grp_FreeListCodGrp (&LstGrpsIWant); Grp_FreeListCodGrp (&LstGrpsIWant);
/***** Query groups in a course from database *****/ /***** Query groups in a course from database *****/
DB_BuildQuery ("SELECT crs_grp_types.GrpTypCod,crs_grp_types.GrpTypName," NumRows =
"crs_grp.GrpCod,crs_grp.GrpName," (unsigned) DB_QuerySELECT (&mysql_res,"can not get user's groups",
"crs_grp.MaxStudents,crs_grp.Open,crs_grp.FileZones" "SELECT crs_grp_types.GrpTypCod,"
"crs_grp_types.GrpTypName,"
"crs_grp.GrpCod,"
"crs_grp.GrpName,"
"crs_grp.MaxStudents,"
"crs_grp.Open,"
"crs_grp.FileZones"
" FROM crs_grp_types,crs_grp" " FROM crs_grp_types,crs_grp"
" WHERE crs_grp_types.CrsCod=%d" " WHERE crs_grp_types.CrsCod=%d"
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
" ORDER BY crs_grp_types.GrpTypName,crs_grp.GrpName", " ORDER BY crs_grp_types.GrpTypName,crs_grp.GrpName",
courseCode); courseCode);
NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get user's groups");
SendMyGroupsOut->numGroups = (int) NumRows; SendMyGroupsOut->numGroups = (int) NumRows;
SendMyGroupsOut->groupsArray.__size = (int) NumRows; SendMyGroupsOut->groupsArray.__size = (int) NumRows;
@ -2073,6 +2113,7 @@ int swad__getAttendanceEvents (struct soap *soap,
int ReturnCode; int ReturnCode;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned NumRows;
int NumAttEvent; int NumAttEvent;
long AttCod; long AttCod;
char PhotoURL[Cns_MAX_BYTES_WWW + 1]; char PhotoURL[Cns_MAX_BYTES_WWW + 1];
@ -2114,7 +2155,9 @@ int swad__getAttendanceEvents (struct soap *soap,
"Requester must be a teacher"); "Requester must be a teacher");
/***** Query list of attendance events *****/ /***** Query list of attendance events *****/
DB_BuildQuery ("SELECT AttCod,Hidden,UsrCod," NumRows =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get attendance events",
"SELECT AttCod,Hidden,UsrCod,"
"UNIX_TIMESTAMP(StartTime) AS ST," "UNIX_TIMESTAMP(StartTime) AS ST,"
"UNIX_TIMESTAMP(EndTime) AS ET," "UNIX_TIMESTAMP(EndTime) AS ET,"
"CommentTchVisible,Title,Txt" "CommentTchVisible,Title,Txt"
@ -2122,8 +2165,9 @@ int swad__getAttendanceEvents (struct soap *soap,
" WHERE CrsCod=%d" " WHERE CrsCod=%d"
" ORDER BY ST DESC,ET DESC,Title DESC", " ORDER BY ST DESC,ET DESC,Title DESC",
courseCode); courseCode);
getAttendanceEventsOut->eventsArray.__size = getAttendanceEventsOut->eventsArray.__size =
getAttendanceEventsOut->numEvents = (int) DB_QuerySELECT_new (&mysql_res,"can not get attendance events"); getAttendanceEventsOut->numEvents = (int) NumRows;
if (getAttendanceEventsOut->numEvents == 0) if (getAttendanceEventsOut->numEvents == 0)
getAttendanceEventsOut->eventsArray.__ptr = NULL; getAttendanceEventsOut->eventsArray.__ptr = NULL;
@ -2237,9 +2281,12 @@ static void Svc_GetListGrpsInAttendanceEventFromDB (long AttCod,char **ListGroup
size_t Length; size_t Length;
/***** Get list of groups *****/ /***** Get list of groups *****/
DB_BuildQuery ("SELECT GrpCod FROM att_grp WHERE AttCod=%ld", NumGrps =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get groups"
" of an attendance event",
"SELECT GrpCod FROM att_grp WHERE AttCod=%ld",
AttCod); AttCod);
if ((NumGrps = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get groups of an attendance event")) == 0) if (NumGrps == 0)
*ListGroups = NULL; *ListGroups = NULL;
else // Events found else // Events found
{ {
@ -2566,14 +2613,18 @@ int swad__getAttendanceUsers (struct soap *soap,
(unsigned) Rol_STD, (unsigned) Rol_STD,
Att.AttCod); Att.AttCod);
// Query: list of users in attendance list + rest of users (subquery) // Query: list of users in attendance list + rest of users (subquery)
DB_BuildQuery ("SELECT u.UsrCod,u.Present FROM " NumRows =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get users"
" in an attendance event",
"SELECT u.UsrCod,u.Present FROM "
"(SELECT UsrCod,Present" "(SELECT UsrCod,Present"
" FROM att_usr WHERE AttCod=%ld" " FROM att_usr WHERE AttCod=%ld"
" UNION %s) AS u,usr_data" " UNION %s) AS u,usr_data"
" WHERE u.UsrCod=usr_data.UsrCod" " WHERE u.UsrCod=usr_data.UsrCod"
" ORDER BY usr_data.Surname1,usr_data.Surname2,usr_data.FirstName", " ORDER BY usr_data.Surname1,"
"usr_data.Surname2,"
"usr_data.FirstName",
(long) attendanceEventCode,SubQuery); (long) attendanceEventCode,SubQuery);
NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get users in an attendance event");
getAttendanceUsersOut->numUsers = (int) NumRows; getAttendanceUsersOut->numUsers = (int) NumRows;
getAttendanceUsersOut->usersArray.__size = (int) NumRows; getAttendanceUsersOut->usersArray.__size = (int) NumRows;
@ -2853,13 +2904,23 @@ int swad__getNotifications (struct soap *soap,
return ReturnCode; return ReturnCode;
/***** Get my notifications from database *****/ /***** Get my notifications from database *****/
DB_BuildQuery ("SELECT NtfCod,NotifyEvent,UNIX_TIMESTAMP(TimeNotif)," NumNotifications =
"FromUsrCod,InsCod,CtrCod,DegCod,CrsCod,Cod,Status" (unsigned) DB_QuerySELECT (&mysql_res,"can not get user's notifications",
"SELECT NtfCod," // row[0]
"NotifyEvent," // row[1]
"UNIX_TIMESTAMP(TimeNotif)," // row[2]
"FromUsrCod," // row[3]
"InsCod," // row[4]
"CtrCod," // row[5]
"DegCod," // row[6]
"CrsCod," // row[7]
"Cod," // row[8]
"Status" // row[9]
" FROM notif" " FROM notif"
" WHERE ToUsrCod=%ld AND TimeNotif>=FROM_UNIXTIME(%ld)" " WHERE ToUsrCod=%ld AND TimeNotif>=FROM_UNIXTIME(%ld)"
" ORDER BY TimeNotif DESC", " ORDER BY TimeNotif DESC",
Gbl.Usrs.Me.UsrDat.UsrCod,beginTime); Gbl.Usrs.Me.UsrDat.UsrCod,beginTime);
NumNotifications = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get user's notifications");
if (NumNotifications) // Notifications found if (NumNotifications) // Notifications found
{ {
getNotificationsOut->numNotifications = (int) NumNotifications; getNotificationsOut->numNotifications = (int) NumNotifications;
@ -3039,10 +3100,10 @@ static int Svc_GetMyLanguage (void)
Txt_Language_t Lan; Txt_Language_t Lan;
/***** Get user's language *****/ /***** Get user's language *****/
DB_BuildQuery ("SELECT Language FROM usr_data" if (DB_QuerySELECT (&mysql_res,"can not get user's language",
"SELECT Language FROM usr_data"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod) != 1)
if (DB_QuerySELECT_new (&mysql_res,"can not get user's language") != 1)
return soap_receiver_fault (Gbl.soap, return soap_receiver_fault (Gbl.soap,
"Can not get user's language from database", "Can not get user's language from database",
"User doen't exist in database"); "User doen't exist in database");
@ -3181,15 +3242,15 @@ int swad__sendMessage (struct soap *soap,
if (messageCode) if (messageCode)
{ {
/***** Check if the original message was really received by me *****/ /***** Check if the original message was really received by me *****/
DB_BuildQuery ("SELECT SUM(N) FROM" if (!DB_QuerySELECT (&mysql_res,"can not check original message",
"SELECT SUM(N) FROM"
" (SELECT COUNT(*) AS N FROM msg_rcv" " (SELECT COUNT(*) AS N FROM msg_rcv"
" WHERE UsrCod=%ld AND MsgCod=%ld" " WHERE UsrCod=%ld AND MsgCod=%ld"
" UNION" " UNION"
" SELECT COUNT(*) AS N FROM msg_rcv_deleted" " SELECT COUNT(*) AS N FROM msg_rcv_deleted"
" WHERE UsrCod=%ld AND MsgCod=%ld) AS T", " WHERE UsrCod=%ld AND MsgCod=%ld) AS T",
Gbl.Usrs.Me.UsrDat.UsrCod,(long) messageCode, Gbl.Usrs.Me.UsrDat.UsrCod,(long) messageCode,
Gbl.Usrs.Me.UsrDat.UsrCod,(long) messageCode); Gbl.Usrs.Me.UsrDat.UsrCod,(long) messageCode))
if (!DB_QuerySELECT_new (&mysql_res,"can not check original message"))
return soap_sender_fault (Gbl.soap, return soap_sender_fault (Gbl.soap,
"Can not check original message", "Can not check original message",
"Error reading from database"); "Error reading from database");
@ -3210,13 +3271,15 @@ int swad__sendMessage (struct soap *soap,
"Original message does not exist"); "Original message does not exist");
/***** Get the recipient of the message *****/ /***** Get the recipient of the message *****/
DB_BuildQuery ("SELECT UsrCod FROM msg_snt" NumRows =
(unsigned) DB_QuerySELECT (&mysql_res,"can not check original message",
"SELECT UsrCod FROM msg_snt"
" WHERE MsgCod=%ld" " WHERE MsgCod=%ld"
" UNION " " UNION "
"SELECT UsrCod FROM msg_snt_deleted" "SELECT UsrCod FROM msg_snt_deleted"
" WHERE MsgCod=%ld", " WHERE MsgCod=%ld",
(long) messageCode,(long) messageCode); (long) messageCode,(long) messageCode);
if ((NumRows = DB_QuerySELECT_new (&mysql_res,"can not check original message"))) // Message found in any of the two tables of sent messages if (NumRows) // Message found in any of the two tables of sent messages
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
ReplyUsrCod = Str_ConvertStrCodToLongCod (row[0]); ReplyUsrCod = Str_ConvertStrCodToLongCod (row[0]);
@ -3571,10 +3634,10 @@ static int Svc_GetTstConfig (long CrsCod)
MYSQL_ROW row; MYSQL_ROW row;
/***** Query database *****/ /***** Query database *****/
DB_BuildQuery ("SELECT Pluggable,Min,Def,Max,MinTimeNxtTstPerQst,Feedback" if (DB_QuerySELECT (&mysql_res,"can not get test configuration",
"SELECT Pluggable,Min,Def,Max,MinTimeNxtTstPerQst,Feedback"
" FROM tst_config WHERE CrsCod=%ld", " FROM tst_config WHERE CrsCod=%ld",
CrsCod); CrsCod))
if (DB_QuerySELECT_new (&mysql_res,"can not get test configuration"))
{ {
/***** Get minimun, default and maximum *****/ /***** Get minimun, default and maximum *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -3714,12 +3777,12 @@ static int Svc_GetTstTags (long CrsCod,struct swad__getTestsOutput *getTestsOut)
unsigned NumRows; unsigned NumRows;
/***** Get available tags from database *****/ /***** Get available tags from database *****/
DB_BuildQuery ("SELECT TagCod,TagTxt" NumRows = DB_QuerySELECT (&mysql_res,"can not get test tags",
"SELECT TagCod,TagTxt"
" FROM tst_tags" " FROM tst_tags"
" WHERE CrsCod=%ld AND TagHidden='N'" " WHERE CrsCod=%ld AND TagHidden='N'"
" ORDER BY TagTxt", " ORDER BY TagTxt",
CrsCod); CrsCod);
NumRows = DB_QuerySELECT_new (&mysql_res,"can not get test tags");
getTestsOut->tagsArray.__size = (int) NumRows; getTestsOut->tagsArray.__size = (int) NumRows;
@ -3767,7 +3830,9 @@ static int Svc_GetTstQuestions (long CrsCod,long BeginTime,struct swad__getTests
/***** Get recent test questions from database *****/ /***** Get recent test questions from database *****/
// DISTINCTROW is necessary to not repeat questions // DISTINCTROW is necessary to not repeat questions
DB_BuildQuery ("SELECT DISTINCTROW tst_questions.QstCod," NumRows =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get test questions",
"SELECT DISTINCTROW tst_questions.QstCod,"
"tst_questions.AnsType,tst_questions.Shuffle," "tst_questions.AnsType,tst_questions.Shuffle,"
"tst_questions.Stem,tst_questions.Feedback" "tst_questions.Stem,tst_questions.Feedback"
" FROM tst_questions,tst_question_tags,tst_tags" " FROM tst_questions,tst_question_tags,tst_tags"
@ -3789,7 +3854,6 @@ static int Svc_GetTstQuestions (long CrsCod,long BeginTime,struct swad__getTests
CrsCod,CrsCod,CrsCod, CrsCod,CrsCod,CrsCod,
BeginTime, BeginTime,
BeginTime); BeginTime);
NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get test questions");
getTestsOut->questionsArray.__size = (int) NumRows; getTestsOut->questionsArray.__size = (int) NumRows;
@ -3851,7 +3915,9 @@ static int Svc_GetTstAnswers (long CrsCod,long BeginTime,struct swad__getTestsOu
unsigned Index; unsigned Index;
/***** Get recent test questions from database *****/ /***** Get recent test questions from database *****/
DB_BuildQuery ("SELECT QstCod,AnsInd,Correct,Answer,Feedback" NumRows =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get test answers",
"SELECT QstCod,AnsInd,Correct,Answer,Feedback"
" FROM tst_answers WHERE QstCod IN " " FROM tst_answers WHERE QstCod IN "
"(SELECT tst_questions.QstCod" "(SELECT tst_questions.QstCod"
" FROM tst_questions,tst_question_tags,tst_tags" " FROM tst_questions,tst_question_tags,tst_tags"
@ -3874,7 +3940,6 @@ static int Svc_GetTstAnswers (long CrsCod,long BeginTime,struct swad__getTestsOu
CrsCod,CrsCod,CrsCod, CrsCod,CrsCod,CrsCod,
BeginTime, BeginTime,
BeginTime); BeginTime);
NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get test answers");
getTestsOut->answersArray.__size = (int) NumRows; getTestsOut->answersArray.__size = (int) NumRows;
@ -3935,7 +4000,9 @@ static int Svc_GetTstQuestionTags (long CrsCod,long BeginTime,struct swad__getTe
unsigned Index; unsigned Index;
/***** Get recent test questions from database *****/ /***** Get recent test questions from database *****/
DB_BuildQuery ("SELECT QstCod,TagCod,TagInd" NumRows =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get test question tags",
"SELECT QstCod,TagCod,TagInd"
" FROM tst_question_tags WHERE QstCod IN " " FROM tst_question_tags WHERE QstCod IN "
"(SELECT tst_questions.QstCod" "(SELECT tst_questions.QstCod"
" FROM tst_questions,tst_question_tags,tst_tags" " FROM tst_questions,tst_question_tags,tst_tags"
@ -3958,7 +4025,6 @@ static int Svc_GetTstQuestionTags (long CrsCod,long BeginTime,struct swad__getTe
CrsCod,CrsCod,CrsCod, CrsCod,CrsCod,CrsCod,
BeginTime, BeginTime,
BeginTime); BeginTime);
NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get test question tags");
getTestsOut->questionTagsArray.__size = (int) NumRows; getTestsOut->questionTagsArray.__size = (int) NumRows;
@ -4095,7 +4161,9 @@ int swad__getTrivialQuestion (struct soap *soap,
/***** Start query *****/ /***** Start query *****/
Str_SetDecimalPointToUS (); // To print the floating point as a dot Str_SetDecimalPointToUS (); // To print the floating point as a dot
DB_BuildQuery ("SELECT DISTINCTROW tst_questions.QstCod," NumRows =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get test questions",
"SELECT DISTINCTROW tst_questions.QstCod,"
"tst_questions.AnsType,tst_questions.Shuffle," "tst_questions.AnsType,tst_questions.Shuffle,"
"tst_questions.Stem,tst_questions.Feedback," "tst_questions.Stem,tst_questions.Feedback,"
"tst_questions.Score/tst_questions.NumHits AS S" "tst_questions.Score/tst_questions.NumHits AS S"
@ -4117,8 +4185,6 @@ int swad__getTrivialQuestion (struct soap *soap,
lowerScore,upperScore); lowerScore,upperScore);
Str_SetDecimalPointToLocal (); // Return to local system Str_SetDecimalPointToLocal (); // Return to local system
NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get test questions");
if (NumRows == 1) // Question found if (NumRows == 1) // Question found
{ {
/* /*
@ -4184,11 +4250,12 @@ int swad__getTrivialQuestion (struct soap *soap,
if (QstCod > 0) if (QstCod > 0)
{ {
/***** Get answer from database *****/ /***** Get answer from database *****/
DB_BuildQuery ("SELECT QstCod,AnsInd,Correct,Answer,Feedback" NumRows =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get test answers",
"SELECT QstCod,AnsInd,Correct,Answer,Feedback"
" FROM tst_answers WHERE QstCod=%ld" " FROM tst_answers WHERE QstCod=%ld"
" ORDER BY AnsInd", " ORDER BY AnsInd",
QstCod); QstCod);
NumRows = (unsigned) DB_QuerySELECT_new (&mysql_res,"can not get test answers");
getTrivialQuestionOut->answersArray.__size = (int) NumRows; getTrivialQuestionOut->answersArray.__size = (int) NumRows;