Version 20.56: Apr 04, 2021 Optimizations in database selects.

This commit is contained in:
acanas 2021-04-04 19:57:17 +02:00
parent 9dba8e5314
commit 3c20280f3a
32 changed files with 598 additions and 843 deletions

View File

@ -358,11 +358,11 @@ static int API_GetPlgCodFromAppKey (struct soap *soap,
const char *appKey) const char *appKey)
{ {
/***** Get number of plugins with a IP address *****/ /***** Get number of plugins with a IP address *****/
Gbl.WebService.PlgCod = DB_QuerySELECTCod ("can not check application key", Gbl.WebService.PlgCod = DB_QuerySELECTCode ("can not check application key",
"SELECT PlgCod" "SELECT PlgCod"
" FROM plg_plugins" " FROM plg_plugins"
" WHERE AppKey='%s'", " WHERE AppKey='%s'",
appKey); // Session found in table of sessions appKey); // Session found in table of sessions
if (Gbl.WebService.PlgCod < 0) if (Gbl.WebService.PlgCod < 0)
return soap_sender_fault (soap, return soap_sender_fault (soap,
"Unknown application key", "Unknown application key",
@ -578,11 +578,11 @@ static int API_RemoveOldWSKeys (struct soap *soap)
static int API_GetCurrentDegCodFromCurrentCrsCod (void) static int API_GetCurrentDegCodFromCurrentCrsCod (void)
{ {
/***** Check that key does not exist in database *****/ /***** Check that key does not exist in database *****/
Gbl.Hierarchy.Deg.DegCod = DB_QuerySELECTCod ("can not get the degree of a course", Gbl.Hierarchy.Deg.DegCod = DB_QuerySELECTCode ("can not get the degree of a course",
"SELECT DegCod" "SELECT DegCod"
" FROM crs_courses" " FROM crs_courses"
" WHERE CrsCod=%ld", " WHERE CrsCod=%ld",
Gbl.Hierarchy.Crs.CrsCod); // Course found in table of courses Gbl.Hierarchy.Crs.CrsCod); // Course found in table of courses
return SOAP_OK; return SOAP_OK;
} }
@ -895,28 +895,28 @@ int swad__loginByUserPasswordKey (struct soap *soap,
Str_RemoveLeadingArrobas (UsrIDNickOrEmail); Str_RemoveLeadingArrobas (UsrIDNickOrEmail);
/* User has typed a nickname */ /* User has typed a nickname */
Gbl.Usrs.Me.UsrDat.UsrCod = DB_QuerySELECTCod ("can not get user's data", Gbl.Usrs.Me.UsrDat.UsrCod = DB_QuerySELECTCode ("can not get user's data",
"SELECT usr_nicknames.UsrCod" "SELECT usr_nicknames.UsrCod"
" FROM usr_nicknames," " FROM usr_nicknames,"
"usr_data" "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"
" AND usr_data.Password='%s'", " AND usr_data.Password='%s'",
UsrIDNickOrEmail, UsrIDNickOrEmail,
userPassword); userPassword);
} }
else if (Mai_CheckIfEmailIsValid (UsrIDNickOrEmail)) // 2: It's an email else if (Mai_CheckIfEmailIsValid (UsrIDNickOrEmail)) // 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?
Gbl.Usrs.Me.UsrDat.UsrCod = DB_QuerySELECTCod ("can not get user's data", Gbl.Usrs.Me.UsrDat.UsrCod = DB_QuerySELECTCode ("can not get user's data",
"SELECT usr_emails.UsrCod" "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"
" AND usr_data.Password='%s'", " AND usr_data.Password='%s'",
UsrIDNickOrEmail, UsrIDNickOrEmail,
userPassword); userPassword);
} }
else // 3: It's not a nickname nor email else // 3: It's not a nickname nor email
{ {
@ -927,15 +927,15 @@ 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?
Gbl.Usrs.Me.UsrDat.UsrCod = DB_QuerySELECTCod ("can not get user's data", Gbl.Usrs.Me.UsrDat.UsrCod = DB_QuerySELECTCode ("can not get user's data",
"SELECT usr_ids.UsrCod" "SELECT usr_ids.UsrCod"
" FROM usr_ids," " FROM usr_ids,"
"usr_data" "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'",
UsrIDNickOrEmail, UsrIDNickOrEmail,
userPassword); userPassword);
} }
else // String is not a valid user's nickname, email or ID else // String is not a valid user's nickname, email or ID
return soap_receiver_fault (soap, return soap_receiver_fault (soap,
@ -1245,20 +1245,20 @@ int swad__getNewPassword (struct soap *soap,
Str_RemoveLeadingArrobas (UsrIDNickOrEmail); Str_RemoveLeadingArrobas (UsrIDNickOrEmail);
/* User has typed a nickname */ /* User has typed a nickname */
Gbl.Usrs.Me.UsrDat.UsrCod = DB_QuerySELECTCod ("can not get user's data", Gbl.Usrs.Me.UsrDat.UsrCod = DB_QuerySELECTCode ("can not get user's data",
"SELECT UsrCod" "SELECT UsrCod"
" FROM usr_nicknames" " FROM usr_nicknames"
" WHERE Nickname='%s'", " 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?
Gbl.Usrs.Me.UsrDat.UsrCod = DB_QuerySELECTCod ("can not get user's data", Gbl.Usrs.Me.UsrDat.UsrCod = DB_QuerySELECTCode ("can not get user's data",
"SELECT UsrCod" "SELECT UsrCod"
" FROM usr_emails" " FROM usr_emails"
" WHERE E_mail='%s'", " WHERE E_mail='%s'",
UsrIDNickOrEmail); UsrIDNickOrEmail);
else // 3: It's not a nickname nor email else // 3: It's not a nickname nor email
{ {
// Users' IDs are always stored internally in capitals and without leading zeros // Users' IDs are always stored internally in capitals and without leading zeros
@ -1267,11 +1267,11 @@ int swad__getNewPassword (struct soap *soap,
if (ID_CheckIfUsrIDIsValid (UsrIDNickOrEmail)) if (ID_CheckIfUsrIDIsValid (UsrIDNickOrEmail))
/* 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?
Gbl.Usrs.Me.UsrDat.UsrCod = DB_QuerySELECTCod ("can not get user's data", Gbl.Usrs.Me.UsrDat.UsrCod = DB_QuerySELECTCode ("can not get user's data",
"SELECT UsrCod" "SELECT UsrCod"
" FROM usr_ids" " FROM usr_ids"
" WHERE UsrID='%s'", " 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
return soap_receiver_fault (soap, return soap_receiver_fault (soap,
"Bad log in", "Bad log in",
@ -2697,7 +2697,7 @@ static void API_GetListGrpsInAttendanceEventFromDB (struct soap *soap,
NumGrp++) NumGrp++)
{ {
/* Get next group */ /* Get next group */
GrpCod = DB_GetNextCod (mysql_res); GrpCod = DB_GetNextCode (mysql_res);
snprintf (GrpCodStr,sizeof (GrpCodStr),NumGrp ? ",%ld" : snprintf (GrpCodStr,sizeof (GrpCodStr),NumGrp ? ",%ld" :
"%ld", "%ld",
GrpCod); GrpCod);
@ -3704,16 +3704,16 @@ 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 *****/
ReplyUsrCod = DB_QuerySELECTCod ("can not check original message", ReplyUsrCod = DB_QuerySELECTCode ("can not check original message",
"SELECT UsrCod" "SELECT UsrCod"
" FROM msg_snt" " FROM msg_snt"
" WHERE MsgCod=%ld" " WHERE MsgCod=%ld"
" UNION " " UNION "
"SELECT UsrCod" "SELECT UsrCod"
" FROM msg_snt_deleted" " FROM msg_snt_deleted"
" WHERE MsgCod=%ld", " WHERE MsgCod=%ld",
(long) messageCode, (long) messageCode,
(long) messageCode); (long) messageCode);
if (ReplyUsrCod <= 0) if (ReplyUsrCod <= 0)
return soap_sender_fault (soap, return soap_sender_fault (soap,
"Can not send reply message", "Can not send reply message",
@ -5418,7 +5418,7 @@ static void API_GetListGrpsInGameFromDB (struct soap *soap,
NumGrp++) NumGrp++)
{ {
/* Get next group */ /* Get next group */
GrpCod = DB_GetNextCod (mysql_res); GrpCod = DB_GetNextCode (mysql_res);
snprintf (GrpCodStr,sizeof (GrpCodStr),NumGrp ? ",%ld" : snprintf (GrpCodStr,sizeof (GrpCodStr),NumGrp ? ",%ld" :
"%ld", "%ld",
GrpCod); GrpCod);

View File

@ -238,7 +238,7 @@ void Acc_CheckIfEmptyAccountExists (void)
{ {
/***** Get user's data from query result *****/ /***** Get user's data from query result *****/
/* Get user's code */ /* Get user's code */
UsrDat.UsrCod = DB_GetNextCod (mysql_res); UsrDat.UsrCod = DB_GetNextCode (mysql_res);
/* Get user's data */ /* Get user's data */
Usr_GetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS); Usr_GetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS);

View File

@ -1175,7 +1175,7 @@ static void Agd_GetListEvents (struct Agd_Agenda *Agenda,
NumEvent < Agenda->Num; NumEvent < Agenda->Num;
NumEvent++) NumEvent++)
/* Get next event code */ /* Get next event code */
if ((Agenda->LstAgdCods[NumEvent] = DB_GetNextCod (mysql_res)) < 0) if ((Agenda->LstAgdCods[NumEvent] = DB_GetNextCode (mysql_res)) < 0)
Lay_ShowErrorAndExit ("Error: wrong event code."); Lay_ShowErrorAndExit ("Error: wrong event code.");
} }

View File

@ -740,7 +740,7 @@ static void Asg_GetListAssignments (struct Asg_Assignments *Assignments)
NumAsg++) NumAsg++)
{ {
/* Get next assignment code */ /* Get next assignment code */
if ((Assignments->LstAsgCods[NumAsg] = DB_GetNextCod (mysql_res)) < 0) if ((Assignments->LstAsgCods[NumAsg] = DB_GetNextCode (mysql_res)) < 0)
Lay_ShowErrorAndExit ("Error: wrong assignment code."); Lay_ShowErrorAndExit ("Error: wrong assignment code.");
} }
} }

View File

@ -720,7 +720,7 @@ static void Att_GetListAttEvents (struct Att_Events *Events,
NumAttEvent++) NumAttEvent++)
{ {
/* Get next attendance event code */ /* Get next attendance event code */
if ((Events->Lst[NumAttEvent].AttCod = DB_GetNextCod (mysql_res)) < 0) if ((Events->Lst[NumAttEvent].AttCod = DB_GetNextCode (mysql_res)) < 0)
Lay_ShowErrorAndExit ("Error: wrong attendance event code."); Lay_ShowErrorAndExit ("Error: wrong attendance event code.");
} }
} }
@ -3069,7 +3069,7 @@ static void Att_GetListSelectedAttCods (struct Att_Events *Events)
NumGrpInThisEvent++) NumGrpInThisEvent++)
{ {
/* Get next group associated to this event */ /* Get next group associated to this event */
if ((GrpCodInThisEvent = DB_GetNextCod (mysql_res)) > 0) if ((GrpCodInThisEvent = DB_GetNextCode (mysql_res)) > 0)
/* Check if this group is selected */ /* Check if this group is selected */
for (NumGrpSel = 0; for (NumGrpSel = 0;
NumGrpSel < Gbl.Crs.Grps.LstGrpsSel.NumGrps && NumGrpSel < Gbl.Crs.Grps.LstGrpsSel.NumGrps &&

View File

@ -423,7 +423,7 @@ void Cfe_PrintCallForExam (void)
/***** Get the code of the call for exam *****/ /***** Get the code of the call for exam *****/
if ((ExaCod = Cfe_GetParamExaCod ()) <= 0) if ((ExaCod = Cfe_GetParamExaCod ()) <= 0)
Lay_ShowErrorAndExit ("Code of call for exam is missing."); Lay_WrongCallForExamExit ();
/***** Read call for exam from the database *****/ /***** Read call for exam from the database *****/
Cfe_GetDataCallForExamFromDB (&CallsForExams,ExaCod); Cfe_GetDataCallForExamFromDB (&CallsForExams,ExaCod);
@ -452,7 +452,7 @@ void Cfe_ReqRemoveCallForExam (void)
/***** Get the code of the call for exam *****/ /***** Get the code of the call for exam *****/
if ((ExaCod = Cfe_GetParamExaCod ()) <= 0) if ((ExaCod = Cfe_GetParamExaCod ()) <= 0)
Lay_ShowErrorAndExit ("Code of call for exam is missing."); Lay_WrongCallForExamExit ();
/***** Show question and button to remove call for exam *****/ /***** Show question and button to remove call for exam *****/
/* Begin alert */ /* Begin alert */
@ -488,7 +488,7 @@ void Cfe_RemoveCallForExam1 (void)
/***** Get the code of the call for exam *****/ /***** Get the code of the call for exam *****/
if ((ExaCod = Cfe_GetParamExaCod ()) <= 0) if ((ExaCod = Cfe_GetParamExaCod ()) <= 0)
Lay_ShowErrorAndExit ("Code of call for exam is missing."); Lay_WrongCallForExamExit ();
/***** Mark the call for exam as deleted in the database *****/ /***** Mark the call for exam as deleted in the database *****/
DB_QueryUPDATE ("can not remove call for exam", DB_QueryUPDATE ("can not remove call for exam",
@ -536,7 +536,7 @@ void Cfe_HideCallForExam (void)
/***** Get the code of the call for exam *****/ /***** Get the code of the call for exam *****/
if ((ExaCod = Cfe_GetParamExaCod ()) <= 0) if ((ExaCod = Cfe_GetParamExaCod ()) <= 0)
Lay_ShowErrorAndExit ("Code of call for exam is missing."); Lay_WrongCallForExamExit ();
/***** Mark the call for exam as hidden in the database *****/ /***** Mark the call for exam as hidden in the database *****/
DB_QueryUPDATE ("can not hide call for exam", DB_QueryUPDATE ("can not hide call for exam",
@ -567,7 +567,7 @@ void Cfe_UnhideCallForExam (void)
/***** Get the code of the call for exam *****/ /***** Get the code of the call for exam *****/
if ((ExaCod = Cfe_GetParamExaCod ()) <= 0) if ((ExaCod = Cfe_GetParamExaCod ()) <= 0)
Lay_ShowErrorAndExit ("Code of call for exam is missing."); Lay_WrongCallForExamExit ();
/***** Mark the call for exam as visible in the database *****/ /***** Mark the call for exam as visible in the database *****/
DB_QueryUPDATE ("can not unhide call for exam", DB_QueryUPDATE ("can not unhide call for exam",
@ -683,7 +683,6 @@ static void Cfe_ListCallsForExams (struct Cfe_CallsForExams *CallsForExams,
extern const char *Txt_No_calls_for_exams_of_X; extern const char *Txt_No_calls_for_exams_of_X;
char SubQueryStatus[64]; char SubQueryStatus[64];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumExaAnn; unsigned long NumExaAnn;
unsigned long NumExaAnns; unsigned long NumExaAnns;
long ExaCod; long ExaCod;
@ -731,10 +730,8 @@ static void Cfe_ListCallsForExams (struct Cfe_CallsForExams *CallsForExams,
NumExaAnn++) NumExaAnn++)
{ {
/***** Get the code of the call for exam (row[0]) *****/ /***** Get the code of the call for exam (row[0]) *****/
row = mysql_fetch_row (mysql_res); if ((ExaCod = DB_GetNextCode (mysql_res)) <= 0)
Lay_WrongCallForExamExit ();
if (sscanf (row[0],"%ld",&ExaCod) != 1)
Lay_ShowErrorAndExit ("Wrong code of call for exam.");
/***** Allocate memory for the call for exam *****/ /***** Allocate memory for the call for exam *****/
Cfe_AllocMemCallForExam (CallsForExams); Cfe_AllocMemCallForExam (CallsForExams);
@ -934,7 +931,7 @@ void Cfe_CreateListCallsForExams (struct Cfe_CallsForExams *CallsForExams)
&CallsForExams->Lst[CallsForExams->NumCallsForExams].ExamDate.Year, &CallsForExams->Lst[CallsForExams->NumCallsForExams].ExamDate.Year,
&CallsForExams->Lst[CallsForExams->NumCallsForExams].ExamDate.Month, &CallsForExams->Lst[CallsForExams->NumCallsForExams].ExamDate.Month,
&CallsForExams->Lst[CallsForExams->NumCallsForExams].ExamDate.Day) != 3) &CallsForExams->Lst[CallsForExams->NumCallsForExams].ExamDate.Day) != 3)
Lay_ShowErrorAndExit ("Wrong date of exam."); Lay_WrongCallForExamExit ();
/***** Increment number of elements in list *****/ /***** Increment number of elements in list *****/
CallsForExams->NumCallsForExams++; CallsForExams->NumCallsForExams++;
@ -999,7 +996,7 @@ static void Cfe_GetDataCallForExamFromDB (struct Cfe_CallsForExams *CallsForExam
/***** The result of the query must have one row *****/ /***** The result of the query must have one row *****/
if (NumExaAnns != 1) if (NumExaAnns != 1)
Lay_ShowErrorAndExit ("Error when getting data of a call for exam."); Lay_WrongCallForExamExit ();
/***** Get the data of the call for exam *****/ /***** Get the data of the call for exam *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1009,9 +1006,9 @@ static void Cfe_GetDataCallForExamFromDB (struct Cfe_CallsForExams *CallsForExam
/* Status of the call for exam (row[1]) */ /* Status of the call for exam (row[1]) */
if (sscanf (row[1],"%u",&UnsignedNum) != 1) if (sscanf (row[1],"%u",&UnsignedNum) != 1)
Lay_ShowErrorAndExit ("Wrong status."); Lay_WrongCallForExamExit ();
if (UnsignedNum >= Cfe_NUM_STATUS) if (UnsignedNum >= Cfe_NUM_STATUS)
Lay_ShowErrorAndExit ("Wrong status."); Lay_WrongCallForExamExit ();
CallsForExams->CallForExam.Status = (Cfe_Status_t) UnsignedNum; CallsForExams->CallForExam.Status = (Cfe_Status_t) UnsignedNum;
/* Name of the course (row[2]) */ /* Name of the course (row[2]) */
@ -1020,7 +1017,7 @@ static void Cfe_GetDataCallForExamFromDB (struct Cfe_CallsForExams *CallsForExam
/* Year (row[3]) */ /* Year (row[3]) */
if (sscanf (row[3],"%u",&CallsForExams->CallForExam.Year) != 1) if (sscanf (row[3],"%u",&CallsForExams->CallForExam.Year) != 1)
Lay_ShowErrorAndExit ("Wrong year."); Lay_WrongCallForExamExit ();
/* Exam session (row[4]) */ /* Exam session (row[4]) */
Str_Copy (CallsForExams->CallForExam.Session,row[4], Str_Copy (CallsForExams->CallForExam.Session,row[4],
@ -1034,7 +1031,7 @@ static void Cfe_GetDataCallForExamFromDB (struct Cfe_CallsForExams *CallsForExam
&Hour, &Hour,
&Minute, &Minute,
&Second) != 6) &Second) != 6)
Lay_ShowErrorAndExit ("Wrong date of call for exam."); Lay_WrongCallForExamExit ();
/* Date of exam (row[6]) */ /* Date of exam (row[6]) */
if (sscanf (row[6],"%04u-%02u-%02u %02u:%02u:%02u", if (sscanf (row[6],"%04u-%02u-%02u %02u:%02u:%02u",
@ -1044,7 +1041,7 @@ static void Cfe_GetDataCallForExamFromDB (struct Cfe_CallsForExams *CallsForExam
&CallsForExams->CallForExam.StartTime.Hour, &CallsForExams->CallForExam.StartTime.Hour,
&CallsForExams->CallForExam.StartTime.Minute, &CallsForExams->CallForExam.StartTime.Minute,
&Second) != 6) &Second) != 6)
Lay_ShowErrorAndExit ("Wrong date of exam."); Lay_WrongCallForExamExit ();
snprintf (CallsForExams->CallForExam.ExamDate.YYYYMMDD, snprintf (CallsForExams->CallForExam.ExamDate.YYYYMMDD,
sizeof (CallsForExams->CallForExam.ExamDate.YYYYMMDD),"%04u%02u%02u", sizeof (CallsForExams->CallForExam.ExamDate.YYYYMMDD),"%04u%02u%02u",
CallsForExams->CallForExam.ExamDate.Year, CallsForExams->CallForExam.ExamDate.Year,
@ -1056,7 +1053,7 @@ static void Cfe_GetDataCallForExamFromDB (struct Cfe_CallsForExams *CallsForExam
&CallsForExams->CallForExam.Duration.Hour, &CallsForExams->CallForExam.Duration.Hour,
&CallsForExams->CallForExam.Duration.Minute, &CallsForExams->CallForExam.Duration.Minute,
&Second) != 3) &Second) != 3)
Lay_ShowErrorAndExit ("Wrong duration of exam."); Lay_WrongCallForExamExit ();
/* Place (row[8]), exam mode (row[9]), structure (row[10]), /* Place (row[8]), exam mode (row[9]), structure (row[10]),
documentation required (row[11]), material required (row[12]), documentation required (row[11]), material required (row[12]),

View File

@ -147,8 +147,8 @@ void Ctr_SeeCtrWithPendingDegs (void)
case Rol_SYS_ADM: case Rol_SYS_ADM:
NumCtrs = (unsigned) NumCtrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get centers with pending degrees", DB_QuerySELECT (&mysql_res,"can not get centers with pending degrees",
"SELECT deg_degrees.CtrCod," "SELECT deg_degrees.CtrCod," // row[0]
"COUNT(*)" "COUNT(*)" // row[1]
" FROM deg_degrees," " FROM deg_degrees,"
"ctr_centers" "ctr_centers"
" WHERE (deg_degrees.Status & %u)<>0" " WHERE (deg_degrees.Status & %u)<>0"
@ -795,29 +795,16 @@ static void Ctr_GetDataOfCenterFromRow (struct Ctr_Center *Ctr,MYSQL_ROW row)
long Ctr_GetInsCodOfCenterByCod (long CtrCod) long Ctr_GetInsCodOfCenterByCod (long CtrCod)
{ {
MYSQL_RES *mysql_res; /***** Trivial check: center code should be > 0 *****/
MYSQL_ROW row; if (CtrCod <= 0)
long InsCod = -1L; return -1L;
if (CtrCod > 0) /***** Get the institution code of a center from database *****/
{ return DB_QuerySELECTCode ("can not get the institution of a center",
/***** Get the institution code of a center from database *****/ "SELECT InsCod"
if (DB_QuerySELECT (&mysql_res,"can not get the institution of a center", " FROM ctr_centers"
"SELECT InsCod" " WHERE CtrCod=%ld",
" FROM ctr_centers" CtrCod);
" WHERE CtrCod=%ld",
CtrCod) == 1)
{
/***** Get the institution code of this center *****/
row = mysql_fetch_row (mysql_res);
InsCod = Str_ConvertStrCodToLongCod (row[0]);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
return InsCod;
} }
/*****************************************************************************/ /*****************************************************************************/
@ -834,7 +821,7 @@ void Ctr_GetShortNameOfCenterByCod (struct Ctr_Center *Ctr)
{ {
/***** Get the short name of a center from database *****/ /***** Get the short name of a center from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get the short name of a center", if (DB_QuerySELECT (&mysql_res,"can not get the short name of a center",
"SELECT ShortName" "SELECT ShortName" // row[0]
" FROM ctr_centers" " FROM ctr_centers"
" WHERE CtrCod=%ld", " WHERE CtrCod=%ld",
Ctr->CtrCod) == 1) Ctr->CtrCod) == 1)
@ -896,8 +883,8 @@ void Ctr_WriteSelectorOfCenter (void)
/***** Get centers from database *****/ /***** Get centers from database *****/
NumCtrs = (unsigned) NumCtrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get centers", DB_QuerySELECT (&mysql_res,"can not get centers",
"SELECT DISTINCT CtrCod," "SELECT DISTINCT CtrCod," // row[0]
"ShortName" "ShortName" // row[1]
" FROM ctr_centers" " FROM ctr_centers"
" WHERE InsCod=%ld" " WHERE InsCod=%ld"
" ORDER BY ShortName", " ORDER BY ShortName",

View File

@ -517,7 +517,7 @@ static void CtrCfg_GetPhotoAttr (long CtrCod,char **PhotoAttribution)
/***** Get photo attribution from database *****/ /***** Get photo attribution from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get photo attribution", if (DB_QuerySELECT (&mysql_res,"can not get photo attribution",
"SELECT PhotoAttribution" "SELECT PhotoAttribution" // row[0]
" FROM ctr_centers" " FROM ctr_centers"
" WHERE CtrCod=%ld", " WHERE CtrCod=%ld",
CtrCod)) CtrCod))

View File

@ -600,13 +600,14 @@ TODO: Salvador Romero Cort
TODO: FIX BUG, URGENT! En las fechas como parámetro Dat_WriteParamsIniEndDates(), por ejemplo al cambiar el color de la gráfica de accesos por día y hora, no se respeta la zona horaria. TODO: FIX BUG, URGENT! En las fechas como parámetro Dat_WriteParamsIniEndDates(), por ejemplo al cambiar el color de la gráfica de accesos por día y hora, no se respeta la zona horaria.
*/ */
#define Log_PLATFORM_VERSION "SWAD 20.55 (2021-04-04)" #define Log_PLATFORM_VERSION "SWAD 20.56 (2021-04-04)"
#define CSS_FILE "swad20.45.css" #define CSS_FILE "swad20.45.css"
#define JS_FILE "swad20.6.2.js" #define JS_FILE "swad20.6.2.js"
/* /*
TODO: Rename CENTRE to CENTER in help wiki. TODO: Rename CENTRE to CENTER in help wiki.
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
Version 20.56: Apr 04, 2021 Optimizations in database selects. (309296 lines)
Version 20.55: Apr 04, 2021 Optimizations in database selects. (309500 lines) Version 20.55: Apr 04, 2021 Optimizations in database selects. (309500 lines)
Version 20.54: Mar 30, 2021 Statistics about agendas. (309539 lines) Version 20.54: Mar 30, 2021 Statistics about agendas. (309539 lines)
Version 20.53.1: Mar 30, 2021 Optimizations in database selects. (309459 lines) Version 20.53.1: Mar 30, 2021 Optimizations in database selects. (309459 lines)

View File

@ -637,8 +637,8 @@ static void Con_GetNumConnectedUsrsWithARoleBelongingCurrentLocation (Rol_Role_t
break; break;
case Hie_Lvl_CTY: // Show connected users in the current country case Hie_Lvl_CTY: // Show connected users in the current country
DB_QuerySELECT (&mysql_res,"can not get number" DB_QuerySELECT (&mysql_res,"can not get number"
" of connected users" " of connected users"
" who belong to this location", " who belong to this location",
"SELECT COUNT(DISTINCT usr_connected.UsrCod)," // row[0] "SELECT COUNT(DISTINCT usr_connected.UsrCod)," // row[0]
"COUNT(DISTINCT usr_data.Sex)," // row[1] "COUNT(DISTINCT usr_data.Sex)," // row[1]
"MIN(usr_data.Sex)" // row[2] "MIN(usr_data.Sex)" // row[2]

View File

@ -271,7 +271,6 @@ static void CtyCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom)
static void CtyCfg_Map (void) static void CtyCfg_Map (void)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row;
struct Coordinates CtyAvgCoord; struct Coordinates CtyAvgCoord;
unsigned Zoom; unsigned Zoom;
unsigned NumCtrs; unsigned NumCtrs;
@ -317,10 +316,7 @@ static void CtyCfg_Map (void)
NumCtr++) NumCtr++)
{ {
/* Get next center */ /* Get next center */
row = mysql_fetch_row (mysql_res); Ctr.CtrCod = DB_GetNextCode (mysql_res);
/* Get center code (row[0]) */
Ctr.CtrCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get data of center */ /* Get data of center */
Ctr_GetDataOfCenterByCod (&Ctr); Ctr_GetDataOfCenterByCod (&Ctr);
@ -583,7 +579,7 @@ static void CtyCfg_GetMapAttr (long CtyCod,char **MapAttribution)
/***** Get photo attribution from database *****/ /***** Get photo attribution from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get photo attribution", if (DB_QuerySELECT (&mysql_res,"can not get photo attribution",
"SELECT MapAttribution" "SELECT MapAttribution" // row[0]
" FROM cty_countrs" " FROM cty_countrs"
" WHERE CtyCod=%ld", " WHERE CtyCod=%ld",
CtyCod)) CtyCod))

View File

@ -2992,7 +2992,6 @@ void Crs_RemoveOldCrss (void)
unsigned MonthsWithoutAccess; unsigned MonthsWithoutAccess;
unsigned long SecondsWithoutAccess; unsigned long SecondsWithoutAccess;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumCrs; unsigned long NumCrs;
unsigned long NumCrss; unsigned long NumCrss;
unsigned NumCrssRemoved = 0; unsigned NumCrssRemoved = 0;
@ -3029,8 +3028,7 @@ void Crs_RemoveOldCrss (void)
NumCrs < NumCrss; NumCrs < NumCrss;
NumCrs++) NumCrs++)
{ {
row = mysql_fetch_row (mysql_res); CrsCod = DB_GetNextCode (mysql_res);
CrsCod = Str_ConvertStrCodToLongCod (row[0]);
Crs_RemoveCourseCompletely (CrsCod); Crs_RemoveCourseCompletely (CrsCod);
NumCrssRemoved++; NumCrssRemoved++;
} }

View File

@ -3808,8 +3808,8 @@ unsigned long DB_QuerySELECT (MYSQL_RES **mysql_res,const char *MsgError,
/*** Make a SELECT query for a unique row with one long code from database ***/ /*** Make a SELECT query for a unique row with one long code from database ***/
/*****************************************************************************/ /*****************************************************************************/
long DB_QuerySELECTCod (const char *MsgError, long DB_QuerySELECTCode (const char *MsgError,
const char *fmt,...) const char *fmt,...)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
va_list ap; va_list ap;
@ -3826,7 +3826,7 @@ long DB_QuerySELECTCod (const char *MsgError,
/***** Do SELECT query *****/ /***** Do SELECT query *****/
if (DB_QuerySELECTusingQueryStr (Query,&mysql_res,MsgError)) // Row found if (DB_QuerySELECTusingQueryStr (Query,&mysql_res,MsgError)) // Row found
Cod = DB_GetNextCod (mysql_res); Cod = DB_GetNextCode (mysql_res);
else else
Cod = -1L; Cod = -1L;
@ -3870,7 +3870,7 @@ static unsigned long DB_QuerySELECTusingQueryStr (char *Query,
/*****************************************************************************/ /*****************************************************************************/
/* Each row of the result should hold a code (long) */ /* Each row of the result should hold a code (long) */
long DB_GetNextCod (MYSQL_RES *mysql_res) long DB_GetNextCode (MYSQL_RES *mysql_res)
{ {
MYSQL_ROW row; MYSQL_ROW row;

View File

@ -41,9 +41,9 @@ void DB_BuildQuery (char **Query,const char *fmt,...);
unsigned long DB_QuerySELECT (MYSQL_RES **mysql_res,const char *MsgError, unsigned long DB_QuerySELECT (MYSQL_RES **mysql_res,const char *MsgError,
const char *fmt,...); const char *fmt,...);
long DB_QuerySELECTCod (const char *MsgError, long DB_QuerySELECTCode (const char *MsgError,
const char *fmt,...); const char *fmt,...);
long DB_GetNextCod (MYSQL_RES *mysql_res); long DB_GetNextCode (MYSQL_RES *mysql_res);
unsigned long DB_GetNumRowsTable (const char *Table); unsigned long DB_GetNumRowsTable (const char *Table);
unsigned long DB_QueryCOUNT (const char *MsgError,const char *fmt,...); unsigned long DB_QueryCOUNT (const char *MsgError,const char *fmt,...);

View File

@ -802,7 +802,7 @@ void Dat_GetBrowserTimeZone (char BrowserTimeZone[Dat_MAX_BYTES_TIME_ZONE + 1])
/* Try to convert a date from server time zone to browser time zone */ /* Try to convert a date from server time zone to browser time zone */
if (DB_QuerySELECT (&mysql_res,"can not check if time zone name" if (DB_QuerySELECT (&mysql_res,"can not check if time zone name"
" is usable", " is usable",
"SELECT CONVERT_TZ(NOW(),@@session.time_zone,'%s')", "SELECT CONVERT_TZ(NOW(),@@session.time_zone,'%s')", // row[0]
BrowserTimeZone)) BrowserTimeZone))
{ {
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);

View File

@ -1438,7 +1438,7 @@ void Deg_GetShortNameOfDegreeByCod (struct Deg_Degree *Deg)
{ {
/***** Get the short name of a degree from database *****/ /***** Get the short name of a degree from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get the short name of a degree", if (DB_QuerySELECT (&mysql_res,"can not get the short name of a degree",
"SELECT ShortName" "SELECT ShortName" // row[0]
" FROM deg_degrees" " FROM deg_degrees"
" WHERE DegCod=%ld", " WHERE DegCod=%ld",
Deg->DegCod) == 1) Deg->DegCod) == 1)
@ -1459,29 +1459,16 @@ void Deg_GetShortNameOfDegreeByCod (struct Deg_Degree *Deg)
long Deg_GetCtrCodOfDegreeByCod (long DegCod) long Deg_GetCtrCodOfDegreeByCod (long DegCod)
{ {
MYSQL_RES *mysql_res; /***** Trivial check: degree code should be > 0 *****/
MYSQL_ROW row; if (DegCod <= 0)
long CtrCod = -1L; return -1L;
if (DegCod > 0) /***** Get the center code of a degree from database *****/
{ return DB_QuerySELECTCode ("can not get the center of a degree",
/***** Get the center code of a degree from database *****/ "SELECT CtrCod"
if (DB_QuerySELECT (&mysql_res,"can not get the center of a degree", " FROM deg_degrees"
"SELECT CtrCod" " WHERE DegCod=%ld",
" FROM deg_degrees" DegCod);
" WHERE DegCod=%ld",
DegCod) == 1)
{
/***** Get the center code of this degree *****/
row = mysql_fetch_row (mysql_res);
CtrCod = Str_ConvertStrCodToLongCod (row[0]);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
return CtrCod;
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1490,31 +1477,18 @@ long Deg_GetCtrCodOfDegreeByCod (long DegCod)
long Deg_GetInsCodOfDegreeByCod (long DegCod) long Deg_GetInsCodOfDegreeByCod (long DegCod)
{ {
MYSQL_RES *mysql_res; /***** Trivial check: degree code should be > 0 *****/
MYSQL_ROW row; if (DegCod <= 0)
long InsCod = -1L; return -1L;
if (DegCod > 0) /***** Get the institution code of a degree from database *****/
{ return DB_QuerySELECTCode ("can not get the institution of a degree",
/***** Get the institution code of a degree from database *****/ "SELECT ctr_centers.InsCod"
if (DB_QuerySELECT (&mysql_res,"can not get the institution of a degree", " FROM deg_degrees,"
"SELECT ctr_centers.InsCod" "ctr_centers"
" FROM deg_degrees," " WHERE deg_degrees.DegCod=%ld"
"ctr_centers" " AND deg_degrees.CtrCod=ctr_centers.CtrCod",
" WHERE deg_degrees.DegCod=%ld" DegCod);
" AND deg_degrees.CtrCod=ctr_centers.CtrCod",
DegCod) == 1)
{
/***** Get the institution code of this degree *****/
row = mysql_fetch_row (mysql_res);
InsCod = Str_ConvertStrCodToLongCod (row[0]);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
return InsCod;
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1524,7 +1498,6 @@ long Deg_GetInsCodOfDegreeByCod (long DegCod)
void Deg_RemoveDegreeCompletely (long DegCod) void Deg_RemoveDegreeCompletely (long DegCod)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows; unsigned long NumRows;
unsigned long NumRow; unsigned long NumRow;
long CrsCod; long CrsCod;
@ -1532,7 +1505,7 @@ void Deg_RemoveDegreeCompletely (long DegCod)
/***** Get courses of a degree from database *****/ /***** Get courses of a degree from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get courses of a degree", NumRows = DB_QuerySELECT (&mysql_res,"can not get courses of a degree",
"SELECT CrsCod" "SELECT CrsCod" // row[0]
" FROM crs_courses" " FROM crs_courses"
" WHERE DegCod=%ld", " WHERE DegCod=%ld",
DegCod); DegCod);
@ -1543,10 +1516,7 @@ void Deg_RemoveDegreeCompletely (long DegCod)
NumRow++) NumRow++)
{ {
/* Get next course */ /* Get next course */
row = mysql_fetch_row (mysql_res); if ((CrsCod = DB_GetNextCode (mysql_res)) < 0)
/* Get course code (row[0]) */
if ((CrsCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of course."); Lay_ShowErrorAndExit ("Wrong code of course.");
/* Remove course */ /* Remove course */

View File

@ -882,7 +882,7 @@ bool DT_GetDataOfDegreeTypeByCod (struct DegreeType *DegTyp)
/***** Get the name of a type of degree from database *****/ /***** Get the name of a type of degree from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get the name of a type of degree", NumRows = DB_QuerySELECT (&mysql_res,"can not get the name of a type of degree",
"SELECT DegTypName" "SELECT DegTypName" // row[0]
" FROM deg_types" " FROM deg_types"
" WHERE DegTypCod=%ld", " WHERE DegTypCod=%ld",
DegTyp->DegTypCod); DegTyp->DegTypCod);
@ -923,14 +923,13 @@ bool DT_GetDataOfDegreeTypeByCod (struct DegreeType *DegTyp)
static void DT_RemoveDegreeTypeCompletely (long DegTypCod) static void DT_RemoveDegreeTypeCompletely (long DegTypCod)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows; unsigned long NumRows;
unsigned long NumRow; unsigned long NumRow;
long DegCod; long DegCod;
/***** Get degrees of a type from database *****/ /***** Get degrees of a type from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get degrees of a type", NumRows = DB_QuerySELECT (&mysql_res,"can not get degrees of a type",
"SELECT DegCod" "SELECT DegCod" // row[0]
" FROM deg_degrees" " FROM deg_degrees"
" WHERE DegTypCod=%ld", " WHERE DegTypCod=%ld",
DegTypCod); DegTypCod);
@ -941,10 +940,7 @@ static void DT_RemoveDegreeTypeCompletely (long DegTypCod)
NumRow++) NumRow++)
{ {
/* Get next degree */ /* Get next degree */
row = mysql_fetch_row (mysql_res); if ((DegCod = DB_GetNextCode (mysql_res)) < 0)
/* Get degree code (row[0]) */
if ((DegCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of degree."); Lay_ShowErrorAndExit ("Wrong code of degree.");
/* Remove degree */ /* Remove degree */
@ -956,7 +952,8 @@ static void DT_RemoveDegreeTypeCompletely (long DegTypCod)
/***** Remove the degree type *****/ /***** Remove the degree type *****/
DB_QueryDELETE ("can not remove a type of degree", DB_QueryDELETE ("can not remove a type of degree",
"DELETE FROM deg_types WHERE DegTypCod=%ld", "DELETE FROM deg_types"
" WHERE DegTypCod=%ld",
DegTypCod); DegTypCod);
} }

View File

@ -146,9 +146,9 @@ void Dup_ListDuplicateUsrs (void)
/***** Make query *****/ /***** Make query *****/
NumUsrs = (unsigned) NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get possibly duplicate users", DB_QuerySELECT (&mysql_res,"can not get possibly duplicate users",
"SELECT UsrCod," "SELECT UsrCod," // row[0]
"COUNT(*) AS N," "COUNT(*) AS N," // row[1]
"UNIX_TIMESTAMP(MIN(InformTime)) AS T" "UNIX_TIMESTAMP(MIN(InformTime)) AS T" // row[2]
" FROM usr_duplicated" " FROM usr_duplicated"
" GROUP BY UsrCod" " GROUP BY UsrCod"
" ORDER BY N DESC," " ORDER BY N DESC,"
@ -263,7 +263,6 @@ static void Dup_ListSimilarUsrs (void)
extern const char *Txt_Similar_users; extern const char *Txt_Similar_users;
struct UsrData UsrDat; struct UsrData UsrDat;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumUsrs; unsigned NumUsrs;
unsigned NumUsr; unsigned NumUsr;
@ -325,10 +324,8 @@ static void Dup_ListSimilarUsrs (void)
NumUsr < NumUsrs; NumUsr < NumUsrs;
NumUsr++) NumUsr++)
{ {
row = mysql_fetch_row (mysql_res); /* Get user code */
UsrDat.UsrCod = DB_GetNextCode (mysql_res);
/* Get user code (row[0]) */
UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]);
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS)) if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS))
{ {
/* Get if user has accepted all his/her courses */ /* Get if user has accepted all his/her courses */

View File

@ -515,9 +515,8 @@ void Enr_GetNotifEnrolment (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
SummaryStr[0] = '\0'; // Return nothing on error SummaryStr[0] = '\0'; // Return nothing on error
/***** Get user's role in course from database *****/ /***** Get user's role in course from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get user's role" if (DB_QuerySELECT (&mysql_res,"can not get user's role in course",
" in course", "SELECT Role" // row[0]
"SELECT Role"
" FROM crs_users" " FROM crs_users"
" WHERE CrsCod=%ld" " WHERE CrsCod=%ld"
" AND UsrCod=%ld", " AND UsrCod=%ld",
@ -866,7 +865,6 @@ void Enr_RemoveOldUsrs (void)
unsigned MonthsWithoutAccess; unsigned MonthsWithoutAccess;
time_t SecondsWithoutAccess; time_t SecondsWithoutAccess;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumUsr; unsigned long NumUsr;
unsigned long NumUsrs; unsigned long NumUsrs;
unsigned NumUsrsEliminated = 0; unsigned NumUsrsEliminated = 0;
@ -884,14 +882,17 @@ void Enr_RemoveOldUsrs (void)
/***** Get old users from database *****/ /***** Get old users from database *****/
NumUsrs = DB_QuerySELECT (&mysql_res,"can not get old users", NumUsrs = DB_QuerySELECT (&mysql_res,"can not get old users",
"SELECT UsrCod FROM" "SELECT UsrCod"
"(" " FROM (SELECT UsrCod"
"SELECT UsrCod FROM usr_last WHERE" " FROM usr_last"
" LastTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)" " WHERE LastTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)"
" UNION " " UNION "
"SELECT UsrCod FROM usr_data WHERE" "SELECT UsrCod"
" UsrCod NOT IN (SELECT UsrCod FROM usr_last)" " FROM usr_data"
") AS candidate_usrs" " WHERE UsrCod NOT IN"
" (SELECT UsrCod"
" FROM usr_last)"
") AS candidate_usrs"
" WHERE UsrCod NOT IN" " WHERE UsrCod NOT IN"
" (SELECT DISTINCT UsrCod" " (SELECT DISTINCT UsrCod"
" FROM crs_users)", " FROM crs_users)",
@ -911,8 +912,7 @@ void Enr_RemoveOldUsrs (void)
NumUsr < NumUsrs; NumUsr < NumUsrs;
NumUsr++) NumUsr++)
{ {
row = mysql_fetch_row (mysql_res); UsrDat.UsrCod = DB_GetNextCode (mysql_res);
UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]);
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS)) // If user's data exist... if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS)) // If user's data exist...
{ {
Acc_CompletelyEliminateAccount (&UsrDat,Cns_QUIET); Acc_CompletelyEliminateAccount (&UsrDat,Cns_QUIET);
@ -1973,8 +1973,6 @@ void Enr_SignUpInCrs (void)
extern const char *Txt_You_were_already_enroled_as_X_in_the_course_Y; extern const char *Txt_You_were_already_enroled_as_X_in_the_course_Y;
extern const char *Txt_ROLES_SINGUL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS]; extern const char *Txt_ROLES_SINGUL_abc[Rol_NUM_ROLES][Usr_NUM_SEXS];
extern const char *Txt_Your_request_for_enrolment_as_X_in_the_course_Y_has_been_accepted_for_processing; extern const char *Txt_Your_request_for_enrolment_as_X_in_the_course_Y_has_been_accepted_for_processing;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
Rol_Role_t RoleFromForm; Rol_Role_t RoleFromForm;
bool Notify; bool Notify;
long ReqCod = -1L; long ReqCod = -1L;
@ -2000,20 +1998,13 @@ void Enr_SignUpInCrs (void)
Rol_WrongRoleExit (); Rol_WrongRoleExit ();
/***** Try to get and old request of the same user in the same course from database *****/ /***** Try to get and old request of the same user in the same course from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get enrolment request", ReqCod = DB_QuerySELECTCode ("can not get enrolment request",
"SELECT ReqCod" "SELECT ReqCod"
" FROM crs_requests" " FROM crs_requests"
" WHERE CrsCod=%ld" " WHERE CrsCod=%ld"
" AND UsrCod=%ld", " AND UsrCod=%ld",
Gbl.Hierarchy.Crs.CrsCod, Gbl.Hierarchy.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod)) Gbl.Usrs.Me.UsrDat.UsrCod);
{
row = mysql_fetch_row (mysql_res);
/* Get request code (row[0]) */
ReqCod = Str_ConvertStrCodToLongCod (row[0]);
}
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
/***** Request user in current course in database *****/ /***** Request user in current course in database *****/
if (ReqCod > 0) // Old request exists in database if (ReqCod > 0) // Old request exists in database
@ -3049,29 +3040,21 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
static void Enr_RemoveEnrolmentRequest (long CrsCod,long UsrCod) static void Enr_RemoveEnrolmentRequest (long CrsCod,long UsrCod)
{ {
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long ReqCod; long ReqCod;
/***** Mark possible notifications as removed /***** Mark possible notifications as removed
Important: do this before removing the request *****/ Important: do this before removing the request *****/
/* Request request code (returns 0 or 1 rows) */ /* Request request code (returns 0 or 1 rows) */
if (DB_QuerySELECT (&mysql_res,"can not get request code", ReqCod = DB_QuerySELECTCode ("can not get request code",
"SELECT ReqCod" "SELECT ReqCod"
" FROM crs_requests" " FROM crs_requests"
" WHERE CrsCod=%ld" " WHERE CrsCod=%ld"
" AND UsrCod=%ld", " AND UsrCod=%ld",
CrsCod,UsrCod)) // Request exists CrsCod,
{ UsrCod);
/* Get request code */
row = mysql_fetch_row (mysql_res);
ReqCod = Str_ConvertStrCodToLongCod (row[0]);
/* Mark possible notifications as removed */ /* Mark possible notifications as removed */
Ntf_MarkNotifAsRemoved (Ntf_EVENT_ENROLMENT_REQUEST,ReqCod); Ntf_MarkNotifAsRemoved (Ntf_EVENT_ENROLMENT_REQUEST,ReqCod);
}
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
/***** Remove enrolment request *****/ /***** Remove enrolment request *****/
DB_QueryDELETE ("can not remove a request for enrolment", DB_QueryDELETE ("can not remove a request for enrolment",

View File

@ -1774,12 +1774,14 @@ long Exa_GetQstCodFromQstInd (long ExaCod,unsigned QstInd)
long QstCod; long QstCod;
/***** Get question code of the question to be moved up *****/ /***** Get question code of the question to be moved up *****/
if (!DB_QuerySELECT (&mysql_res,"can not get question code", QstCod = DB_QuerySELECTCode ("can not get question code",
"SELECT QstCod" "SELECT QstCod"
" FROM exa_set_questions" " FROM exa_set_questions"
" WHERE ExaCod=%ld" " WHERE ExaCod=%ld"
" AND QstInd=%u", " AND QstInd=%u",
ExaCod,QstInd)) ExaCod,
QstInd);
if (QstCod <= 0)
Lay_ShowErrorAndExit ("Error: wrong question index."); Lay_ShowErrorAndExit ("Error: wrong question index.");
/***** Get question code (row[0]) *****/ /***** Get question code (row[0]) *****/
@ -1809,7 +1811,7 @@ unsigned Exa_GetPrevQuestionIndexInExam (long ExaCod,unsigned QstInd)
// Although indexes are always continuous... // Although indexes are always continuous...
// ...this implementation works even with non continuous indexes // ...this implementation works even with non continuous indexes
if (!DB_QuerySELECT (&mysql_res,"can not get previous question index", if (!DB_QuerySELECT (&mysql_res,"can not get previous question index",
"SELECT MAX(QstInd)" "SELECT MAX(QstInd)" // row[0]
" FROM exa_set_questions" " FROM exa_set_questions"
" WHERE ExaCod=%ld" " WHERE ExaCod=%ld"
" AND QstInd<%u", " AND QstInd<%u",
@ -1846,7 +1848,7 @@ unsigned Exa_GetNextQuestionIndexInExam (long ExaCod,unsigned QstInd)
// Although indexes are always continuous... // Although indexes are always continuous...
// ...this implementation works even with non continuous indexes // ...this implementation works even with non continuous indexes
if (!DB_QuerySELECT (&mysql_res,"can not get next question index", if (!DB_QuerySELECT (&mysql_res,"can not get next question index",
"SELECT MIN(QstInd)" "SELECT MIN(QstInd)" // row[0]
" FROM exa_set_questions" " FROM exa_set_questions"
" WHERE ExaCod=%ld" " WHERE ExaCod=%ld"
" AND QstInd>%u", " AND QstInd>%u",
@ -1899,87 +1901,67 @@ bool Exa_CheckIfEditable (const struct Exa_Exam *Exam)
unsigned Exa_GetNumCoursesWithExams (Hie_Lvl_Level_t Scope) unsigned Exa_GetNumCoursesWithExams (Hie_Lvl_Level_t Scope)
{ {
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumCourses;
/***** Get number of courses with exams from database *****/ /***** Get number of courses with exams from database *****/
switch (Scope) switch (Scope)
{ {
case Hie_Lvl_SYS: case Hie_Lvl_SYS:
DB_QuerySELECT (&mysql_res,"can not get number of courses with exams", return DB_QueryCOUNT ("can not get number of courses with exams",
"SELECT COUNT(DISTINCT CrsCod)" "SELECT COUNT(DISTINCT CrsCod)"
" FROM exa_exams"); " FROM exa_exams");
break;
case Hie_Lvl_CTY: case Hie_Lvl_CTY:
DB_QuerySELECT (&mysql_res,"can not get number of courses with exams", return DB_QueryCOUNT ("can not get number of courses with exams",
"SELECT COUNT(DISTINCT exa_exams.CrsCod)" "SELECT COUNT(DISTINCT exa_exams.CrsCod)"
" FROM ins_instits," " FROM ins_instits,"
"ctr_centers," "ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"exa_exams" "exa_exams"
" WHERE ins_instits.CtyCod=%ld" " WHERE ins_instits.CtyCod=%ld"
" AND ins_instits.InsCod=ctr_centers.InsCod" " AND ins_instits.InsCod=ctr_centers.InsCod"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=exa_exams.CrsCod", " AND crs_courses.CrsCod=exa_exams.CrsCod",
Gbl.Hierarchy.Ins.InsCod); Gbl.Hierarchy.Ins.InsCod);
break;
case Hie_Lvl_INS: case Hie_Lvl_INS:
DB_QuerySELECT (&mysql_res,"can not get number of courses with exams", return DB_QueryCOUNT ("can not get number of courses with exams",
"SELECT COUNT(DISTINCT exa_exams.CrsCod)" "SELECT COUNT(DISTINCT exa_exams.CrsCod)"
" FROM ctr_centers," " FROM ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"exa_exams" "exa_exams"
" WHERE ctr_centers.InsCod=%ld" " WHERE ctr_centers.InsCod=%ld"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=exa_exams.CrsCod", " AND crs_courses.CrsCod=exa_exams.CrsCod",
Gbl.Hierarchy.Ins.InsCod); Gbl.Hierarchy.Ins.InsCod);
break;
case Hie_Lvl_CTR: case Hie_Lvl_CTR:
DB_QuerySELECT (&mysql_res,"can not get number of courses with exams", return DB_QueryCOUNT ("can not get number of courses with exams",
"SELECT COUNT(DISTINCT exa_exams.CrsCod)" "SELECT COUNT(DISTINCT exa_exams.CrsCod)"
" FROM deg_degrees," " FROM deg_degrees,"
"crs_courses," "crs_courses,"
"exa_exams" "exa_exams"
" WHERE deg_degrees.CtrCod=%ld" " WHERE deg_degrees.CtrCod=%ld"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=exa_exams.CrsCod", " AND crs_courses.CrsCod=exa_exams.CrsCod",
Gbl.Hierarchy.Ctr.CtrCod); Gbl.Hierarchy.Ctr.CtrCod);
break;
case Hie_Lvl_DEG: case Hie_Lvl_DEG:
DB_QuerySELECT (&mysql_res,"can not get number of courses with exams", return DB_QueryCOUNT ("can not get number of courses with exams",
"SELECT COUNT(DISTINCT exa_exams.CrsCod)" "SELECT COUNT(DISTINCT exa_exams.CrsCod)"
" FROM crs_courses," " FROM crs_courses,"
"exa_exams" "exa_exams"
" WHERE crs_courses.DegCod=%ld" " WHERE crs_courses.DegCod=%ld"
" AND crs_courses.CrsCod=exa_exams.CrsCod", " AND crs_courses.CrsCod=exa_exams.CrsCod",
Gbl.Hierarchy.Deg.DegCod); Gbl.Hierarchy.Deg.DegCod);
break;
case Hie_Lvl_CRS: case Hie_Lvl_CRS:
DB_QuerySELECT (&mysql_res,"can not get number of courses with exams", return DB_QueryCOUNT ("can not get number of courses with exams",
"SELECT COUNT(DISTINCT CrsCod)" "SELECT COUNT(DISTINCT CrsCod)"
" FROM exa_exams" " FROM exa_exams"
" WHERE CrsCod=%ld", " WHERE CrsCod=%ld",
Gbl.Hierarchy.Crs.CrsCod); Gbl.Hierarchy.Crs.CrsCod);
break;
default: default:
Lay_WrongScopeExit (); Lay_WrongScopeExit ();
break; return 0; // Not reached
} }
/***** Get number of exams *****/
row = mysql_fetch_row (mysql_res);
if (sscanf (row[0],"%u",&NumCourses) != 1)
Lay_ShowErrorAndExit ("Error when getting number of courses with exams.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumCourses;
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1989,87 +1971,67 @@ unsigned Exa_GetNumCoursesWithExams (Hie_Lvl_Level_t Scope)
unsigned Exa_GetNumExams (Hie_Lvl_Level_t Scope) unsigned Exa_GetNumExams (Hie_Lvl_Level_t Scope)
{ {
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumExams;
/***** Get number of exams from database *****/ /***** Get number of exams from database *****/
switch (Scope) switch (Scope)
{ {
case Hie_Lvl_SYS: case Hie_Lvl_SYS:
DB_QuerySELECT (&mysql_res,"can not get number of exams", return DB_QueryCOUNT ("can not get number of exams",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM exa_exams"); " FROM exa_exams");
break;
case Hie_Lvl_CTY: case Hie_Lvl_CTY:
DB_QuerySELECT (&mysql_res,"can not get number of exams", return DB_QueryCOUNT ("can not get number of exams",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM ins_instits," " FROM ins_instits,"
"ctr_centers," "ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"exa_exams" "exa_exams"
" WHERE ins_instits.CtyCod=%ld" " WHERE ins_instits.CtyCod=%ld"
" AND ins_instits.InsCod=ctr_centers.InsCod" " AND ins_instits.InsCod=ctr_centers.InsCod"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=exa_exams.CrsCod", " AND crs_courses.CrsCod=exa_exams.CrsCod",
Gbl.Hierarchy.Cty.CtyCod); Gbl.Hierarchy.Cty.CtyCod);
break;
case Hie_Lvl_INS: case Hie_Lvl_INS:
DB_QuerySELECT (&mysql_res,"can not get number of exams", return DB_QueryCOUNT ("can not get number of exams",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM ctr_centers," " FROM ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
"exa_exams" "exa_exams"
" WHERE ctr_centers.InsCod=%ld" " WHERE ctr_centers.InsCod=%ld"
" AND ctr_centers.CtrCod=deg_degrees.CtrCod" " AND ctr_centers.CtrCod=deg_degrees.CtrCod"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=exa_exams.CrsCod", " AND crs_courses.CrsCod=exa_exams.CrsCod",
Gbl.Hierarchy.Ins.InsCod); Gbl.Hierarchy.Ins.InsCod);
break;
case Hie_Lvl_CTR: case Hie_Lvl_CTR:
DB_QuerySELECT (&mysql_res,"can not get number of exams", return DB_QueryCOUNT ("can not get number of exams",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM deg_degrees," " FROM deg_degrees,"
"crs_courses," "crs_courses,"
"exa_exams" "exa_exams"
" WHERE deg_degrees.CtrCod=%ld" " WHERE deg_degrees.CtrCod=%ld"
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=exa_exams.CrsCod", " AND crs_courses.CrsCod=exa_exams.CrsCod",
Gbl.Hierarchy.Ctr.CtrCod); Gbl.Hierarchy.Ctr.CtrCod);
break;
case Hie_Lvl_DEG: case Hie_Lvl_DEG:
DB_QuerySELECT (&mysql_res,"can not get number of exams", return DB_QueryCOUNT ("can not get number of exams",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM crs_courses," " FROM crs_courses,"
"exa_exams" "exa_exams"
" WHERE crs_courses.DegCod=%ld" " WHERE crs_courses.DegCod=%ld"
" AND crs_courses.CrsCod=exa_exams.CrsCod", " AND crs_courses.CrsCod=exa_exams.CrsCod",
Gbl.Hierarchy.Deg.DegCod); Gbl.Hierarchy.Deg.DegCod);
break;
case Hie_Lvl_CRS: case Hie_Lvl_CRS:
DB_QuerySELECT (&mysql_res,"can not get number of exams", return DB_QueryCOUNT ("can not get number of exams",
"SELECT COUNT(*)" "SELECT COUNT(*)"
" FROM exa_exams" " FROM exa_exams"
" WHERE CrsCod=%ld", " WHERE CrsCod=%ld",
Gbl.Hierarchy.Crs.CrsCod); Gbl.Hierarchy.Crs.CrsCod);
break;
default: default:
Lay_WrongScopeExit (); Lay_WrongScopeExit ();
break; return 0; // Not reached
} }
/***** Get number of exams *****/
row = mysql_fetch_row (mysql_res);
if (sscanf (row[0],"%u",&NumExams) != 1)
Lay_ShowErrorAndExit ("Error when getting number of exams.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumExams;
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2087,7 +2049,7 @@ double Exa_GetNumQstsPerCrsExam (Hie_Lvl_Level_t Scope)
{ {
case Hie_Lvl_SYS: case Hie_Lvl_SYS:
DB_QuerySELECT (&mysql_res,"can not get number of questions per exam", DB_QuerySELECT (&mysql_res,"can not get number of questions per exam",
"SELECT AVG(NumQsts)" "SELECT AVG(NumQsts)" // row[0]
" FROM (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts" " FROM (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts"
" FROM exa_exams," " FROM exa_exams,"
"exa_set_questions" "exa_set_questions"
@ -2096,7 +2058,7 @@ double Exa_GetNumQstsPerCrsExam (Hie_Lvl_Level_t Scope)
break; break;
case Hie_Lvl_CTY: case Hie_Lvl_CTY:
DB_QuerySELECT (&mysql_res,"can not get number of questions per exam", DB_QuerySELECT (&mysql_res,"can not get number of questions per exam",
"SELECT AVG(NumQsts)" "SELECT AVG(NumQsts)" // row[0]
" FROM (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts" " FROM (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts"
" FROM ins_instits," " FROM ins_instits,"
"ctr_centers," "ctr_centers,"
@ -2115,7 +2077,7 @@ double Exa_GetNumQstsPerCrsExam (Hie_Lvl_Level_t Scope)
break; break;
case Hie_Lvl_INS: case Hie_Lvl_INS:
DB_QuerySELECT (&mysql_res,"can not get number of questions per exam", DB_QuerySELECT (&mysql_res,"can not get number of questions per exam",
"SELECT AVG(NumQsts)" "SELECT AVG(NumQsts)" // row[0]
" FROM (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts" " FROM (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts"
" FROM ctr_centers," " FROM ctr_centers,"
"deg_degrees," "deg_degrees,"
@ -2132,7 +2094,7 @@ double Exa_GetNumQstsPerCrsExam (Hie_Lvl_Level_t Scope)
break; break;
case Hie_Lvl_CTR: case Hie_Lvl_CTR:
DB_QuerySELECT (&mysql_res,"can not get number of questions per exam", DB_QuerySELECT (&mysql_res,"can not get number of questions per exam",
"SELECT AVG(NumQsts)" "SELECT AVG(NumQsts)" // row[0]
" FROM (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts" " FROM (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts"
" FROM deg_degrees," " FROM deg_degrees,"
"crs_courses," "crs_courses,"
@ -2147,7 +2109,7 @@ double Exa_GetNumQstsPerCrsExam (Hie_Lvl_Level_t Scope)
break; break;
case Hie_Lvl_DEG: case Hie_Lvl_DEG:
DB_QuerySELECT (&mysql_res,"can not get number of questions per exam", DB_QuerySELECT (&mysql_res,"can not get number of questions per exam",
"SELECT AVG(NumQsts)" "SELECT AVG(NumQsts)" // row[0]
" FROM (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts" " FROM (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts"
" FROM crs_courses," " FROM crs_courses,"
"exa_exams," "exa_exams,"
@ -2160,7 +2122,7 @@ double Exa_GetNumQstsPerCrsExam (Hie_Lvl_Level_t Scope)
break; break;
case Hie_Lvl_CRS: case Hie_Lvl_CRS:
DB_QuerySELECT (&mysql_res,"can not get number of questions per exam", DB_QuerySELECT (&mysql_res,"can not get number of questions per exam",
"SELECT AVG(NumQsts)" "SELECT AVG(NumQsts)" // row[0]
" FROM (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts" " FROM (SELECT COUNT(exa_set_questions.QstCod) AS NumQsts"
" FROM exa_exams," " FROM exa_exams,"
"exa_set_questions" "exa_set_questions"
@ -2190,39 +2152,22 @@ double Exa_GetNumQstsPerCrsExam (Hie_Lvl_Level_t Scope)
void Exa_GetScoreRange (long ExaCod,double *MinScore,double *MaxScore) void Exa_GetScoreRange (long ExaCod,double *MinScore,double *MaxScore)
{ {
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumRows;
unsigned NumRow;
unsigned NumAnswers; unsigned NumAnswers;
/***** Get maximum score of an exam from database *****/ /***** Get number of answers of exam from database *****/
NumRows = (unsigned) NumAnswers = DB_QueryCOUNT ("can not get data of a question",
DB_QuerySELECT (&mysql_res,"can not get data of a question", "SELECT COUNT(tst_answers.AnsInd)"
"SELECT COUNT(tst_answers.AnsInd) AS N" " FROM tst_answers,"
" FROM tst_answers," "exa_set_questions"
"exa_set_questions" " WHERE exa_set_questions.ExaCod=%ld"
" WHERE exa_set_questions.ExaCod=%ld" " AND exa_set_questions.QstCod=tst_answers.QstCod"
" AND exa_set_questions.QstCod=tst_answers.QstCod" " GROUP BY tst_answers.QstCod",
" GROUP BY tst_answers.QstCod", ExaCod);
ExaCod); if (NumAnswers < 2)
for (NumRow = 0, *MinScore = *MaxScore = 0.0; Lay_ShowErrorAndExit ("Wrong number of answers.");
NumRow < NumRows;
NumRow++)
{
row = mysql_fetch_row (mysql_res);
/* Get min answers (row[0]) */ /***** Set minimum and maximum scores *****/
if (sscanf (row[0],"%u",&NumAnswers) != 1) *MinScore = *MaxScore = 0.0;
NumAnswers = 0; *MinScore += -1.0 / (double) (NumAnswers - 1);
*MaxScore += 1.0;
/* Accumulate minimum and maximum score */
if (NumAnswers < 2)
Lay_ShowErrorAndExit ("Wrong number of answers.");
*MinScore += -1.0 / (double) (NumAnswers - 1);
*MaxScore += 1.0;
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
} }

View File

@ -307,22 +307,22 @@ void ExaLog_ShowExamLog (const struct ExaPrn_Print *Print)
/***** Get print log from database *****/ /***** Get print log from database *****/
NumClicks = (unsigned) NumClicks = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get exam print log", DB_QuerySELECT (&mysql_res,"can not get exam print log",
"SELECT exa_log.ActCod," // row[0] "SELECT exa_log.ActCod," // row[0]
"exa_log.QstInd," // row[1] "exa_log.QstInd," // row[1]
"exa_log.CanAnswer," // row[2] "exa_log.CanAnswer," // row[2]
"UNIX_TIMESTAMP(exa_log.ClickTime)," // row[3] "UNIX_TIMESTAMP(exa_log.ClickTime)," // row[3]
"exa_log.IP," // row[4] "exa_log.IP," // row[4]
"exa_log_sessions.SessionId," // row[5] "exa_log_sessions.SessionId," // row[5]
"exa_log_user_agents.UserAgent" // row[6] "exa_log_user_agents.UserAgent" // row[6]
" FROM exa_log" " FROM exa_log"
" LEFT JOIN exa_log_sessions" " LEFT JOIN exa_log_sessions"
" ON exa_log.LogCod=exa_log_sessions.LogCod" " ON exa_log.LogCod=exa_log_sessions.LogCod"
" LEFT JOIN exa_log_user_agents" " LEFT JOIN exa_log_user_agents"
" ON exa_log.LogCod=exa_log_user_agents.LogCod" " ON exa_log.LogCod=exa_log_user_agents.LogCod"
" WHERE exa_log.PrnCod=%ld" " WHERE exa_log.PrnCod=%ld"
" ORDER BY exa_log.LogCod", " ORDER BY exa_log.LogCod",
Print->PrnCod); Print->PrnCod);
if (NumClicks) if (NumClicks)
{ {

View File

@ -370,14 +370,14 @@ static void ExaPrn_GetQuestionsForNewPrintFromDB (struct ExaPrn_Print *Print,lon
/***** Get data of set of questions from database *****/ /***** Get data of set of questions from database *****/
NumSets = (unsigned) NumSets = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get sets of questions", DB_QuerySELECT (&mysql_res,"can not get sets of questions",
"SELECT SetCod," // row[0] "SELECT SetCod," // row[0]
"NumQstsToPrint," // row[1] "NumQstsToPrint," // row[1]
"Title" // row[2] "Title" // row[2]
" FROM exa_sets" " FROM exa_sets"
" WHERE ExaCod=%ld" " WHERE ExaCod=%ld"
" ORDER BY SetInd", " ORDER BY SetInd",
ExaCod); ExaCod);
/***** Get questions from all sets *****/ /***** Get questions from all sets *****/
Print->NumQsts.All = 0; Print->NumQsts.All = 0;
@ -436,16 +436,16 @@ static unsigned ExaPrn_GetSomeQstsFromSetToPrint (struct ExaPrn_Print *Print,
/***** Get questions from database *****/ /***** Get questions from database *****/
NumQstsInSet = (unsigned) NumQstsInSet = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get questions from set", DB_QuerySELECT (&mysql_res,"can not get questions from set",
"SELECT QstCod," // row[0] "SELECT QstCod," // row[0]
"AnsType," // row[1] "AnsType," // row[1]
"Shuffle" // row[2] "Shuffle" // row[2]
" FROM exa_set_questions" " FROM exa_set_questions"
" WHERE SetCod=%ld" " WHERE SetCod=%ld"
" ORDER BY RAND()" // Don't use RAND(NOW()) because the same ordering will be repeated across sets " ORDER BY RAND()" // Don't use RAND(NOW()) because the same ordering will be repeated across sets
" LIMIT %u", " LIMIT %u",
Set->SetCod, Set->SetCod,
Set->NumQstsToPrint); Set->NumQstsToPrint);
/***** Questions in this set *****/ /***** Questions in this set *****/
for (NumQstInSet = 0; for (NumQstInSet = 0;
@ -609,18 +609,17 @@ void ExaPrn_GetPrintQuestionsFromDB (struct ExaPrn_Print *Print)
unsigned NumQst; unsigned NumQst;
/***** Get questions of an exam print from database *****/ /***** Get questions of an exam print from database *****/
Print->NumQsts.All = Print->NumQsts.All = (unsigned)
(unsigned) DB_QuerySELECT (&mysql_res,"can not get questions" DB_QuerySELECT (&mysql_res,"can not get questions of an exam print",
" of an exam print", "SELECT QstCod," // row[0]
"SELECT QstCod," // row[0] "SetCod," // row[1]
"SetCod," // row[1] "Score," // row[2]
"Score," // row[2] "Indexes," // row[3]
"Indexes," // row[3] "Answers" // row[4]
"Answers" // row[4] " FROM exa_print_questions"
" FROM exa_print_questions" " WHERE PrnCod=%ld"
" WHERE PrnCod=%ld" " ORDER BY QstInd",
" ORDER BY QstInd", Print->PrnCod);
Print->PrnCod);
/***** Get questions *****/ /***** Get questions *****/
if (Print->NumQsts.All <= ExaPrn_MAX_QUESTIONS_PER_EXAM_PRINT) if (Print->NumQsts.All <= ExaPrn_MAX_QUESTIONS_PER_EXAM_PRINT)
@ -1273,12 +1272,12 @@ static void ExaPrn_GetCorrectIntAnswerFromDB (struct Tst_Question *Question)
MYSQL_ROW row; MYSQL_ROW row;
/***** Query database *****/ /***** Query database *****/
Question->Answer.NumOptions = Question->Answer.NumOptions = (unsigned)
(unsigned) DB_QuerySELECT (&mysql_res,"can not get answers of a question", DB_QuerySELECT (&mysql_res,"can not get answers of a question",
"SELECT Answer" // row[0] "SELECT Answer" // row[0]
" FROM exa_set_answers" " FROM exa_set_answers"
" WHERE QstCod=%ld", " WHERE QstCod=%ld",
Question->QstCod); Question->QstCod);
/***** Check if number of rows is correct *****/ /***** Check if number of rows is correct *****/
Tst_CheckIfNumberOfAnswersIsOne (Question); Tst_CheckIfNumberOfAnswersIsOne (Question);
@ -1300,12 +1299,12 @@ static void ExaPrn_GetCorrectFltAnswerFromDB (struct Tst_Question *Question)
double Tmp; double Tmp;
/***** Query database *****/ /***** Query database *****/
Question->Answer.NumOptions = Question->Answer.NumOptions = (unsigned)
(unsigned) DB_QuerySELECT (&mysql_res,"can not get answers of a question", DB_QuerySELECT (&mysql_res,"can not get answers of a question",
"SELECT Answer" // row[0] "SELECT Answer" // row[0]
" FROM exa_set_answers" " FROM exa_set_answers"
" WHERE QstCod=%ld", " WHERE QstCod=%ld",
Question->QstCod); Question->QstCod);
/***** Check if number of rows is correct *****/ /***** Check if number of rows is correct *****/
if (Question->Answer.NumOptions != 2) if (Question->Answer.NumOptions != 2)
@ -1338,12 +1337,12 @@ static void ExaPrn_GetCorrectTF_AnswerFromDB (struct Tst_Question *Question)
MYSQL_ROW row; MYSQL_ROW row;
/***** Query database *****/ /***** Query database *****/
Question->Answer.NumOptions = Question->Answer.NumOptions = (unsigned)
(unsigned) DB_QuerySELECT (&mysql_res,"can not get answers of a question", DB_QuerySELECT (&mysql_res,"can not get answers of a question",
"SELECT Answer" // row[0] "SELECT Answer" // row[0]
" FROM exa_set_answers" " FROM exa_set_answers"
" WHERE QstCod=%ld", " WHERE QstCod=%ld",
Question->QstCod); Question->QstCod);
/***** Check if number of rows is correct *****/ /***** Check if number of rows is correct *****/
Tst_CheckIfNumberOfAnswersIsOne (Question); Tst_CheckIfNumberOfAnswersIsOne (Question);
@ -1363,13 +1362,13 @@ static void ExaPrn_GetCorrectChoAnswerFromDB (struct Tst_Question *Question)
unsigned NumOpt; unsigned NumOpt;
/***** Query database *****/ /***** Query database *****/
Question->Answer.NumOptions = Question->Answer.NumOptions = (unsigned)
(unsigned) DB_QuerySELECT (&mysql_res,"can not get answers of a question", DB_QuerySELECT (&mysql_res,"can not get answers of a question",
"SELECT Correct" // row[0] "SELECT Correct" // row[0]
" FROM exa_set_answers" " FROM exa_set_answers"
" WHERE QstCod=%ld" " WHERE QstCod=%ld"
" ORDER BY AnsInd", " ORDER BY AnsInd",
Question->QstCod); Question->QstCod);
for (NumOpt = 0; for (NumOpt = 0;
NumOpt < Question->Answer.NumOptions; NumOpt < Question->Answer.NumOptions;
NumOpt++) NumOpt++)
@ -1392,12 +1391,12 @@ static void ExaPrn_GetCorrectTxtAnswerFromDB (struct Tst_Question *Question)
unsigned NumOpt; unsigned NumOpt;
/***** Query database *****/ /***** Query database *****/
Question->Answer.NumOptions = Question->Answer.NumOptions = (unsigned)
(unsigned) DB_QuerySELECT (&mysql_res,"can not get answers of a question", DB_QuerySELECT (&mysql_res,"can not get answers of a question",
"SELECT Answer" // row[0] "SELECT Answer" // row[0]
" FROM exa_set_answers" " FROM exa_set_answers"
" WHERE QstCod=%ld", " WHERE QstCod=%ld",
Question->QstCod); Question->QstCod);
/***** Get text and correctness of answers for this question from database (one row per answer) *****/ /***** Get text and correctness of answers for this question from database (one row per answer) *****/
for (NumOpt = 0; for (NumOpt = 0;
@ -1436,7 +1435,7 @@ static void ExaPrn_GetAnswerFromDB (struct ExaPrn_Print *Print,long QstCod,
/***** Get questions of an exam print from database *****/ /***** Get questions of an exam print from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get answer in an exam print", if (DB_QuerySELECT (&mysql_res,"can not get answer in an exam print",
"SELECT Answers" "SELECT Answers" // row[0]
" FROM exa_print_questions" " FROM exa_print_questions"
" WHERE PrnCod=%ld" " WHERE PrnCod=%ld"
" AND QstCod=%ld", " AND QstCod=%ld",
@ -1507,7 +1506,7 @@ static void ExaPrn_ComputeTotalScoreOfPrint (struct ExaPrn_Print *Print)
/***** Compute total score of exam print *****/ /***** Compute total score of exam print *****/
if (DB_QuerySELECT (&mysql_res,"can not get score of exam print", if (DB_QuerySELECT (&mysql_res,"can not get score of exam print",
"SELECT SUM(Score)" "SELECT SUM(Score)" // row[0]
" FROM exa_print_questions" " FROM exa_print_questions"
" WHERE PrnCod=%ld", " WHERE PrnCod=%ld",
Print->PrnCod)) Print->PrnCod))

View File

@ -427,7 +427,6 @@ void ExaRes_ShowAllResultsInExa (void)
static void ExaRes_ListAllResultsInExa (struct Exa_Exams *Exams,long ExaCod) static void ExaRes_ListAllResultsInExa (struct Exa_Exams *Exams,long ExaCod)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumUsrs; unsigned long NumUsrs;
unsigned long NumUsr; unsigned long NumUsr;
@ -450,26 +449,20 @@ static void ExaRes_ListAllResultsInExa (struct Exa_Exams *Exams,long ExaCod)
"usr_data.FirstName", "usr_data.FirstName",
ExaCod, ExaCod,
Gbl.Hierarchy.Crs.CrsCod); Gbl.Hierarchy.Crs.CrsCod);
if (NumUsrs)
{
/***** List sessions results for each user *****/
for (NumUsr = 0;
NumUsr < NumUsrs;
NumUsr++)
{
row = mysql_fetch_row (mysql_res);
/* Get session code (row[0]) */ /***** List sessions results for each user *****/
if ((Gbl.Usrs.Other.UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0])) > 0) for (NumUsr = 0;
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,Usr_DONT_GET_PREFS)) NumUsr < NumUsrs;
if (Usr_CheckIfICanViewTstExaMchResult (&Gbl.Usrs.Other.UsrDat)) NumUsr++)
{ /* Get session code */
/***** Show sessions results *****/ if ((Gbl.Usrs.Other.UsrDat.UsrCod = DB_GetNextCode (mysql_res)) > 0)
Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat); if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,Usr_DONT_GET_PREFS))
ExaRes_ShowResults (Exams,Usr_OTHER,-1L,ExaCod,NULL); if (Usr_CheckIfICanViewTstExaMchResult (&Gbl.Usrs.Other.UsrDat))
} {
} /***** Show sessions results *****/
} Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat);
ExaRes_ShowResults (Exams,Usr_OTHER,-1L,ExaCod,NULL);
}
/***** Free structure that stores the query result *****/ /***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res); DB_FreeMySQLResult (&mysql_res);
@ -523,7 +516,6 @@ void ExaRes_ShowAllResultsInSes (void)
static void ExaRes_ListAllResultsInSes (struct Exa_Exams *Exams,long SesCod) static void ExaRes_ListAllResultsInSes (struct Exa_Exams *Exams,long SesCod)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumUsrs; unsigned long NumUsrs;
unsigned long NumUsr; unsigned long NumUsr;
@ -532,7 +524,7 @@ static void ExaRes_ListAllResultsInSes (struct Exa_Exams *Exams,long SesCod)
/***** Get all users who have answered any session question in this exam *****/ /***** Get all users who have answered any session question in this exam *****/
NumUsrs = DB_QuerySELECT (&mysql_res,"can not get users in session", NumUsrs = DB_QuerySELECT (&mysql_res,"can not get users in session",
"SELECT users.UsrCod" "SELECT users.UsrCod" // row[0]
" FROM (SELECT exa_prints.UsrCod AS UsrCod" // row[0] " FROM (SELECT exa_prints.UsrCod AS UsrCod" // row[0]
" FROM exa_prints,exa_sessions,exa_exams" " FROM exa_prints,exa_sessions,exa_exams"
" WHERE exa_prints.SesCod=%ld" " WHERE exa_prints.SesCod=%ld"
@ -546,26 +538,20 @@ static void ExaRes_ListAllResultsInSes (struct Exa_Exams *Exams,long SesCod)
"usr_data.FirstName", "usr_data.FirstName",
SesCod, SesCod,
Gbl.Hierarchy.Crs.CrsCod); Gbl.Hierarchy.Crs.CrsCod);
if (NumUsrs)
{
/***** List sessions results for each user *****/
for (NumUsr = 0;
NumUsr < NumUsrs;
NumUsr++)
{
row = mysql_fetch_row (mysql_res);
/* Get session code (row[0]) */ /***** List sessions results for each user *****/
if ((Gbl.Usrs.Other.UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0])) > 0) for (NumUsr = 0;
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,Usr_DONT_GET_PREFS)) NumUsr < NumUsrs;
if (Usr_CheckIfICanViewTstExaMchResult (&Gbl.Usrs.Other.UsrDat)) NumUsr++)
{ /* Get session code (row[0]) */
/***** Show sessions results *****/ if ((Gbl.Usrs.Other.UsrDat.UsrCod = DB_GetNextCode (mysql_res)) > 0)
Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat); if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,Usr_DONT_GET_PREFS))
ExaRes_ShowResults (Exams,Usr_OTHER,SesCod,-1L,NULL); if (Usr_CheckIfICanViewTstExaMchResult (&Gbl.Usrs.Other.UsrDat))
} {
} /***** Show sessions results *****/
} Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat);
ExaRes_ShowResults (Exams,Usr_OTHER,SesCod,-1L,NULL);
}
/***** Free structure that stores the query result *****/ /***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res); DB_FreeMySQLResult (&mysql_res);
@ -814,7 +800,6 @@ static void ExaRes_ShowResults (struct Exa_Exams *Exams,
char *HidExaSubQuery; char *HidExaSubQuery;
char *ExaSubQuery; char *ExaSubQuery;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row;
struct UsrData *UsrDat; struct UsrData *UsrDat;
unsigned NumResults; unsigned NumResults;
unsigned NumResult; unsigned NumResult;
@ -955,10 +940,8 @@ static void ExaRes_ShowResults (struct Exa_Exams *Exams,
NumResult < NumResults; NumResult < NumResults;
NumResult++) NumResult++)
{ {
row = mysql_fetch_row (mysql_res);
/* Get print code (row[0]) */ /* Get print code (row[0]) */
if ((Print.PrnCod = Str_ConvertStrCodToLongCod (row[0])) < 0) if ((Print.PrnCod = DB_GetNextCode (mysql_res)) < 0)
Lay_ShowErrorAndExit ("Wrong code of exam print."); Lay_ShowErrorAndExit ("Wrong code of exam print.");
/* Get print data */ /* Get print data */

View File

@ -200,20 +200,20 @@ void ExaSes_ListSessions (struct Exa_Exams *Exams,
/***** Get data of sessions from database *****/ /***** Get data of sessions from database *****/
NumSessions = (unsigned) NumSessions = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get sessions", DB_QuerySELECT (&mysql_res,"can not get sessions",
"SELECT SesCod," // row[0] "SELECT SesCod," // row[0]
"ExaCod," // row[1] "ExaCod," // row[1]
"Hidden," // row[2] "Hidden," // row[2]
"UsrCod," // row[3] "UsrCod," // row[3]
"UNIX_TIMESTAMP(StartTime)," // row[4] "UNIX_TIMESTAMP(StartTime)," // row[4]
"UNIX_TIMESTAMP(EndTime)," // row[5] "UNIX_TIMESTAMP(EndTime)," // row[5]
"NOW() BETWEEN StartTime AND EndTime," // row[6] "NOW() BETWEEN StartTime AND EndTime," // row[6]
"Title," // row[7] "Title," // row[7]
"ShowUsrResults" // row[8] "ShowUsrResults" // row[8]
" FROM exa_sessions" " FROM exa_sessions"
" WHERE ExaCod=%ld%s%s" " WHERE ExaCod=%ld%s%s"
" ORDER BY SesCod", " ORDER BY SesCod",
Exam->ExaCod,HiddenSubQuery,GroupsSubQuery); Exam->ExaCod,HiddenSubQuery,GroupsSubQuery);
/***** Free allocated memory for subqueries *****/ /***** Free allocated memory for subqueries *****/
free (GroupsSubQuery); free (GroupsSubQuery);
@ -303,24 +303,24 @@ void ExaSes_GetDataOfSessionByCod (struct ExaSes_Session *Session)
/***** Get exam data session from database *****/ /***** Get exam data session from database *****/
NumRows = (unsigned) NumRows = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get sessions", DB_QuerySELECT (&mysql_res,"can not get sessions",
"SELECT SesCod," // row[0] "SELECT SesCod," // row[0]
"ExaCod," // row[1] "ExaCod," // row[1]
"Hidden," // row[2] "Hidden," // row[2]
"UsrCod," // row[3] "UsrCod," // row[3]
"UNIX_TIMESTAMP(StartTime)," // row[4] "UNIX_TIMESTAMP(StartTime)," // row[4]
"UNIX_TIMESTAMP(EndTime)," // row[5] "UNIX_TIMESTAMP(EndTime)," // row[5]
"NOW() BETWEEN StartTime AND EndTime," // row[6] "NOW() BETWEEN StartTime AND EndTime," // row[6]
"Title," // row[7] "Title," // row[7]
"ShowUsrResults" // row[8] "ShowUsrResults" // row[8]
" FROM exa_sessions" " FROM exa_sessions"
" WHERE SesCod=%ld" " WHERE SesCod=%ld"
" AND ExaCod IN" // Extra check " AND ExaCod IN" // Extra check
" (SELECT ExaCod" " (SELECT ExaCod"
" FROM exa_exams" " FROM exa_exams"
" WHERE CrsCod='%ld')", " WHERE CrsCod='%ld')",
Session->SesCod, Session->SesCod,
Gbl.Hierarchy.Crs.CrsCod); Gbl.Hierarchy.Crs.CrsCod);
if (NumRows) // Session found... if (NumRows) // Session found...
/* Get exam session data from row */ /* Get exam session data from row */
ExaSes_GetSessionDataFromRow (mysql_res,Session); ExaSes_GetSessionDataFromRow (mysql_res,Session);

View File

@ -646,7 +646,7 @@ unsigned ExaSet_GetNumQstsExam (long ExaCod)
/***** Get total number of questions to appear in exam print *****/ /***** Get total number of questions to appear in exam print *****/
if (!DB_QuerySELECT (&mysql_res,"can not get number of questions in an exam print", if (!DB_QuerySELECT (&mysql_res,"can not get number of questions in an exam print",
"SELECT SUM(NumQstsToPrint)" "SELECT SUM(NumQstsToPrint)" // row[0]
" FROM exa_sets" " FROM exa_sets"
" WHERE ExaCod=%ld", " WHERE ExaCod=%ld",
ExaCod)) ExaCod))
@ -790,7 +790,7 @@ static unsigned ExaSet_GetSetIndFromSetCod (long ExaCod,long SetCod)
/***** Get set index from set code *****/ /***** Get set index from set code *****/
if (!DB_QuerySELECT (&mysql_res,"can not get set index", if (!DB_QuerySELECT (&mysql_res,"can not get set index",
"SELECT SetInd" "SELECT SetInd" // row[0]
" FROM exa_sets" " FROM exa_sets"
" WHERE SetCod=%u" " WHERE SetCod=%u"
" AND ExaCod=%ld", // Extra check " AND ExaCod=%ld", // Extra check
@ -813,27 +813,19 @@ static unsigned ExaSet_GetSetIndFromSetCod (long ExaCod,long SetCod)
static long ExaSet_GetSetCodFromSetInd (long ExaCod,unsigned SetInd) static long ExaSet_GetSetCodFromSetInd (long ExaCod,unsigned SetInd)
{ {
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long SetCod; long SetCod;
/***** Get set code from set index *****/ /***** Get set code from set index *****/
if (!DB_QuerySELECT (&mysql_res,"can not get set code", SetCod = DB_QuerySELECTCode ("can not get set code",
"SELECT SetCod" "SELECT SetCod"
" FROM exa_sets" " FROM exa_sets"
" WHERE ExaCod=%ld" " WHERE ExaCod=%ld"
" AND SetInd=%u", " AND SetInd=%u",
ExaCod,SetInd)) ExaCod,
SetInd);
if (SetCod <= 0)
Lay_ShowErrorAndExit ("Error: wrong set index."); Lay_ShowErrorAndExit ("Error: wrong set index.");
/***** Get set code (row[0]) *****/
row = mysql_fetch_row (mysql_res);
if ((SetCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
Lay_ShowErrorAndExit ("Error: wrong set code.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return SetCod; return SetCod;
} }
@ -851,7 +843,7 @@ static unsigned ExaSet_GetMaxSetIndexInExam (long ExaCod)
/***** Get maximum set index in an exam from database *****/ /***** Get maximum set index in an exam from database *****/
DB_QuerySELECT (&mysql_res,"can not get max set index", DB_QuerySELECT (&mysql_res,"can not get max set index",
"SELECT MAX(SetInd)" "SELECT MAX(SetInd)" // row[0]
" FROM exa_sets" " FROM exa_sets"
" WHERE ExaCod=%ld", " WHERE ExaCod=%ld",
ExaCod); ExaCod);
@ -882,7 +874,7 @@ static unsigned ExaSet_GetPrevSetIndexInExam (long ExaCod,unsigned SetInd)
// Although indexes are always continuous... // Although indexes are always continuous...
// ...this implementation works even with non continuous indexes // ...this implementation works even with non continuous indexes
if (!DB_QuerySELECT (&mysql_res,"can not get previous set index", if (!DB_QuerySELECT (&mysql_res,"can not get previous set index",
"SELECT MAX(SetInd)" "SELECT MAX(SetInd)" // row[0]
" FROM exa_sets" " FROM exa_sets"
" WHERE ExaCod=%ld" " WHERE ExaCod=%ld"
" AND SetInd<%u", " AND SetInd<%u",
@ -918,7 +910,7 @@ static unsigned ExaSet_GetNextSetIndexInExam (long ExaCod,unsigned SetInd)
// Although indexes are always continuous... // Although indexes are always continuous...
// ...this implementation works even with non continuous indexes // ...this implementation works even with non continuous indexes
if (!DB_QuerySELECT (&mysql_res,"can not get next set index", if (!DB_QuerySELECT (&mysql_res,"can not get next set index",
"SELECT MIN(SetInd)" "SELECT MIN(SetInd)" // row[0]
" FROM exa_sets" " FROM exa_sets"
" WHERE ExaCod=%ld" " WHERE ExaCod=%ld"
" AND SetInd>%u", " AND SetInd>%u",
@ -958,15 +950,15 @@ void ExaSet_ListExamSets (struct Exa_Exams *Exams,
/***** Get data of set of questions from database *****/ /***** Get data of set of questions from database *****/
NumSets = (unsigned) NumSets = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get sets of questions", DB_QuerySELECT (&mysql_res,"can not get sets of questions",
"SELECT SetCod," // row[0] "SELECT SetCod," // row[0]
"SetInd," // row[1] "SetInd," // row[1]
"NumQstsToPrint," // row[2] "NumQstsToPrint," // row[2]
"Title" // row[3] "Title" // row[3]
" FROM exa_sets" " FROM exa_sets"
" WHERE ExaCod=%ld" " WHERE ExaCod=%ld"
" ORDER BY SetInd", " ORDER BY SetInd",
Exam->ExaCod); Exam->ExaCod);
/***** Begin box *****/ /***** Begin box *****/
Exams->ExaCod = Exam->ExaCod; Exams->ExaCod = Exam->ExaCod;
@ -1008,12 +1000,12 @@ static void ExaSet_ListSetQuestions (struct Exa_Exams *Exams,
/***** Get data of questions from database *****/ /***** Get data of questions from database *****/
NumQsts = (unsigned) NumQsts = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get exam questions", DB_QuerySELECT (&mysql_res,"can not get exam questions",
"SELECT QstCod" // row[0] "SELECT QstCod" // row[0]
" FROM exa_set_questions" " FROM exa_set_questions"
" WHERE SetCod=%ld" " WHERE SetCod=%ld"
" ORDER BY Stem", " ORDER BY Stem",
Set->SetCod); Set->SetCod);
/***** Begin box *****/ /***** Begin box *****/
if (ICanEditQuestions) if (ICanEditQuestions)
@ -1280,7 +1272,6 @@ static void ExaSet_ListOneOrMoreQuestionsForEdition (struct Exa_Exams *Exams,
extern const char *Txt_No_INDEX; extern const char *Txt_No_INDEX;
extern const char *Txt_Question; extern const char *Txt_Question;
unsigned NumQst; unsigned NumQst;
MYSQL_ROW row;
struct Tst_Question Question; struct Tst_Question Question;
char *Anchor; char *Anchor;
static Act_Action_t NextAction[Tst_NUM_VALIDITIES] = static Act_Action_t NextAction[Tst_NUM_VALIDITIES] =
@ -1321,12 +1312,8 @@ static void ExaSet_ListOneOrMoreQuestionsForEdition (struct Exa_Exams *Exams,
Tst_QstConstructor (&Question); Tst_QstConstructor (&Question);
/***** Get question data *****/ /***** Get question data *****/
row = mysql_fetch_row (mysql_res); /* Get question code */
/* Exams->QstCod = Question.QstCod = DB_GetNextCode (mysql_res);
row[0] QstCod
*/
/* Get question code (row[0]) */
Exams->QstCod = Question.QstCod = Str_ConvertStrCodToLongCod (row[0]);
ExaSet_GetQstDataFromDB (&Question); ExaSet_GetQstDataFromDB (&Question);
/***** Build anchor string *****/ /***** Build anchor string *****/

View File

@ -1079,8 +1079,8 @@ static void Fig_GetAndShowInssOrderedByNumCtrs (void)
case Hie_Lvl_SYS: case Hie_Lvl_SYS:
NumInss = (unsigned) NumInss = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get institutions", DB_QuerySELECT (&mysql_res,"can not get institutions",
"SELECT InsCod," "SELECT InsCod," // row[0]
"COUNT(*) AS N" "COUNT(*) AS N" // row[1]
" FROM ctr_centers" " FROM ctr_centers"
" GROUP BY InsCod" " GROUP BY InsCod"
" ORDER BY N DESC"); " ORDER BY N DESC");
@ -1088,8 +1088,8 @@ static void Fig_GetAndShowInssOrderedByNumCtrs (void)
case Hie_Lvl_CTY: case Hie_Lvl_CTY:
NumInss = (unsigned) NumInss = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get institutions", DB_QuerySELECT (&mysql_res,"can not get institutions",
"SELECT ctr_centers.InsCod," "SELECT ctr_centers.InsCod," // row[0]
"COUNT(*) AS N" "COUNT(*) AS N" // row[1]
" FROM ins_instits," " FROM ins_instits,"
"ctr_centers" "ctr_centers"
" WHERE ins_instits.CtyCod=%ld" " WHERE ins_instits.CtyCod=%ld"
@ -1104,8 +1104,8 @@ static void Fig_GetAndShowInssOrderedByNumCtrs (void)
case Hie_Lvl_CRS: case Hie_Lvl_CRS:
NumInss = (unsigned) NumInss = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get institutions", DB_QuerySELECT (&mysql_res,"can not get institutions",
"SELECT InsCod," "SELECT InsCod," // row[0]
"COUNT(*) AS N" "COUNT(*) AS N" // row[1]
" FROM ctr_centers" " FROM ctr_centers"
" WHERE InsCod=%ld" " WHERE InsCod=%ld"
" GROUP BY InsCod" " GROUP BY InsCod"
@ -1149,8 +1149,8 @@ static void Fig_GetAndShowInssOrderedByNumDegs (void)
case Hie_Lvl_SYS: case Hie_Lvl_SYS:
NumInss = (unsigned) NumInss = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get institutions", DB_QuerySELECT (&mysql_res,"can not get institutions",
"SELECT ctr_centers.InsCod," "SELECT ctr_centers.InsCod," // row[0]
"COUNT(*) AS N" "COUNT(*) AS N" // row[1]
" FROM ctr_centers," " FROM ctr_centers,"
"deg_degrees" "deg_degrees"
" WHERE ctr_centers.CtrCod=deg_degrees.CtrCod" " WHERE ctr_centers.CtrCod=deg_degrees.CtrCod"
@ -1160,8 +1160,8 @@ static void Fig_GetAndShowInssOrderedByNumDegs (void)
case Hie_Lvl_CTY: case Hie_Lvl_CTY:
NumInss = (unsigned) NumInss = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get institutions", DB_QuerySELECT (&mysql_res,"can not get institutions",
"SELECT ctr_centers.InsCod," "SELECT ctr_centers.InsCod," // row[0]
"COUNT(*) AS N" "COUNT(*) AS N" // row[1]
" FROM ins_instits," " FROM ins_instits,"
"ctr_centers," "ctr_centers,"
"deg_degrees" "deg_degrees"
@ -1178,8 +1178,8 @@ static void Fig_GetAndShowInssOrderedByNumDegs (void)
case Hie_Lvl_CRS: case Hie_Lvl_CRS:
NumInss = (unsigned) NumInss = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get institutions", DB_QuerySELECT (&mysql_res,"can not get institutions",
"SELECT ctr_centers.InsCod," "SELECT ctr_centers.InsCod," // row[0]
"COUNT(*) AS N" "COUNT(*) AS N" // row[1]
" FROM ctr_centers," " FROM ctr_centers,"
"deg_degrees" "deg_degrees"
" WHERE ctr_centers.InsCod=%ld" " WHERE ctr_centers.InsCod=%ld"
@ -1225,8 +1225,8 @@ static void Fig_GetAndShowInssOrderedByNumCrss (void)
case Hie_Lvl_SYS: case Hie_Lvl_SYS:
NumInss = (unsigned) NumInss = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get institutions", DB_QuerySELECT (&mysql_res,"can not get institutions",
"SELECT ctr_centers.InsCod," "SELECT ctr_centers.InsCod," // row[0]
"COUNT(*) AS N" "COUNT(*) AS N" // row[1]
" FROM ctr_centers," " FROM ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses" "crs_courses"
@ -1238,8 +1238,8 @@ static void Fig_GetAndShowInssOrderedByNumCrss (void)
case Hie_Lvl_CTY: case Hie_Lvl_CTY:
NumInss = (unsigned) NumInss = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get institutions", DB_QuerySELECT (&mysql_res,"can not get institutions",
"SELECT ctr_centers.InsCod," "SELECT ctr_centers.InsCod," // row[0]
"COUNT(*) AS N" "COUNT(*) AS N" // row[1]
" FROM ins_instits," " FROM ins_instits,"
"ctr_centers," "ctr_centers,"
"deg_degrees," "deg_degrees,"
@ -1258,8 +1258,8 @@ static void Fig_GetAndShowInssOrderedByNumCrss (void)
case Hie_Lvl_CRS: case Hie_Lvl_CRS:
NumInss = (unsigned) NumInss = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get institutions", DB_QuerySELECT (&mysql_res,"can not get institutions",
"SELECT ctr_centers.InsCod," "SELECT ctr_centers.InsCod," // row[0]
"COUNT(*) AS N" "COUNT(*) AS N" // row[1]
" FROM ctr_centers," " FROM ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses" "crs_courses"
@ -1307,8 +1307,8 @@ static void Fig_GetAndShowInssOrderedByNumUsrsInCrss (void)
case Hie_Lvl_SYS: case Hie_Lvl_SYS:
NumInss = (unsigned) NumInss = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get institutions", DB_QuerySELECT (&mysql_res,"can not get institutions",
"SELECT ctr_centers.InsCod," "SELECT ctr_centers.InsCod," // row[0]
"COUNT(DISTINCT crs_users.UsrCod) AS N" "COUNT(DISTINCT crs_users.UsrCod) AS N" // row[1]
" FROM ctr_centers," " FROM ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
@ -1322,8 +1322,8 @@ static void Fig_GetAndShowInssOrderedByNumUsrsInCrss (void)
case Hie_Lvl_CTY: case Hie_Lvl_CTY:
NumInss = (unsigned) NumInss = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get institutions", DB_QuerySELECT (&mysql_res,"can not get institutions",
"SELECT ctr_centers.InsCod," "SELECT ctr_centers.InsCod," // row[0]
"COUNT(DISTINCT crs_users.UsrCod) AS N" "COUNT(DISTINCT crs_users.UsrCod) AS N" // row[1]
" FROM ins_instits," " FROM ins_instits,"
"ctr_centers," "ctr_centers,"
"deg_degrees," "deg_degrees,"
@ -1344,8 +1344,8 @@ static void Fig_GetAndShowInssOrderedByNumUsrsInCrss (void)
case Hie_Lvl_CRS: case Hie_Lvl_CRS:
NumInss = (unsigned) NumInss = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get institutions", DB_QuerySELECT (&mysql_res,"can not get institutions",
"SELECT ctr_centers.InsCod," "SELECT ctr_centers.InsCod," // row[0]
"COUNT(DISTINCT crs_users.UsrCod) AS N" "COUNT(DISTINCT crs_users.UsrCod) AS N" // row[1]
" FROM ctr_centers," " FROM ctr_centers,"
"deg_degrees," "deg_degrees,"
"crs_courses," "crs_courses,"
@ -1396,7 +1396,8 @@ static void Fig_GetAndShowInssOrderedByNumUsrsWhoClaimToBelongToThem (void)
case Hie_Lvl_SYS: case Hie_Lvl_SYS:
NumInss = NumInss =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions", (unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions",
"SELECT InsCod,COUNT(*) AS N" "SELECT InsCod," // row[0]
"COUNT(*) AS N" // row[1]
" FROM usr_data" " FROM usr_data"
" WHERE InsCod>0" " WHERE InsCod>0"
" GROUP BY InsCod" " GROUP BY InsCod"
@ -1405,7 +1406,8 @@ static void Fig_GetAndShowInssOrderedByNumUsrsWhoClaimToBelongToThem (void)
case Hie_Lvl_CTY: case Hie_Lvl_CTY:
NumInss = NumInss =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions", (unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions",
"SELECT usr_data.InsCod,COUNT(*) AS N" "SELECT usr_data.InsCod," // row[0]
"COUNT(*) AS N" // row[1]
" FROM ins_instits,usr_data" " FROM ins_instits,usr_data"
" WHERE ins_instits.CtyCod=%ld" " WHERE ins_instits.CtyCod=%ld"
" AND ins_instits.InsCod=usr_data.InsCod" " AND ins_instits.InsCod=usr_data.InsCod"
@ -1419,7 +1421,8 @@ static void Fig_GetAndShowInssOrderedByNumUsrsWhoClaimToBelongToThem (void)
case Hie_Lvl_CRS: case Hie_Lvl_CRS:
NumInss = NumInss =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions", (unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions",
"SELECT InsCod,COUNT(*) AS N" "SELECT InsCod," // row[0]
"COUNT(*) AS N" // row[1]
" FROM usr_data" " FROM usr_data"
" WHERE InsCod=%ld" " WHERE InsCod=%ld"
" GROUP BY InsCod" " GROUP BY InsCod"
@ -3583,8 +3586,8 @@ static void Fig_GetAndShowTimelineActivityStats (void)
case Hie_Lvl_SYS: case Hie_Lvl_SYS:
NumRows = NumRows =
DB_QuerySELECT (&mysql_res,"can not get number of social notes", DB_QuerySELECT (&mysql_res,"can not get number of social notes",
"SELECT COUNT(*)," "SELECT COUNT(*)," // row[0]
"COUNT(DISTINCT UsrCod)" "COUNT(DISTINCT UsrCod)" // row[1]
" FROM tml_notes WHERE NoteType=%u", " FROM tml_notes WHERE NoteType=%u",
NoteType); NoteType);
break; break;
@ -3735,8 +3738,8 @@ static void Fig_GetAndShowTimelineActivityStats (void)
case Hie_Lvl_SYS: case Hie_Lvl_SYS:
NumRows = NumRows =
DB_QuerySELECT (&mysql_res,"can not get number of social notes", DB_QuerySELECT (&mysql_res,"can not get number of social notes",
"SELECT COUNT(*)," "SELECT COUNT(*)," // row[0]
"COUNT(DISTINCT UsrCod)" "COUNT(DISTINCT UsrCod)" // row[1]
" FROM tml_notes"); " FROM tml_notes");
break; break;
case Hie_Lvl_CTY: case Hie_Lvl_CTY:

View File

@ -2671,7 +2671,6 @@ static void Brw_SetPathFileBrowser (void)
bool Brw_CheckIfExistsFolderAssigmentForAnyUsr (const char *FolderName) bool Brw_CheckIfExistsFolderAssigmentForAnyUsr (const char *FolderName)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumUsrs; unsigned NumUsrs;
unsigned NumUsr; unsigned NumUsr;
long UsrCod; long UsrCod;
@ -2692,8 +2691,7 @@ bool Brw_CheckIfExistsFolderAssigmentForAnyUsr (const char *FolderName)
NumUsr++) NumUsr++)
{ {
/* Get next user */ /* Get next user */
row = mysql_fetch_row (mysql_res); UsrCod = DB_GetNextCode (mysql_res);
UsrCod = Str_ConvertStrCodToLongCod (row[0]);
/* Check if folder exists */ /* Check if folder exists */
snprintf (PathFolder,sizeof (PathFolder),"%s/usr/%02u/%ld/%s/%s", snprintf (PathFolder,sizeof (PathFolder),"%s/usr/%02u/%ld/%s/%s",
@ -2782,7 +2780,6 @@ bool Brw_UpdateFoldersAssigmentsIfExistForAllUsrs (const char *OldFolderName,con
extern const char *Txt_Folders_renamed; extern const char *Txt_Folders_renamed;
extern const char *Txt_Folders_not_renamed; extern const char *Txt_Folders_not_renamed;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumUsrs; unsigned NumUsrs;
unsigned NumUsr; unsigned NumUsr;
long UsrCod; long UsrCod;
@ -2795,12 +2792,12 @@ bool Brw_UpdateFoldersAssigmentsIfExistForAllUsrs (const char *OldFolderName,con
unsigned NumUsrsSuccess = 0; unsigned NumUsrsSuccess = 0;
/***** Get all the users belonging to current course from database *****/ /***** Get all the users belonging to current course from database *****/
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get users" NumUsrs = (unsigned)
" from current course", DB_QuerySELECT (&mysql_res,"can not get users from current course",
"SELECT UsrCod" // row[0] "SELECT UsrCod" // row[0]
" FROM crs_users" " FROM crs_users"
" WHERE CrsCod=%ld", " WHERE CrsCod=%ld",
Gbl.Hierarchy.Crs.CrsCod); Gbl.Hierarchy.Crs.CrsCod);
/***** Check if there exist folders with the new name *****/ /***** Check if there exist folders with the new name *****/
for (NumUsr = 0; for (NumUsr = 0;
@ -2808,8 +2805,7 @@ bool Brw_UpdateFoldersAssigmentsIfExistForAllUsrs (const char *OldFolderName,con
NumUsr++) NumUsr++)
{ {
/* Get next user */ /* Get next user */
row = mysql_fetch_row (mysql_res); UsrCod = DB_GetNextCode (mysql_res);
UsrCod = Str_ConvertStrCodToLongCod (row[0]);
/* Rename folder if exists */ /* Rename folder if exists */
snprintf (PathOldFolder,sizeof (PathOldFolder),"%s/usr/%02u/%ld/%s/%s", snprintf (PathOldFolder,sizeof (PathOldFolder),"%s/usr/%02u/%ld/%s/%s",
@ -2838,8 +2834,7 @@ bool Brw_UpdateFoldersAssigmentsIfExistForAllUsrs (const char *OldFolderName,con
NumUsr++) NumUsr++)
{ {
/* Get next user */ /* Get next user */
row = mysql_fetch_row (mysql_res); UsrCod = DB_GetNextCode (mysql_res);
UsrCod = Str_ConvertStrCodToLongCod (row[0]);
/* Rename folder if exists */ /* Rename folder if exists */
snprintf (PathOldFolder,sizeof (PathOldFolder),"%s/usr/%02u/%ld/%s/%s", snprintf (PathOldFolder,sizeof (PathOldFolder),"%s/usr/%02u/%ld/%s/%s",
@ -2908,19 +2903,18 @@ bool Brw_UpdateFoldersAssigmentsIfExistForAllUsrs (const char *OldFolderName,con
void Brw_RemoveFoldersAssignmentsIfExistForAllUsrs (const char *FolderName) void Brw_RemoveFoldersAssignmentsIfExistForAllUsrs (const char *FolderName)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumUsrs; unsigned NumUsrs;
unsigned NumUsr; unsigned NumUsr;
long UsrCod; long UsrCod;
char PathFolder[PATH_MAX * 2 + 128]; char PathFolder[PATH_MAX * 2 + 128];
/***** Get all the users belonging to current course from database *****/ /***** Get all the users belonging to current course from database *****/
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get users" NumUsrs = (unsigned)
" from current course", DB_QuerySELECT (&mysql_res,"can not get users from current course",
"SELECT UsrCod" // row[0] "SELECT UsrCod" // row[0]
" FROM crs_users" " FROM crs_users"
" WHERE CrsCod=%ld", " WHERE CrsCod=%ld",
Gbl.Hierarchy.Crs.CrsCod); Gbl.Hierarchy.Crs.CrsCod);
/***** Remove folders *****/ /***** Remove folders *****/
for (NumUsr = 0; for (NumUsr = 0;
@ -2928,8 +2922,7 @@ void Brw_RemoveFoldersAssignmentsIfExistForAllUsrs (const char *FolderName)
NumUsr++) NumUsr++)
{ {
/* Get next user */ /* Get next user */
row = mysql_fetch_row (mysql_res); UsrCod = DB_GetNextCode (mysql_res);
UsrCod = Str_ConvertStrCodToLongCod (row[0]);
/* Remove tree if exists */ /* Remove tree if exists */
snprintf (PathFolder,sizeof (PathFolder),"%s/usr/%02u/%ld/%s/%s", snprintf (PathFolder,sizeof (PathFolder),"%s/usr/%02u/%ld/%s/%s",
@ -9381,7 +9374,7 @@ bool Brw_CheckIfFileOrFolderIsSetAsHiddenInDB (Brw_FileType_t FileType,const cha
/***** Get if a file or folder is hidden from database *****/ /***** Get if a file or folder is hidden from database *****/
if (DB_QuerySELECT (&mysql_res,"can not check if a file is hidden", if (DB_QuerySELECT (&mysql_res,"can not check if a file is hidden",
"SELECT Hidden" // row[0] "SELECT Hidden" // row[0]
" FROM brw_files" // row[1] " FROM brw_files"
" WHERE FileBrowser=%u" " WHERE FileBrowser=%u"
" AND Cod=%ld" " AND Cod=%ld"
" AND ZoneUsrCod=%ld" " AND ZoneUsrCod=%ld"
@ -10374,38 +10367,22 @@ long Brw_GetFilCodByPath (const char *Path,bool OnlyIfPublic)
{ {
long Cod = Brw_GetCodForFiles (); long Cod = Brw_GetCodForFiles ();
long ZoneUsrCod = Brw_GetZoneUsrCodForFiles (); long ZoneUsrCod = Brw_GetZoneUsrCodForFiles ();
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long FilCod;
/***** Get code of a file from database *****/ /***** Get code of a file from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get file code", return DB_QuerySELECTCode ("can not get file code",
"SELECT FilCod" "SELECT FilCod"
" FROM brw_files" " FROM brw_files"
" WHERE FileBrowser=%u" " WHERE FileBrowser=%u"
" AND Cod=%ld" " AND Cod=%ld"
" AND ZoneUsrCod=%ld" " AND ZoneUsrCod=%ld"
" AND Path='%s'" " AND Path='%s'"
"%s", "%s",
(unsigned) Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type], (unsigned) Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type],
Cod,ZoneUsrCod, Cod,
Path, ZoneUsrCod,
OnlyIfPublic ? " AND Public='Y'" : Path,
"")) OnlyIfPublic ? " AND Public='Y'" :
{ "");
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get file code (row[0]) */
FilCod = Str_ConvertStrCodToLongCod (row[0]);
}
else
FilCod = -1L;
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return FilCod;
} }
/*****************************************************************************/ /*****************************************************************************/
@ -11749,41 +11726,22 @@ static bool Brw_CheckIfICanModifyPrjAssFileOrFolder (void)
static long Brw_GetPublisherOfSubtree (void) static long Brw_GetPublisherOfSubtree (void)
{ {
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
long PublisherUsrCod;
long Cod = Brw_GetCodForFiles (); long Cod = Brw_GetCodForFiles ();
/***** Get all common files that are equal to full path (including filename) /***** Get all common files that are equal to full path (including filename)
or that are under that full path from database *****/ or that are under that full path from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get publishers of files", return DB_QuerySELECTCode ("can not get publishers of files",
"SELECT DISTINCT(PublisherUsrCod)" "SELECT DISTINCT(PublisherUsrCod)"
" FROM brw_files" " FROM brw_files"
" WHERE FileBrowser=%u" " WHERE FileBrowser=%u"
" AND Cod=%ld" " AND Cod=%ld"
" AND (Path='%s'" " AND (Path='%s'"
" OR" " OR"
" Path LIKE '%s/%%')", " Path LIKE '%s/%%')",
(unsigned) Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type], (unsigned) Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type],
Cod, Cod,
Gbl.FileBrowser.FilFolLnk.Full, Gbl.FileBrowser.FilFolLnk.Full,
Gbl.FileBrowser.FilFolLnk.Full); Gbl.FileBrowser.FilFolLnk.Full);
/***** Check all common files that are equal to full path (including filename)
or that are under that full path *****/
if (NumRows == 1) // Get the publisher of the file(s)
{
row = mysql_fetch_row (mysql_res);
PublisherUsrCod = Str_ConvertStrCodToLongCod (row[0]);
}
else
PublisherUsrCod = -1L;
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return PublisherUsrCod;
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -675,7 +675,6 @@ static void Fol_ListFollowingUsr (struct UsrData *UsrDat)
{ {
extern const char *Txt_Following; extern const char *Txt_Following;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumUsrs; unsigned long NumUsrs;
unsigned long NumUsr; unsigned long NumUsr;
struct UsrData FollowingUsrDat; struct UsrData FollowingUsrDat;
@ -685,7 +684,7 @@ static void Fol_ListFollowingUsr (struct UsrData *UsrDat)
{ {
/***** Check if a user is a follower of another user *****/ /***** Check if a user is a follower of another user *****/
NumUsrs = DB_QuerySELECT (&mysql_res,"can not get followed users", NumUsrs = DB_QuerySELECT (&mysql_res,"can not get followed users",
"SELECT FollowedCod" "SELECT FollowedCod" // row[0]
" FROM usr_follow" " FROM usr_follow"
" WHERE FollowerCod=%ld" " WHERE FollowerCod=%ld"
" ORDER BY FollowTime DESC", " ORDER BY FollowTime DESC",
@ -705,11 +704,8 @@ static void Fol_ListFollowingUsr (struct UsrData *UsrDat)
NumUsr < NumUsrs; NumUsr < NumUsrs;
NumUsr++) NumUsr++)
{ {
/***** Get user *****/ /***** Get user's code *****/
row = mysql_fetch_row (mysql_res); FollowingUsrDat.UsrCod = DB_GetNextCode (mysql_res);
/* Get user's code (row[0]) */
FollowingUsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]);
/***** Show user *****/ /***** Show user *****/
if ((NumUsr % Fol_NUM_COLUMNS_FOLLOW) == 0) if ((NumUsr % Fol_NUM_COLUMNS_FOLLOW) == 0)
@ -759,7 +755,6 @@ static void Fol_ListFollowersUsr (struct UsrData *UsrDat)
{ {
extern const char *Txt_Followers; extern const char *Txt_Followers;
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumUsrs; unsigned long NumUsrs;
unsigned long NumUsr; unsigned long NumUsr;
struct UsrData FollowerUsrDat; struct UsrData FollowerUsrDat;
@ -790,11 +785,8 @@ static void Fol_ListFollowersUsr (struct UsrData *UsrDat)
NumUsr < NumUsrs; NumUsr < NumUsrs;
NumUsr++) NumUsr++)
{ {
/***** Get user and number of clicks *****/ /***** Get user's code *****/
row = mysql_fetch_row (mysql_res); FollowerUsrDat.UsrCod = DB_GetNextCode (mysql_res);
/* Get user's code (row[0]) */
FollowerUsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]);
/***** Show user *****/ /***** Show user *****/
if ((NumUsr % Fol_NUM_COLUMNS_FOLLOW) == 0) if ((NumUsr % Fol_NUM_COLUMNS_FOLLOW) == 0)
@ -1378,8 +1370,8 @@ void Fol_GetAndShowRankingFollowers (void)
case Hie_Lvl_SYS: case Hie_Lvl_SYS:
NumUsrs = (unsigned) NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get ranking", DB_QuerySELECT (&mysql_res,"can not get ranking",
"SELECT FollowedCod," // row[0] "SELECT FollowedCod," // row[0]
"COUNT(FollowerCod) AS N" // row[1] "COUNT(FollowerCod) AS N" // row[1]
" FROM usr_follow" " FROM usr_follow"
" GROUP BY FollowedCod" " GROUP BY FollowedCod"
" ORDER BY N DESC," " ORDER BY N DESC,"

View File

@ -731,9 +731,8 @@ static void For_GetThrSubject (long ThrCod,char Subject[Cns_MAX_BYTES_SUBJECT +
MYSQL_ROW row; MYSQL_ROW row;
/***** Get subject of a thread from database *****/ /***** Get subject of a thread from database *****/
DB_QuerySELECT (&mysql_res,"can not get the subject" DB_QuerySELECT (&mysql_res,"can not get the subject of a thread of a forum",
" of a thread of a forum", "SELECT for_posts.Subject" // row[0]
"SELECT for_posts.Subject"
" FROM for_threads," " FROM for_threads,"
"for_posts" "for_posts"
" WHERE for_threads.ThrCod=%ld" " WHERE for_threads.ThrCod=%ld"
@ -827,23 +826,18 @@ static void For_UpdateThrLastPst (long ThrCod,long LastPstCod)
static long For_GetLastPstCod (long ThrCod) static long For_GetLastPstCod (long ThrCod)
{ {
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long LastPstCod; long LastPstCod;
/***** Get the code of the last post of a thread from database *****/ /***** Get the code of the last post of a thread from database *****/
DB_QuerySELECT (&mysql_res,"can not get the most recent post" LastPstCod = DB_QuerySELECTCode ("can not get the most recent post"
" of a thread of a forum", " of a thread of a forum",
"SELECT PstCod" "SELECT PstCod"
" FROM for_posts" " FROM for_posts"
" WHERE ThrCod=%ld" " WHERE ThrCod=%ld"
" ORDER BY CreatTime DESC" " ORDER BY CreatTime DESC"
" LIMIT 1", " LIMIT 1",
ThrCod); ThrCod);
if (LastPstCod <= 0)
/***** Write the subject of the thread *****/
row = mysql_fetch_row (mysql_res);
if (sscanf (row[0],"%ld",&LastPstCod) != 1)
Lay_ShowErrorAndExit ("Error when getting the most recent post of a thread of a forum."); Lay_ShowErrorAndExit ("Error when getting the most recent post of a thread of a forum.");
return LastPstCod; return LastPstCod;
@ -894,29 +888,12 @@ static unsigned For_GetNumOfReadersOfThr (long ThrCod)
static unsigned For_GetNumOfWritersInThr (long ThrCod) static unsigned For_GetNumOfWritersInThr (long ThrCod)
{ {
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumWriters;
/***** Get number of distinct writers in a thread from database *****/ /***** Get number of distinct writers in a thread from database *****/
DB_QuerySELECT (&mysql_res,"can not get the number of writers" return DB_QueryCOUNT ("can not get the number of writers in a thread of a forum",
" in a thread of a forum", "SELECT COUNT(DISTINCT UsrCod)"
"SELECT COUNT(DISTINCT UsrCod)" " FROM for_posts"
" FROM for_posts" " WHERE ThrCod=%ld",
" WHERE ThrCod=%ld", ThrCod);
ThrCod);
/* Get row with number of writers */
row = mysql_fetch_row (mysql_res);
/* Get number of writers (row[0]) */
if (sscanf (row[0],"%u",&NumWriters) != 1)
Lay_ShowErrorAndExit ("Error when getting the number of writers in a thread of a forum.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NumWriters;
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2473,7 +2450,6 @@ static void For_ShowForumThreadsHighlightingOneThread (struct For_Forums *Forums
extern const char *Txt_ReaBRders; extern const char *Txt_ReaBRders;
char SubQuery[256]; char SubQuery[256];
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row;
char FrameTitle[128 + For_MAX_BYTES_FORUM_NAME]; char FrameTitle[128 + For_MAX_BYTES_FORUM_NAME];
char ForumName[For_MAX_BYTES_FORUM_NAME + 1]; char ForumName[For_MAX_BYTES_FORUM_NAME + 1];
unsigned NumThr; unsigned NumThr;
@ -2531,13 +2507,9 @@ static void For_ShowForumThreadsHighlightingOneThread (struct For_Forums *Forums
for (NumThr = PaginationThrs.FirstItemVisible, NumThrInScreen = 0; for (NumThr = PaginationThrs.FirstItemVisible, NumThrInScreen = 0;
NumThr <= PaginationThrs.LastItemVisible; NumThr <= PaginationThrs.LastItemVisible;
NumThr++, NumThrInScreen++) NumThr++, NumThrInScreen++)
{
row = mysql_fetch_row (mysql_res);
/* Get thread code(row[0]) */ /* Get thread code(row[0]) */
if ((ThrCods[NumThrInScreen] = Str_ConvertStrCodToLongCod (row[0])) < 0) if ((ThrCods[NumThrInScreen] = DB_GetNextCode (mysql_res)) < 0)
Lay_ShowErrorAndExit ("Error when getting thread of a forum."); Lay_ShowErrorAndExit ("Error when getting thread of a forum.");
}
/***** Free structure that stores the query result *****/ /***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res); DB_FreeMySQLResult (&mysql_res);
@ -3688,12 +3660,12 @@ static void For_GetThreadData (struct For_Thread *Thr)
/***** Get data of a thread from database *****/ /***** Get data of a thread from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get data" NumRows = DB_QuerySELECT (&mysql_res,"can not get data"
" of a thread of a forum", " of a thread of a forum",
"SELECT m0.PstCod," "SELECT m0.PstCod," // row[0]
"m1.PstCod," "m1.PstCod," // row[1]
"m0.UsrCod," "m0.UsrCod," // row[2]
"m1.UsrCod," "m1.UsrCod," // row[3]
"UNIX_TIMESTAMP(m0.CreatTime)," "UNIX_TIMESTAMP(m0.CreatTime)," // row[4]
"UNIX_TIMESTAMP(m1.CreatTime)," "UNIX_TIMESTAMP(m1.CreatTime)," // row[5]
"m0.Subject" "m0.Subject"
" FROM for_threads," " FROM for_threads,"
"for_posts AS m0," "for_posts AS m0,"
@ -4555,31 +4527,13 @@ static bool For_CheckIfICanMoveThreads (void)
static long For_GetThrInMyClipboard (void) static long For_GetThrInMyClipboard (void)
{ {
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
long ThrCod = -1L;
/***** Get if there is a thread ready to move in my clipboard from database *****/ /***** Get if there is a thread ready to move in my clipboard from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not check if there is" return DB_QuerySELECTCode ("can not check if there is"
" any thread ready to be moved", " any thread ready to be moved",
"SELECT ThrCod" "SELECT ThrCod"
" FROM for_clipboards" " FROM for_clipboards"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod); Gbl.Usrs.Me.UsrDat.UsrCod);
if (NumRows == 1)
{
/* Get thread code */
row = mysql_fetch_row (mysql_res);
if (sscanf (row[0],"%ld",&ThrCod) != 1)
Lay_ShowErrorAndExit ("Error when checking if there is any thread ready to be moved.");
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return ThrCod;
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -1429,6 +1429,15 @@ void Lay_WrongProjectExit (void)
Lay_ShowErrorAndExit ("Wrong project."); Lay_ShowErrorAndExit ("Wrong project.");
} }
/*****************************************************************************/
/********** Write error message and exit when wrong call for exam ************/
/*****************************************************************************/
void Lay_WrongCallForExamExit (void)
{
Lay_ShowErrorAndExit ("Wrong call for exam.");
}
/*****************************************************************************/ /*****************************************************************************/
/************** Write error message and exit when wrong exam *****************/ /************** Write error message and exit when wrong exam *****************/
/*****************************************************************************/ /*****************************************************************************/

View File

@ -74,6 +74,7 @@ void Lay_WrongScopeExit (void);
void Lay_WrongOrderExit (void); void Lay_WrongOrderExit (void);
void Lay_WrongTypeOfViewExit (void); void Lay_WrongTypeOfViewExit (void);
void Lay_WrongProjectExit (void); void Lay_WrongProjectExit (void);
void Lay_WrongCallForExamExit (void);
void Lay_WrongExamExit (void); void Lay_WrongExamExit (void);
void Lay_WrongSetExit (void); void Lay_WrongSetExit (void);
void Lay_WrongExamSessionExit (void); void Lay_WrongExamSessionExit (void);

View File

@ -1929,7 +1929,6 @@ long Med_CloneMedia (const struct Med_Media *MediaSrc)
void Med_RemoveMediaFromAllRows (unsigned NumMedia,MYSQL_RES *mysql_res) void Med_RemoveMediaFromAllRows (unsigned NumMedia,MYSQL_RES *mysql_res)
{ {
MYSQL_ROW row;
unsigned NumMed; unsigned NumMed;
long MedCod; long MedCod;
@ -1938,9 +1937,8 @@ void Med_RemoveMediaFromAllRows (unsigned NumMedia,MYSQL_RES *mysql_res)
NumMed < NumMedia; NumMed < NumMedia;
NumMed++) NumMed++)
{ {
/***** Get media code (row[0]) *****/ /***** Get media code *****/
row = mysql_fetch_row (mysql_res); MedCod = DB_GetNextCode (mysql_res);
MedCod = Str_ConvertStrCodToLongCod (row[0]);
/***** Remove media files *****/ /***** Remove media files *****/
Med_RemoveMedia (MedCod); Med_RemoveMedia (MedCod);