diff --git a/swad_API.c b/swad_API.c index 468c335e..4c1fd491 100644 --- a/swad_API.c +++ b/swad_API.c @@ -1013,14 +1013,14 @@ int swad__loginBySessionKey (struct soap *soap, // Now, we know that sessionID is a valid session identifier /***** Query data of the session from database *****/ - NumRows = - (unsigned) DB_QuerySELECT (&mysql_res,"can not get session data", - "SELECT UsrCod," // row[0] - "DegCod," // row[1] - "CrsCod" // row[2] - " FROM ses_sessions" - " WHERE SessionId='%s'", - sessionID); + NumRows = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get session data", + "SELECT UsrCod," // row[0] + "DegCod," // row[1] + "CrsCod" // row[2] + " FROM ses_sessions" + " WHERE SessionId='%s'", + sessionID); if (NumRows == 1) // Session found in table of sessions { row = mysql_fetch_row (mysql_res); @@ -2625,13 +2625,12 @@ static void API_GetListGrpsInAttendanceEventFromDB (struct soap *soap, size_t Length; /***** Get list of groups *****/ - NumGrps = - (unsigned) DB_QuerySELECT (&mysql_res,"can not get groups" - " of an attendance event", - "SELECT GrpCod" - " FROM att_groups" - " WHERE AttCod=%ld", - AttCod); + NumGrps = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get groups of an attendance event", + "SELECT GrpCod" + " FROM att_groups" + " WHERE AttCod=%ld", + AttCod); if (NumGrps == 0) *ListGroups = NULL; else // Events found @@ -3587,8 +3586,8 @@ int swad__sendMessage (struct soap *soap, char *Query = NULL; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned NumRow; - unsigned NumRows; + unsigned NumUsrs; + unsigned NumUsr; bool FirstNickname = true; bool ThereAreNicknames = false; const char *Ptr; @@ -3715,22 +3714,23 @@ int swad__sendMessage (struct soap *soap, if (ReplyUsrCod > 0 || ThereAreNicknames) // There are a recipient to reply or nicknames in "to" { /***** Get users *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get users", - "%s", - Query); + NumUsrs = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get users", + "%s", + Query); - sendMessageOut->numUsers = (int) NumRows; - sendMessageOut->usersArray.__size = (int) NumRows; + sendMessageOut->numUsers = (int) NumUsrs; + sendMessageOut->usersArray.__size = (int) NumUsrs; - if (NumRows) // Users found + if (NumUsrs) // Users found { sendMessageOut->usersArray.__ptr = soap_malloc (soap, (sendMessageOut->usersArray.__size) * sizeof (*(sendMessageOut->usersArray.__ptr))); - for (NumRow = 0; - NumRow < NumRows; - NumRow++) + for (NumUsr = 0; + NumUsr < NumUsrs; + NumUsr++) { /* Get next user */ row = mysql_fetch_row (mysql_res); @@ -3754,7 +3754,7 @@ int swad__sendMessage (struct soap *soap, /* Copy user's data into output structure */ API_CopyUsrData (soap, - &(sendMessageOut->usersArray.__ptr[NumRow]), + &(sendMessageOut->usersArray.__ptr[NumUsr]), &Gbl.Usrs.Other.UsrDat, false); } @@ -4180,22 +4180,23 @@ static int API_GetTstTags (struct soap *soap, extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES]; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned NumRow; - unsigned NumRows; + unsigned NumTags; + unsigned NumTag; /***** Get available tags from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get test tags", - "SELECT TagCod," // row[0] - "TagTxt" // row[1] - " FROM tst_tags" - " WHERE CrsCod=%ld" - " AND TagHidden='N'" - " ORDER BY TagTxt", - CrsCod); + NumTags = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get test tags", + "SELECT TagCod," // row[0] + "TagTxt" // row[1] + " FROM tst_tags" + " WHERE CrsCod=%ld" + " AND TagHidden='N'" + " ORDER BY TagTxt", + CrsCod); - getTestsOut->tagsArray.__size = (int) NumRows; + getTestsOut->tagsArray.__size = (int) NumTags; - if (NumRows == 0) + if (NumTags == 0) getTestsOut->tagsArray.__ptr = NULL; else // Tags found { @@ -4203,20 +4204,20 @@ static int API_GetTstTags (struct soap *soap, (getTestsOut->tagsArray.__size) * sizeof (*(getTestsOut->tagsArray.__ptr))); - for (NumRow = 0; - NumRow < NumRows; - NumRow++) + for (NumTag = 0; + NumTag < NumTags; + NumTag++) { /* Get next tag */ row = mysql_fetch_row (mysql_res); /* Get tag code (row[0]) */ - getTestsOut->tagsArray.__ptr[NumRow].tagCode = (int) Str_ConvertStrCodToLongCod (row[0]); + getTestsOut->tagsArray.__ptr[NumTag].tagCode = (int) Str_ConvertStrCodToLongCod (row[0]); /* Get tag text (row[1]) */ - getTestsOut->tagsArray.__ptr[NumRow].tagText = + getTestsOut->tagsArray.__ptr[NumTag].tagText = soap_malloc (soap,Tag_MAX_BYTES_TAG + 1); - Str_Copy (getTestsOut->tagsArray.__ptr[NumRow].tagText,row[1], + Str_Copy (getTestsOut->tagsArray.__ptr[NumTag].tagText,row[1], Tag_MAX_BYTES_TAG); } } @@ -4766,7 +4767,7 @@ int swad__getGames (struct soap *soap, int ReturnCode; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; + unsigned NumGames; int NumGame; long GamCod; char PhotoURL[Cns_MAX_BYTES_WWW + 1]; @@ -4808,27 +4809,28 @@ int swad__getGames (struct soap *soap, "Requester must be a student in the course"); /***** Query list of games *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get games", - "SELECT gam_games.GamCod," // row[0] - "gam_games.UsrCod," // row[1] - "UNIX_TIMESTAMP(MIN(mch_matches.StartTime)) AS StartTime," // row[2] - "UNIX_TIMESTAMP(MAX(mch_matches.EndTime)) AS EndTime," // row[3] - "gam_games.MaxGrade," // row[4] - "gam_games.Visibility," // row[5] - "gam_games.Title," // row[6] - "gam_games.Txt" // row[7] - " FROM gam_games" - " LEFT JOIN mch_matches" - " ON gam_games.GamCod=mch_matches.GamCod" - " WHERE gam_games.CrsCod=%ld" - " AND Hidden='N'" - " GROUP BY gam_games.GamCod" - " ORDER BY StartTime DESC," - "EndTime DESC," - "gam_games.Title DESC", - Gbl.Hierarchy.Crs.CrsCod); + NumGames = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get games", + "SELECT gam_games.GamCod," // row[0] + "gam_games.UsrCod," // row[1] + "UNIX_TIMESTAMP(MIN(mch_matches.StartTime)) AS StartTime," // row[2] + "UNIX_TIMESTAMP(MAX(mch_matches.EndTime)) AS EndTime," // row[3] + "gam_games.MaxGrade," // row[4] + "gam_games.Visibility," // row[5] + "gam_games.Title," // row[6] + "gam_games.Txt" // row[7] + " FROM gam_games" + " LEFT JOIN mch_matches" + " ON gam_games.GamCod=mch_matches.GamCod" + " WHERE gam_games.CrsCod=%ld" + " AND Hidden='N'" + " GROUP BY gam_games.GamCod" + " ORDER BY StartTime DESC," + "EndTime DESC," + "gam_games.Title DESC", + Gbl.Hierarchy.Crs.CrsCod); getGamesOut->gamesArray.__size = - getGamesOut->numGames = (int) NumRows; + getGamesOut->numGames = (int) NumGames; if (getGamesOut->numGames == 0) getGamesOut->gamesArray.__ptr = NULL; @@ -4938,7 +4940,7 @@ int swad__getMatches (struct soap *soap, struct Gam_Game Game; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; + unsigned NumMatches; int NumMatch; long MchCod; char PhotoURL[Cns_MAX_BYTES_WWW + 1]; @@ -4991,29 +4993,30 @@ int swad__getMatches (struct soap *soap, "Requester must be a student in the course"); /***** Query list of matches *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get matches", - "SELECT MchCod," // row[ 0] - "UsrCod," // row[ 1] - "UNIX_TIMESTAMP(StartTime)," // row[ 2] - "UNIX_TIMESTAMP(EndTime)," // row[ 3] - "Title," // row[ 4] - "QstInd" // row[ 5] - " FROM mch_matches" - " WHERE GamCod=%ld" - " AND (MchCod NOT IN" - " (SELECT MchCod FROM mch_groups)" - " OR" - " MchCod IN" - " (SELECT mch_groups.MchCod" - " FROM mch_groups," - "grp_users" - " WHERE grp_users.UsrCod=%ld" - " AND mch_groups.GrpCod=grp_users.GrpCod))" - " ORDER BY MchCod", - Game.GamCod, - Gbl.Usrs.Me.UsrDat.UsrCod); + NumMatches = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get matches", + "SELECT MchCod," // row[ 0] + "UsrCod," // row[ 1] + "UNIX_TIMESTAMP(StartTime)," // row[ 2] + "UNIX_TIMESTAMP(EndTime)," // row[ 3] + "Title," // row[ 4] + "QstInd" // row[ 5] + " FROM mch_matches" + " WHERE GamCod=%ld" + " AND (MchCod NOT IN" + " (SELECT MchCod FROM mch_groups)" + " OR" + " MchCod IN" + " (SELECT mch_groups.MchCod" + " FROM mch_groups," + "grp_users" + " WHERE grp_users.UsrCod=%ld" + " AND mch_groups.GrpCod=grp_users.GrpCod))" + " ORDER BY MchCod", + Game.GamCod, + Gbl.Usrs.Me.UsrDat.UsrCod); getMatchesOut->matchesArray.__size = - getMatchesOut->numMatches = (int) NumRows; + getMatchesOut->numMatches = (int) NumMatches; if (getMatchesOut->numMatches == 0) getMatchesOut->matchesArray.__ptr = NULL; diff --git a/swad_MFU.c b/swad_MFU.c index 11b91e85..a2b92f40 100644 --- a/swad_MFU.c +++ b/swad_MFU.c @@ -102,24 +102,25 @@ void MFU_GetMFUActions (struct MFU_ListMFUActions *ListMFUActions,unsigned MaxAc { extern Act_Action_t Act_FromActCodToAction[1 + Act_MAX_ACTION_COD]; MYSQL_RES *mysql_res; - unsigned long NumRows; - unsigned long NumRow; + unsigned NumActions; + unsigned NumAction; long ActCod; Act_Action_t Action; /***** Get most frequently used actions *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get most frequently used actions", - "SELECT ActCod" - " FROM act_frequent" - " WHERE UsrCod=%ld" - " ORDER BY Score DESC," - "LastClick DESC", - Gbl.Usrs.Me.UsrDat.UsrCod); + NumActions = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get most frequently used actions", + "SELECT ActCod" + " FROM act_frequent" + " WHERE UsrCod=%ld" + " ORDER BY Score DESC," + "LastClick DESC", + Gbl.Usrs.Me.UsrDat.UsrCod); /***** Write list of frequently used actions *****/ - for (NumRow = 0, ListMFUActions->NumActions = 0; - NumRow < NumRows && ListMFUActions->NumActions < MaxActionsShown; - NumRow++) + for (NumAction = 0, ListMFUActions->NumActions = 0; + NumAction < NumActions && ListMFUActions->NumActions < MaxActionsShown; + NumAction++) { /* Get action code */ ActCod = DB_GetNextCode (mysql_res); diff --git a/swad_assignment.c b/swad_assignment.c index 6b9b2ebb..fff95b2e 100644 --- a/swad_assignment.c +++ b/swad_assignment.c @@ -89,7 +89,7 @@ static void Asg_PutParams (void *Assignments); static void Asg_GetListAssignments (struct Asg_Assignments *Assignments); static void Asg_GetDataOfAssignment (struct Asg_Assignment *Asg, MYSQL_RES **mysql_res, - unsigned long NumRows); + unsigned NumAsgs); static void Asg_ResetAssignment (struct Asg_Assignment *Asg); static void Asg_FreeListAssignments (struct Asg_Assignments *Assignments); static void Asg_GetAssignmentTxtFromDB (long AsgCod,char Txt[Cns_MAX_BYTES_TEXT + 1]); @@ -684,7 +684,7 @@ static void Asg_GetListAssignments (struct Asg_Assignments *Assignments) [Dat_END_TIME ] = "EndTime DESC,StartTime DESC,Title DESC", }; MYSQL_RES *mysql_res; - unsigned long NumRows; + unsigned NumAsgs; unsigned NumAsg; if (Assignments->LstIsRead) @@ -692,45 +692,47 @@ static void Asg_GetListAssignments (struct Asg_Assignments *Assignments) /***** Get list of assignments from database *****/ if (Gbl.Crs.Grps.WhichGrps == Grp_MY_GROUPS) - NumRows = DB_QuerySELECT (&mysql_res,"can not get assignments", - "SELECT AsgCod" - " FROM asg_assignments" - " WHERE CrsCod=%ld%s" - " AND (" - // Assignment is for the whole course - "AsgCod NOT IN" - " (SELECT AsgCod" - " FROM asg_groups)" // Not associated to any group - " OR" - // Assignment is for some of my groups - " AsgCod IN" - " (SELECT asg_groups.AsgCod" - " FROM asg_groups," - "grp_users" - " WHERE grp_users.UsrCod=%ld" - " AND asg_groups.GrpCod=grp_users.GrpCod)" - ")" - " ORDER BY %s", - Gbl.Hierarchy.Crs.CrsCod, - HiddenSubQuery[Gbl.Usrs.Me.Role.Logged], - Gbl.Usrs.Me.UsrDat.UsrCod, - OrderBySubQuery[Assignments->SelectedOrder]); + NumAsgs = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get assignments", + "SELECT AsgCod" + " FROM asg_assignments" + " WHERE CrsCod=%ld%s" + " AND (" + // Assignment is for the whole course + "AsgCod NOT IN" + " (SELECT AsgCod" + " FROM asg_groups)" // Not associated to any group + " OR" + // Assignment is for some of my groups + " AsgCod IN" + " (SELECT asg_groups.AsgCod" + " FROM asg_groups," + "grp_users" + " WHERE grp_users.UsrCod=%ld" + " AND asg_groups.GrpCod=grp_users.GrpCod)" + ")" + " ORDER BY %s", + Gbl.Hierarchy.Crs.CrsCod, + HiddenSubQuery[Gbl.Usrs.Me.Role.Logged], + Gbl.Usrs.Me.UsrDat.UsrCod, + OrderBySubQuery[Assignments->SelectedOrder]); else // Gbl.Crs.Grps.WhichGrps == Grp_ALL_GROUPS - NumRows = DB_QuerySELECT (&mysql_res,"can not get assignments", - "SELECT AsgCod" - " FROM asg_assignments" - " WHERE CrsCod=%ld%s" - " ORDER BY %s", - Gbl.Hierarchy.Crs.CrsCod, - HiddenSubQuery[Gbl.Usrs.Me.Role.Logged], - OrderBySubQuery[Assignments->SelectedOrder]); + NumAsgs = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get assignments", + "SELECT AsgCod" + " FROM asg_assignments" + " WHERE CrsCod=%ld%s" + " ORDER BY %s", + Gbl.Hierarchy.Crs.CrsCod, + HiddenSubQuery[Gbl.Usrs.Me.Role.Logged], + OrderBySubQuery[Assignments->SelectedOrder]); - if (NumRows) // Assignments found... + if (NumAsgs) // Assignments found... { - Assignments->Num = (unsigned) NumRows; + Assignments->Num = (unsigned) NumAsgs; /***** Create list of assignments *****/ - if ((Assignments->LstAsgCods = calloc (NumRows, + if ((Assignments->LstAsgCods = calloc (NumAsgs, sizeof (*Assignments->LstAsgCods))) == NULL) Lay_NotEnoughMemoryExit (); @@ -760,28 +762,29 @@ static void Asg_GetListAssignments (struct Asg_Assignments *Assignments) void Asg_GetDataOfAssignmentByCod (struct Asg_Assignment *Asg) { MYSQL_RES *mysql_res; - unsigned long NumRows; + unsigned NumAsgs; if (Asg->AsgCod > 0) { /***** Build query *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get assignment data", - "SELECT AsgCod," // row[0] - "Hidden," // row[1] - "UsrCod," // row[2] - "UNIX_TIMESTAMP(StartTime)," // row[3] - "UNIX_TIMESTAMP(EndTime)," // row[4] - "NOW() BETWEEN StartTime AND EndTime," // row[5] - "Title," // row[6] - "Folder" // row[7] - " FROM asg_assignments" - " WHERE AsgCod=%ld" - " AND CrsCod=%ld", - Asg->AsgCod, - Gbl.Hierarchy.Crs.CrsCod); + NumAsgs = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get assignment data", + "SELECT AsgCod," // row[0] + "Hidden," // row[1] + "UsrCod," // row[2] + "UNIX_TIMESTAMP(StartTime)," // row[3] + "UNIX_TIMESTAMP(EndTime)," // row[4] + "NOW() BETWEEN StartTime AND EndTime," // row[5] + "Title," // row[6] + "Folder" // row[7] + " FROM asg_assignments" + " WHERE AsgCod=%ld" + " AND CrsCod=%ld", + Asg->AsgCod, + Gbl.Hierarchy.Crs.CrsCod); /***** Get data of assignment *****/ - Asg_GetDataOfAssignment (Asg,&mysql_res,NumRows); + Asg_GetDataOfAssignment (Asg,&mysql_res,NumAsgs); } else { @@ -798,28 +801,29 @@ void Asg_GetDataOfAssignmentByCod (struct Asg_Assignment *Asg) void Asg_GetDataOfAssignmentByFolder (struct Asg_Assignment *Asg) { MYSQL_RES *mysql_res; - unsigned long NumRows; + unsigned NumAsgs; if (Asg->Folder[0]) { /***** Query database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get assignment data", - "SELECT AsgCod," // row[0] - "Hidden," // row[1] - "UsrCod," // row[2] - "UNIX_TIMESTAMP(StartTime)," // row[3] - "UNIX_TIMESTAMP(EndTime)," // row[4] - "NOW() BETWEEN StartTime AND EndTime," // row[5] - "Title," // row[6] - "Folder" // row[7] - " FROM asg_assignments" - " WHERE CrsCod=%ld" - " AND Folder='%s'", - Gbl.Hierarchy.Crs.CrsCod, - Asg->Folder); + NumAsgs = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get assignment data", + "SELECT AsgCod," // row[0] + "Hidden," // row[1] + "UsrCod," // row[2] + "UNIX_TIMESTAMP(StartTime)," // row[3] + "UNIX_TIMESTAMP(EndTime)," // row[4] + "NOW() BETWEEN StartTime AND EndTime," // row[5] + "Title," // row[6] + "Folder" // row[7] + " FROM asg_assignments" + " WHERE CrsCod=%ld" + " AND Folder='%s'", + Gbl.Hierarchy.Crs.CrsCod, + Asg->Folder); /***** Get data of assignment *****/ - Asg_GetDataOfAssignment (Asg,&mysql_res,NumRows); + Asg_GetDataOfAssignment (Asg,&mysql_res,NumAsgs); } else { @@ -835,7 +839,7 @@ void Asg_GetDataOfAssignmentByFolder (struct Asg_Assignment *Asg) static void Asg_GetDataOfAssignment (struct Asg_Assignment *Asg, MYSQL_RES **mysql_res, - unsigned long NumRows) + unsigned NumAsgs) { MYSQL_ROW row; @@ -843,7 +847,7 @@ static void Asg_GetDataOfAssignment (struct Asg_Assignment *Asg, Asg_ResetAssignment (Asg); /***** Get data of assignment from database *****/ - if (NumRows) // Assignment found... + if (NumAsgs) // Assignment found... { /* Get row */ row = mysql_fetch_row (*mysql_res); @@ -953,21 +957,22 @@ void Asg_GetNotifAssignment (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1], { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; + unsigned NumAsgs; size_t Length; SummaryStr[0] = '\0'; // Return nothing on error /***** Build query *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get assignment title and text", - "SELECT Title," // row[0] - "Txt" // row[1] - " FROM asg_assignments" - " WHERE AsgCod=%ld", - AsgCod); + NumAsgs = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get assignment title and text", + "SELECT Title," // row[0] + "Txt" // row[1] + " FROM asg_assignments" + " WHERE AsgCod=%ld", + AsgCod); /***** Result should have a unique row *****/ - if (NumRows == 1) + if (NumAsgs == 1) { /***** Get row *****/ row = mysql_fetch_row (mysql_res); @@ -1727,36 +1732,37 @@ static void Asg_GetAndWriteNamesOfGrpsAssociatedToAsg (struct Asg_Assignment *As extern const char *Txt_The_whole_course; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRow; - unsigned long NumRows; + unsigned NumGrps; + unsigned NumGrp; /***** Get groups associated to an assignment from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get groups of an assignment", - "SELECT grp_types.GrpTypName," // row[0] - "grp_groups.GrpName" // row[1] - " FROM asg_groups," - "grp_groups," - "grp_types" - " WHERE asg_groups.AsgCod=%ld" - " AND asg_groups.GrpCod=grp_groups.GrpCod" - " AND grp_groups.GrpTypCod=grp_types.GrpTypCod" - " ORDER BY grp_types.GrpTypName," - "grp_groups.GrpName", - Asg->AsgCod); + NumGrps = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get groups of an assignment", + "SELECT grp_types.GrpTypName," // row[0] + "grp_groups.GrpName" // row[1] + " FROM asg_groups," + "grp_groups," + "grp_types" + " WHERE asg_groups.AsgCod=%ld" + " AND asg_groups.GrpCod=grp_groups.GrpCod" + " AND grp_groups.GrpTypCod=grp_types.GrpTypCod" + " ORDER BY grp_types.GrpTypName," + "grp_groups.GrpName", + Asg->AsgCod); /***** Write heading *****/ HTM_DIV_Begin ("class=\"%s\"",Asg->Hidden ? "ASG_GRP_LIGHT" : "ASG_GRP"); - HTM_TxtColonNBSP (NumRows == 1 ? Txt_Group : + HTM_TxtColonNBSP (NumGrps == 1 ? Txt_Group : Txt_Groups); /***** Write groups *****/ - if (NumRows) // Groups found... + if (NumGrps) // Groups found... { /* Get and write the group types and names */ - for (NumRow = 0; - NumRow < NumRows; - NumRow++) + for (NumGrp = 0; + NumGrp < NumGrps; + NumGrp++) { /* Get next group */ row = mysql_fetch_row (mysql_res); @@ -1764,12 +1770,12 @@ static void Asg_GetAndWriteNamesOfGrpsAssociatedToAsg (struct Asg_Assignment *As /* Write group type name and group name */ HTM_TxtF ("%s %s",row[0],row[1]); - if (NumRows >= 2) + if (NumGrps >= 2) { - if (NumRow == NumRows-2) + if (NumGrp == NumGrps - 2) HTM_TxtF (" %s ",Txt_and); - if (NumRows >= 3) - if (NumRow < NumRows-2) + if (NumGrps >= 3) + if (NumGrp < NumGrps - 2) HTM_Txt (", "); } } diff --git a/swad_attendance.c b/swad_attendance.c index 974b880e..6cbb47c2 100644 --- a/swad_attendance.c +++ b/swad_attendance.c @@ -668,7 +668,6 @@ static void Att_GetListAttEvents (struct Att_Events *Events, [Dat_END_TIME ][Att_OLDEST_FIRST] = "EndTime,StartTime,Title", }; MYSQL_RES *mysql_res; - unsigned long NumRows; unsigned NumAttEvent; if (Events->LstIsRead) @@ -676,42 +675,42 @@ static void Att_GetListAttEvents (struct Att_Events *Events, /***** Get list of attendance events from database *****/ if (Gbl.Crs.Grps.WhichGrps == Grp_MY_GROUPS) - NumRows = DB_QuerySELECT (&mysql_res,"can not get attendance events", - "SELECT AttCod" - " FROM att_events" - " WHERE CrsCod=%ld" - "%s" - " AND (AttCod NOT IN" - " (SELECT AttCod" - " FROM att_groups)" - " OR" - " AttCod IN" - " (SELECT att_groups.AttCod" - " FROM grp_users," - "att_groups" - " WHERE grp_users.UsrCod=%ld" - " AND att_groups.GrpCod=grp_users.GrpCod))" - " ORDER BY %s", - Gbl.Hierarchy.Crs.CrsCod, - HiddenSubQuery[Gbl.Usrs.Me.Role.Logged], - Gbl.Usrs.Me.UsrDat.UsrCod, - OrderBySubQuery[Events->SelectedOrder][OrderNewestOldest]); + Events->Num = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get attendance events", + "SELECT AttCod" + " FROM att_events" + " WHERE CrsCod=%ld" + "%s" + " AND (AttCod NOT IN" + " (SELECT AttCod" + " FROM att_groups)" + " OR" + " AttCod IN" + " (SELECT att_groups.AttCod" + " FROM grp_users," + "att_groups" + " WHERE grp_users.UsrCod=%ld" + " AND att_groups.GrpCod=grp_users.GrpCod))" + " ORDER BY %s", + Gbl.Hierarchy.Crs.CrsCod, + HiddenSubQuery[Gbl.Usrs.Me.Role.Logged], + Gbl.Usrs.Me.UsrDat.UsrCod, + OrderBySubQuery[Events->SelectedOrder][OrderNewestOldest]); else // Gbl.Crs.Grps.WhichGrps == Grp_ALL_GROUPS - NumRows = DB_QuerySELECT (&mysql_res,"can not get attendance events", - "SELECT AttCod" - " FROM att_events" - " WHERE CrsCod=%ld%s" - " ORDER BY %s", - Gbl.Hierarchy.Crs.CrsCod, - HiddenSubQuery[Gbl.Usrs.Me.Role.Logged], - OrderBySubQuery[Events->SelectedOrder][OrderNewestOldest]); + Events->Num = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get attendance events", + "SELECT AttCod" + " FROM att_events" + " WHERE CrsCod=%ld%s" + " ORDER BY %s", + Gbl.Hierarchy.Crs.CrsCod, + HiddenSubQuery[Gbl.Usrs.Me.Role.Logged], + OrderBySubQuery[Events->SelectedOrder][OrderNewestOldest]); - if (NumRows) // Attendance events found... + if (Events->Num) // Attendance events found... { - Events->Num = (unsigned) NumRows; - /***** Create list of attendance events *****/ - if ((Events->Lst = calloc (NumRows,sizeof (*Events->Lst))) == NULL) + if ((Events->Lst = calloc (Events->Num,sizeof (*Events->Lst))) == NULL) Lay_NotEnoughMemoryExit (); /***** Get the attendance events codes *****/ @@ -724,8 +723,6 @@ static void Att_GetListAttEvents (struct Att_Events *Events, Lay_ShowErrorAndExit ("Error: wrong attendance event code."); } } - else - Events->Num = 0; /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -758,7 +755,7 @@ bool Att_GetDataOfAttEventByCod (struct Att_Event *Event) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; + unsigned NumAttEvents; bool Found = false; /***** Reset attendance event data *****/ @@ -767,22 +764,23 @@ bool Att_GetDataOfAttEventByCod (struct Att_Event *Event) if (Event->AttCod > 0) { /***** Build query *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get attendance event data", - "SELECT AttCod," // row[0] - "CrsCod," // row[1] - "Hidden," // row[2] - "UsrCod," // row[3] - "UNIX_TIMESTAMP(StartTime)," // row[4] - "UNIX_TIMESTAMP(EndTime)," // row[5] - "NOW() BETWEEN StartTime AND EndTime," // row[6] - "CommentTchVisible," // row[7] - "Title" // row[8] - " FROM att_events" - " WHERE AttCod=%ld", - Event->AttCod); + NumAttEvents = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get attendance event data", + "SELECT AttCod," // row[0] + "CrsCod," // row[1] + "Hidden," // row[2] + "UsrCod," // row[3] + "UNIX_TIMESTAMP(StartTime)," // row[4] + "UNIX_TIMESTAMP(EndTime)," // row[5] + "NOW() BETWEEN StartTime AND EndTime," // row[6] + "CommentTchVisible," // row[7] + "Title" // row[8] + " FROM att_events" + " WHERE AttCod=%ld", + Event->AttCod); /***** Get data of attendance event from database *****/ - if ((Found = (NumRows != 0))) // Attendance event found... + if ((Found = (NumAttEvents != 0))) // Attendance event found... { /* Get row */ row = mysql_fetch_row (mysql_res); @@ -2236,11 +2234,12 @@ static void Att_PutParamsCodGrps (long AttCod) /***** Get groups associated to an attendance event from database *****/ if (Gbl.Crs.Grps.NumGrps) - NumGrps = (unsigned) DB_QuerySELECT (&mysql_res,"can not get groups of an attendance event", - "SELECT GrpCod" // row[0] - " FROM att_groups" - " WHERE att_groups.AttCod=%ld", - AttCod); + NumGrps = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get groups of an attendance event", + "SELECT GrpCod" // row[0] + " FROM att_groups" + " WHERE att_groups.AttCod=%ld", + AttCod); else NumGrps = 0; @@ -2572,21 +2571,19 @@ static bool Att_CheckIfUsrIsPresentInAttEventAndGetComments (long AttCod,long Us { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; bool Present; /***** Check if a students is registered in an event in database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get if a student" - " is already registered in an event", - "SELECT Present," // row[0] - "CommentStd," // row[1] - "CommentTch" // row[2] - " FROM att_users" - " WHERE AttCod=%ld" - " AND UsrCod=%ld", - AttCod, - UsrCod); - if (NumRows) + if (DB_QuerySELECT (&mysql_res,"can not get if a student" + " is already registered in an event", + "SELECT Present," // row[0] + "CommentStd," // row[1] + "CommentTch" // row[2] + " FROM att_users" + " WHERE AttCod=%ld" + " AND UsrCod=%ld", + AttCod, + UsrCod)) { /* Get row */ row = mysql_fetch_row (mysql_res); diff --git a/swad_banner.c b/swad_banner.c index 9776da9a..f77fc4b9 100644 --- a/swad_banner.c +++ b/swad_banner.c @@ -83,7 +83,7 @@ static void Ban_PutIconToEditBanners (void); static void Ban_EditBannersInternal (struct Ban_Banners *Banners, const struct Ban_Banner *Ban); static void Ban_GetListBanners (struct Ban_Banners *Banners, - MYSQL_RES **mysql_res,unsigned long NumRows); + MYSQL_RES **mysql_res,unsigned NumBanners); static void Ban_FreeListBanners (struct Ban_Banners *Banners); static void Ban_PutIconsEditingBanners (__attribute__((unused)) void *Args); @@ -134,23 +134,24 @@ void Ban_SeeBanners (void) extern const char *Txt_New_banner; struct Ban_Banners Banners; MYSQL_RES *mysql_res; - unsigned long NumRows; + unsigned NumBanners; /***** Reset banners *****/ Ban_ResetBanners (&Banners); /***** Get list of banners *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get banners", - "SELECT BanCod," // row[0] - "Hidden," // row[1] - "ShortName," // row[2] - "FullName," // row[3] - "Img," // row[4] - "WWW" // row[5] - " FROM ban_banners" - " WHERE Hidden='N'" - " ORDER BY ShortName"); - Ban_GetListBanners (&Banners,&mysql_res,NumRows); + NumBanners = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get banners", + "SELECT BanCod," // row[0] + "Hidden," // row[1] + "ShortName," // row[2] + "FullName," // row[3] + "Img," // row[4] + "WWW" // row[5] + " FROM ban_banners" + " WHERE Hidden='N'" + " ORDER BY ShortName"); + Ban_GetListBanners (&Banners,&mysql_res,NumBanners); /***** Begin box *****/ Box_BoxBegin (NULL,Txt_Banners, @@ -258,19 +259,20 @@ static void Ban_EditBannersInternal (struct Ban_Banners *Banners, extern const char *Hlp_SYSTEM_Banners_edit; extern const char *Txt_Banners; MYSQL_RES *mysql_res; - unsigned long NumRows; + unsigned NumBanners; /***** Get list of banners *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get banners", - "SELECT BanCod," // row[0] - "Hidden," // row[1] - "ShortName," // row[2] - "FullName," // row[3] - "Img," // row[4] - "WWW" // row[5] - " FROM ban_banners" - " ORDER BY ShortName"); - Ban_GetListBanners (Banners,&mysql_res,NumRows); + NumBanners = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get banners", + "SELECT BanCod," // row[0] + "Hidden," // row[1] + "ShortName," // row[2] + "FullName," // row[3] + "Img," // row[4] + "WWW" // row[5] + " FROM ban_banners" + " ORDER BY ShortName"); + Ban_GetListBanners (Banners,&mysql_res,NumBanners); /***** Begin box *****/ Box_BoxBegin (NULL,Txt_Banners, @@ -296,19 +298,19 @@ static void Ban_EditBannersInternal (struct Ban_Banners *Banners, /*****************************************************************************/ static void Ban_GetListBanners (struct Ban_Banners *Banners, - MYSQL_RES **mysql_res,unsigned long NumRows) + MYSQL_RES **mysql_res,unsigned NumBanners) { MYSQL_ROW row; unsigned NumBan; struct Ban_Banner *Ban; /***** Get banners from database *****/ - if (NumRows) // Banners found... + Banners->Num = NumBanners; + if (Banners->Num) // Banners found... { - Banners->Num = (unsigned) NumRows; /***** Create list with banners *****/ - if ((Banners->Lst = calloc (NumRows,sizeof (*Banners->Lst))) == NULL) + if ((Banners->Lst = calloc ((size_t) Banners->Num,sizeof (*Banners->Lst))) == NULL) Lay_NotEnoughMemoryExit (); /***** Get the banners *****/ @@ -336,8 +338,6 @@ static void Ban_GetListBanners (struct Ban_Banners *Banners, Str_Copy (Ban->WWW ,row[5],sizeof (Ban->WWW ) - 1); } } - else - Banners->Num = 0; /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (mysql_res); @@ -351,7 +351,6 @@ void Ban_GetDataOfBannerByCod (struct Ban_Banner *Ban) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; /***** Clear data *****/ Ban->Hidden = false; @@ -361,16 +360,15 @@ void Ban_GetDataOfBannerByCod (struct Ban_Banner *Ban) if (Ban->BanCod > 0) { /***** Get data of a banner from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a banner", - "SELECT Hidden," // row[0] - "ShortName," // row[1] - "FullName," // row[2] - "Img," // row[3] - "WWW" // row[4] - " FROM ban_banners" - " WHERE BanCod=%ld", - Ban->BanCod); - if (NumRows) // Banner found... + if (DB_QuerySELECT (&mysql_res,"can not get data of a banner", + "SELECT Hidden," // row[0] + "ShortName," // row[1] + "FullName," // row[2] + "Img," // row[3] + "WWW" // row[4] + " FROM ban_banners" + " WHERE BanCod=%ld", + Ban->BanCod)) // Banner found... { /* Get row */ row = mysql_fetch_row (mysql_res); @@ -1103,7 +1101,7 @@ void Ban_WriteMenuWithBanners (void) { struct Ban_Banners Banners; MYSQL_RES *mysql_res; - unsigned long NumRows; + unsigned NumBanners; unsigned NumBan; /***** Reset banners *****/ @@ -1111,21 +1109,22 @@ void Ban_WriteMenuWithBanners (void) /***** Get random banner *****/ // The banner(s) will change once in a while - NumRows = DB_QuerySELECT (&mysql_res,"can not get banners", - "SELECT BanCod," // row[0] - "Hidden," // row[1] - "ShortName," // row[2] - "FullName," // row[3] - "Img," // row[4] - "WWW" // row[5] - " FROM ban_banners" - " WHERE Hidden='N'" - " ORDER BY RAND(%lu)" - " LIMIT %u", - (unsigned long) (Gbl.StartExecutionTimeUTC / - Cfg_TIME_TO_CHANGE_BANNER), - Cfg_NUMBER_OF_BANNERS); - Ban_GetListBanners (&Banners,&mysql_res,NumRows); + NumBanners = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get banners", + "SELECT BanCod," // row[0] + "Hidden," // row[1] + "ShortName," // row[2] + "FullName," // row[3] + "Img," // row[4] + "WWW" // row[5] + " FROM ban_banners" + " WHERE Hidden='N'" + " ORDER BY RAND(%lu)" + " LIMIT %u", + (unsigned long) (Gbl.StartExecutionTimeUTC / + Cfg_TIME_TO_CHANGE_BANNER), + Cfg_NUMBER_OF_BANNERS); + Ban_GetListBanners (&Banners,&mysql_res,NumBanners); /***** Write all the banners *****/ for (NumBan = 0; diff --git a/swad_building.c b/swad_building.c index d1fcca29..8f857b91 100644 --- a/swad_building.c +++ b/swad_building.c @@ -318,7 +318,6 @@ void Bld_GetListBuildings (struct Bld_Buildings *Buildings, }; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; unsigned NumBuilding; struct Bld_Building *Building; @@ -326,36 +325,36 @@ void Bld_GetListBuildings (struct Bld_Buildings *Buildings, switch (WhichData) { case Bld_ALL_DATA: - NumRows = DB_QuerySELECT (&mysql_res,"can not get buildings", - "SELECT BldCod," // row[0] - "ShortName," // row[1] - "FullName," // row[2] - "Location" // row[3] - " FROM bld_buildings" - " WHERE CtrCod=%ld" - " ORDER BY %s", - Gbl.Hierarchy.Ctr.CtrCod, - OrderBySubQuery[Buildings->SelectedOrder]); + Buildings->Num = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get buildings", + "SELECT BldCod," // row[0] + "ShortName," // row[1] + "FullName," // row[2] + "Location" // row[3] + " FROM bld_buildings" + " WHERE CtrCod=%ld" + " ORDER BY %s", + Gbl.Hierarchy.Ctr.CtrCod, + OrderBySubQuery[Buildings->SelectedOrder]); break; case Bld_ONLY_SHRT_NAME: default: - NumRows = DB_QuerySELECT (&mysql_res,"can not get buildings", - "SELECT BldCod," // row[0] - "ShortName" // row[1] - " FROM bld_buildings" - " WHERE CtrCod=%ld" - " ORDER BY ShortName", - Gbl.Hierarchy.Ctr.CtrCod); + Buildings->Num = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get buildings", + "SELECT BldCod," // row[0] + "ShortName" // row[1] + " FROM bld_buildings" + " WHERE CtrCod=%ld" + " ORDER BY ShortName", + Gbl.Hierarchy.Ctr.CtrCod); break; } /***** Count number of rows in result *****/ - if (NumRows) // Buildings found... + if (Buildings->Num) // Buildings found... { - Buildings->Num = (unsigned) NumRows; - /***** Create list with courses in center *****/ - if ((Buildings->Lst = calloc (NumRows,sizeof (*Buildings->Lst))) == NULL) + if ((Buildings->Lst = calloc ((size_t) Buildings->Num,sizeof (*Buildings->Lst))) == NULL) Lay_NotEnoughMemoryExit (); /***** Get the buildings *****/ @@ -383,8 +382,6 @@ void Bld_GetListBuildings (struct Bld_Buildings *Buildings, } } } - else - Buildings->Num = 0; /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -398,7 +395,6 @@ void Bld_GetDataOfBuildingByCod (struct Bld_Building *Building) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; /***** Clear data *****/ Building->ShrtName[0] = '\0'; @@ -409,16 +405,13 @@ void Bld_GetDataOfBuildingByCod (struct Bld_Building *Building) if (Building->BldCod > 0) { /***** Get data of a building from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a building", - "SELECT ShortName," // row[0] - "FullName," // row[1] - "Location" // row[2] - " FROM bld_buildings" - " WHERE BldCod=%ld", - Building->BldCod); - - /***** Count number of rows in result *****/ - if (NumRows) // Building found... + if (DB_QuerySELECT (&mysql_res,"can not get data of a building", + "SELECT ShortName," // row[0] + "FullName," // row[1] + "Location" // row[2] + " FROM bld_buildings" + " WHERE BldCod=%ld", + Building->BldCod)) // Building found... { /* Get row */ row = mysql_fetch_row (mysql_res); diff --git a/swad_call_for_exam.c b/swad_call_for_exam.c index 8caf5b45..835d7d46 100644 --- a/swad_call_for_exam.c +++ b/swad_call_for_exam.c @@ -683,8 +683,8 @@ static void Cfe_ListCallsForExams (struct Cfe_CallsForExams *CallsForExams, extern const char *Txt_No_calls_for_exams_of_X; char SubQueryStatus[64]; MYSQL_RES *mysql_res; - unsigned long NumExaAnn; - unsigned long NumExaAnns; + unsigned NumExaAnns; + unsigned NumExaAnn; long ExaCod; bool HighLight; bool ICanEdit = (Gbl.Usrs.Me.Role.Logged == Rol_TCH || @@ -700,14 +700,16 @@ static void Cfe_ListCallsForExams (struct Cfe_CallsForExams *CallsForExams, /***** Get calls for exams (the most recent first) in current course from database *****/ - NumExaAnns = DB_QuerySELECT (&mysql_res,"can not get calls for exams" - " in this course for listing", - "SELECT ExaCod" // row[0] - " FROM cfe_exams" - " WHERE CrsCod=%ld" - " AND %s" - " ORDER BY ExamDate DESC", - Gbl.Hierarchy.Crs.CrsCod,SubQueryStatus); + NumExaAnns = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get calls for exams" + " in this course for listing", + "SELECT ExaCod" // row[0] + " FROM cfe_exams" + " WHERE CrsCod=%ld" + " AND %s" + " ORDER BY ExamDate DESC", + Gbl.Hierarchy.Crs.CrsCod, + SubQueryStatus); /***** Begin box *****/ if (ICanEdit) @@ -887,24 +889,24 @@ void Cfe_CreateListCallsForExams (struct Cfe_CallsForExams *CallsForExams) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumExaAnn; - unsigned long NumExaAnns; + unsigned NumExaAnns; + unsigned NumExaAnn; if (Gbl.DB.DatabaseIsOpen) { /***** Get exam dates (ordered from more recent to older) of visible calls for exams in current course from database *****/ - NumExaAnns = DB_QuerySELECT (&mysql_res,"can not get calls for exams" - " in this course", - "SELECT ExaCod," // row[0] - "DATE(ExamDate)" // row[1] - " FROM cfe_exams" - " WHERE CrsCod=%ld" - " AND Status=%u" - " ORDER BY ExamDate DESC", - Gbl.Hierarchy.Crs.CrsCod, - (unsigned) Cfe_VISIBLE_CALL_FOR_EXAM); + NumExaAnns = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get calls for exams in this course", + "SELECT ExaCod," // row[0] + "DATE(ExamDate)" // row[1] + " FROM cfe_exams" + " WHERE CrsCod=%ld" + " AND Status=%u" + " ORDER BY ExamDate DESC", + Gbl.Hierarchy.Crs.CrsCod, + (unsigned) Cfe_VISIBLE_CALL_FOR_EXAM); /***** The result of the query may be empty *****/ CallsForExams->Lst = NULL; @@ -966,36 +968,31 @@ static void Cfe_GetDataCallForExamFromDB (struct Cfe_CallsForExams *CallsForExam { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumExaAnns; unsigned UnsignedNum; unsigned Hour; unsigned Minute; unsigned Second; /***** Get data of a call for exam from database *****/ - NumExaAnns = DB_QuerySELECT (&mysql_res,"can not get data" - " of a call for exam", - "SELECT CrsCod," // row[ 0] - "Status," // row[ 1] - "CrsFullName," // row[ 2] - "Year," // row[ 3] - "ExamSession," // row[ 4] - "CallDate," // row[ 5] - "ExamDate," // row[ 6] - "Duration," // row[ 7] - "Place," // row[ 8] - "ExamMode," // row[ 9] - "Structure," // row[10] - "DocRequired," // row[11] - "MatRequired," // row[12] - "MatAllowed," // row[13] - "OtherInfo" // row[14] - " FROM cfe_exams" - " WHERE ExaCod=%ld", - ExaCod); - - /***** The result of the query must have one row *****/ - if (NumExaAnns != 1) + if (DB_QuerySELECT (&mysql_res,"can not get data of a call for exam", + "SELECT CrsCod," // row[ 0] + "Status," // row[ 1] + "CrsFullName," // row[ 2] + "Year," // row[ 3] + "ExamSession," // row[ 4] + "CallDate," // row[ 5] + "ExamDate," // row[ 6] + "Duration," // row[ 7] + "Place," // row[ 8] + "ExamMode," // row[ 9] + "Structure," // row[10] + "DocRequired," // row[11] + "MatRequired," // row[12] + "MatAllowed," // row[13] + "OtherInfo" // row[14] + " FROM cfe_exams" + " WHERE ExaCod=%ld", + ExaCod) != 1) Lay_WrongCallForExamExit (); /***** Get the data of the call for exam *****/ diff --git a/swad_center.c b/swad_center.c index 5b315f70..a1c0168b 100644 --- a/swad_center.c +++ b/swad_center.c @@ -550,35 +550,32 @@ void Ctr_GetBasicListOfCenters (long InsCod) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; unsigned NumCtr; struct Ctr_Center *Ctr; /***** Get centers from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get centers", - "SELECT CtrCod," // row[ 0] - "InsCod," // row[ 1] - "PlcCod," // row[ 2] - "Status," // row[ 3] - "RequesterUsrCod," // row[ 4] - "Latitude," // row[ 5] - "Longitude," // row[ 6] - "Altitude," // row[ 7] - "ShortName," // row[ 8] - "FullName," // row[ 9] - "WWW" // row[10] - " FROM ctr_centers" - " WHERE InsCod=%ld" - " ORDER BY FullName", - InsCod); + Gbl.Hierarchy.Ctrs.Num = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get centers", + "SELECT CtrCod," // row[ 0] + "InsCod," // row[ 1] + "PlcCod," // row[ 2] + "Status," // row[ 3] + "RequesterUsrCod," // row[ 4] + "Latitude," // row[ 5] + "Longitude," // row[ 6] + "Altitude," // row[ 7] + "ShortName," // row[ 8] + "FullName," // row[ 9] + "WWW" // row[10] + " FROM ctr_centers" + " WHERE InsCod=%ld" + " ORDER BY FullName", + InsCod); - if (NumRows) // Centers found... + if (Gbl.Hierarchy.Ctrs.Num) // Centers found... { - // NumRows should be equal to Deg->NumCourses - Gbl.Hierarchy.Ctrs.Num = (unsigned) NumRows; - /***** Create list with courses in degree *****/ - if ((Gbl.Hierarchy.Ctrs.Lst = calloc (NumRows, + if ((Gbl.Hierarchy.Ctrs.Lst = calloc ((size_t) Gbl.Hierarchy.Ctrs.Num, sizeof (*Gbl.Hierarchy.Ctrs.Lst))) == NULL) Lay_NotEnoughMemoryExit (); @@ -597,8 +594,6 @@ void Ctr_GetBasicListOfCenters (long InsCod) Ctr->NumUsrsWhoClaimToBelongToCtr.Valid = false; } } - else - Gbl.Hierarchy.Ctrs.Num = 0; /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -618,58 +613,55 @@ void Ctr_GetFullListOfCenters (long InsCod) }; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; unsigned NumCtr; struct Ctr_Center *Ctr; /***** Get centers from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get centers", - "(SELECT ctr_centers.CtrCod," // row[ 0] - "ctr_centers.InsCod," // row[ 1] - "ctr_centers.PlcCod," // row[ 2] - "ctr_centers.Status," // row[ 3] - "ctr_centers.RequesterUsrCod," // row[ 4] - "ctr_centers.Latitude," // row[ 5] - "ctr_centers.Longitude," // row[ 6] - "ctr_centers.Altitude," // row[ 7] - "ctr_centers.ShortName," // row[ 8] - "ctr_centers.FullName," // row[ 9] - "ctr_centers.WWW," // row[10] - "COUNT(*) AS NumUsrs" // row[11] - " FROM ctr_centers,usr_data" - " WHERE ctr_centers.InsCod=%ld" - " AND ctr_centers.CtrCod=usr_data.CtrCod" - " GROUP BY ctr_centers.CtrCod)" - " UNION " - "(SELECT CtrCod," // row[ 0] - "InsCod," // row[ 1] - "PlcCod," // row[ 2] - "Status," // row[ 3] - "RequesterUsrCod," // row[ 4] - "Latitude," // row[ 5] - "Longitude," // row[ 6] - "Altitude," // row[ 7] - "ShortName," // row[ 8] - "FullName," // row[ 9] - "WWW," // row[10] - "0 AS NumUsrs" // row[11] - " FROM ctr_centers" - " WHERE InsCod=%ld" - " AND CtrCod NOT IN" - " (SELECT DISTINCT CtrCod" - " FROM usr_data))" - " ORDER BY %s", - InsCod, - InsCod, - OrderBySubQuery[Gbl.Hierarchy.Ctrs.SelectedOrder]); + Gbl.Hierarchy.Ctrs.Num = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get centers", + "(SELECT ctr_centers.CtrCod," // row[ 0] + "ctr_centers.InsCod," // row[ 1] + "ctr_centers.PlcCod," // row[ 2] + "ctr_centers.Status," // row[ 3] + "ctr_centers.RequesterUsrCod," // row[ 4] + "ctr_centers.Latitude," // row[ 5] + "ctr_centers.Longitude," // row[ 6] + "ctr_centers.Altitude," // row[ 7] + "ctr_centers.ShortName," // row[ 8] + "ctr_centers.FullName," // row[ 9] + "ctr_centers.WWW," // row[10] + "COUNT(*) AS NumUsrs" // row[11] + " FROM ctr_centers,usr_data" + " WHERE ctr_centers.InsCod=%ld" + " AND ctr_centers.CtrCod=usr_data.CtrCod" + " GROUP BY ctr_centers.CtrCod)" + " UNION " + "(SELECT CtrCod," // row[ 0] + "InsCod," // row[ 1] + "PlcCod," // row[ 2] + "Status," // row[ 3] + "RequesterUsrCod," // row[ 4] + "Latitude," // row[ 5] + "Longitude," // row[ 6] + "Altitude," // row[ 7] + "ShortName," // row[ 8] + "FullName," // row[ 9] + "WWW," // row[10] + "0 AS NumUsrs" // row[11] + " FROM ctr_centers" + " WHERE InsCod=%ld" + " AND CtrCod NOT IN" + " (SELECT DISTINCT CtrCod" + " FROM usr_data))" + " ORDER BY %s", + InsCod, + InsCod, + OrderBySubQuery[Gbl.Hierarchy.Ctrs.SelectedOrder]); - if (NumRows) // Centers found... + if (Gbl.Hierarchy.Ctrs.Num) // Centers found... { - // NumRows should be equal to Deg->NumCourses - Gbl.Hierarchy.Ctrs.Num = (unsigned) NumRows; - /***** Create list with courses in degree *****/ - if ((Gbl.Hierarchy.Ctrs.Lst = calloc (NumRows, + if ((Gbl.Hierarchy.Ctrs.Lst = calloc ((size_t) Gbl.Hierarchy.Ctrs.Num, sizeof (*Gbl.Hierarchy.Ctrs.Lst))) == NULL) Lay_NotEnoughMemoryExit (); @@ -690,8 +682,6 @@ void Ctr_GetFullListOfCenters (long InsCod) Ctr->NumUsrsWhoClaimToBelongToCtr.Valid = true; } } - else - Gbl.Hierarchy.Ctrs.Num = 0; /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -705,7 +695,6 @@ bool Ctr_GetDataOfCenterByCod (struct Ctr_Center *Ctr) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; bool CtrFound = false; /***** Clear data *****/ @@ -722,22 +711,21 @@ bool Ctr_GetDataOfCenterByCod (struct Ctr_Center *Ctr) if (Ctr->CtrCod > 0) { /***** Get data of a center from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a center", - "SELECT CtrCod," // row[ 0] - "InsCod," // row[ 1] - "PlcCod," // row[ 2] - "Status," // row[ 3] - "RequesterUsrCod," // row[ 4] - "Latitude," // row[ 5] - "Longitude," // row[ 6] - "Altitude," // row[ 7] - "ShortName," // row[ 8] - "FullName," // row[ 9] - "WWW" // row[10] - " FROM ctr_centers" - " WHERE CtrCod=%ld", - Ctr->CtrCod); - if (NumRows) // Center found... + if (DB_QuerySELECT (&mysql_res,"can not get data of a center", + "SELECT CtrCod," // row[ 0] + "InsCod," // row[ 1] + "PlcCod," // row[ 2] + "Status," // row[ 3] + "RequesterUsrCod," // row[ 4] + "Latitude," // row[ 5] + "Longitude," // row[ 6] + "Altitude," // row[ 7] + "ShortName," // row[ 8] + "FullName," // row[ 9] + "WWW" // row[10] + " FROM ctr_centers" + " WHERE CtrCod=%ld", + Ctr->CtrCod)) // Center found... { /* Get row */ row = mysql_fetch_row (mysql_res); diff --git a/swad_changelog.h b/swad_changelog.h index 0d1b3d28..5475cdc2 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -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. */ -#define Log_PLATFORM_VERSION "SWAD 20.62 (2021-04-15)" +#define Log_PLATFORM_VERSION "SWAD 20.63 (2021-04-16)" #define CSS_FILE "swad20.45.css" #define JS_FILE "swad20.6.2.js" /* TODO: Rename CENTRE to CENTER in help wiki. TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams + Version 20.63: Apr 16, 2021 Optimizations in database selects. (308487 lines) Version 20.62: Apr 15, 2021 Optimizations in database selects related to roles. (308574 lines) Version 20.61: Apr 13, 2021 Optimizations in database selects. (308567 lines) Version 20.60: Apr 07, 2021 Optimizations in database selects. (308790 lines) diff --git a/swad_chat.c b/swad_chat.c index b2a3b768..8f211687 100644 --- a/swad_chat.c +++ b/swad_chat.c @@ -114,8 +114,8 @@ void Cht_ShowListOfAvailableChatRooms (void) struct Crs_Course Crs; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRow; - unsigned long NumRows; + unsigned NumCrss; + unsigned NumCrs; char ThisRoomCode [Cht_MAX_BYTES_ROOM_CODE + 1]; char ThisRoomShrtName[Cht_MAX_BYTES_ROOM_SHRT_NAME + 1]; char ThisRoomFullName[Cht_MAX_BYTES_ROOM_FULL_NAME + 1]; @@ -190,33 +190,33 @@ void Cht_ShowListOfAvailableChatRooms (void) Cht_WriteLinkToChat2 (ThisRoomCode,ThisRoomFullName); /* Get my courses in this degree from database */ - if ((NumRows = Usr_GetCrssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,Deg.DegCod,&mysql_res)) > 0) // Courses found in this degree - for (NumRow = 0; - NumRow < NumRows; - NumRow++) + NumCrss = Usr_GetCrssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,Deg.DegCod,&mysql_res); + for (NumCrs = 0; + NumCrs < NumCrss; + NumCrs++) + { + /* Get next course */ + row = mysql_fetch_row (mysql_res); + + /* Get course code */ + if ((Crs.CrsCod = Str_ConvertStrCodToLongCod (row[0])) > 0) { - /* Get next course */ - row = mysql_fetch_row (mysql_res); + /* Get data of this course */ + Crs_GetDataOfCourseByCod (&Crs); - /* Get course code */ - if ((Crs.CrsCod = Str_ConvertStrCodToLongCod (row[0])) > 0) - { - /* Get data of this course */ - Crs_GetDataOfCourseByCod (&Crs); - - /* Link to the room of this course */ - IsLastItemInLevel[2] = (NumRow == NumRows - 1); - snprintf (ThisRoomCode,sizeof (ThisRoomCode),"CRS_%ld", - Crs.CrsCod); - snprintf (ThisRoomShrtName,sizeof (ThisRoomShrtName),"%s", - Crs.ShrtName); - snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),"%s %s", - Txt_Course,Crs.ShrtName); - Cht_WriteLinkToChat1 (ThisRoomCode,ThisRoomShrtName,ThisRoomFullName,2,IsLastItemInLevel); - Ico_PutIcon ("chalkboard-teacher.svg",ThisRoomFullName,"ICO16x16"); - Cht_WriteLinkToChat2 (ThisRoomCode,ThisRoomFullName); - } + /* Link to the room of this course */ + IsLastItemInLevel[2] = (NumCrs == NumCrss - 1); + snprintf (ThisRoomCode,sizeof (ThisRoomCode),"CRS_%ld", + Crs.CrsCod); + snprintf (ThisRoomShrtName,sizeof (ThisRoomShrtName),"%s", + Crs.ShrtName); + snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),"%s %s", + Txt_Course,Crs.ShrtName); + Cht_WriteLinkToChat1 (ThisRoomCode,ThisRoomShrtName,ThisRoomFullName,2,IsLastItemInLevel); + Ico_PutIcon ("chalkboard-teacher.svg",ThisRoomFullName,"ICO16x16"); + Cht_WriteLinkToChat2 (ThisRoomCode,ThisRoomFullName); } + } /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -238,19 +238,19 @@ void Cht_ShowListOfChatRoomsWithUsrs (void) extern const char *Txt_Number_of_users; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; - unsigned long NumRow; + unsigned NumRooms; + unsigned NumRoom; /***** Get chat rooms with connected users from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get chat rooms" - " with connected users", - "SELECT RoomCode," // row[0] - "NumUsrs" // row[1] - " FROM cht_rooms" - " WHERE NumUsrs>0" - " ORDER BY NumUsrs DESC," - "RoomCode"); - if (NumRows > 0) // If not empty chat rooms found + NumRooms = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get chat rooms with connected users", + "SELECT RoomCode," // row[0] + "NumUsrs" // row[1] + " FROM cht_rooms" + " WHERE NumUsrs>0" + " ORDER BY NumUsrs DESC," + "RoomCode"); + if (NumRooms) // If not empty chat rooms found { /***** Begin box and table *****/ Box_BoxTableBegin (NULL,Txt_Rooms_with_users, @@ -266,9 +266,9 @@ void Cht_ShowListOfChatRoomsWithUsrs (void) HTM_TR_End (); /***** Loop over chat rooms *****/ - for (NumRow = 0; - NumRow < NumRows; - NumRow++) + for (NumRoom = 0; + NumRoom < NumRooms; + NumRoom++) { /* Get next chat room */ row = mysql_fetch_row (mysql_res); diff --git a/swad_connected.c b/swad_connected.c index 7c125a49..3e8273c7 100644 --- a/swad_connected.c +++ b/swad_connected.c @@ -784,25 +784,26 @@ static void Con_ComputeConnectedUsrsWithARoleCurrentCrsOneByOne (Rol_Role_t Role { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; + unsigned NumUsrs; unsigned NumUsr = Gbl.Usrs.Connected.NumUsrs; // Save current number of users /***** Get connected users who belong to current course from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get list of connected users" - " who belong to this course", - "SELECT usr_connected.UsrCod," // row[0] - "usr_connected.LastCrsCod," // row[1] - "UNIX_TIMESTAMP()-UNIX_TIMESTAMP(usr_connected.LastTime) AS Dif" // row[2] - " FROM crs_users," - "usr_connected" - " WHERE crs_users.CrsCod=%ld" - " AND crs_users.Role=%u" - " AND crs_users.UsrCod=usr_connected.UsrCod" - " ORDER BY Dif", - Gbl.Hierarchy.Crs.CrsCod, - (unsigned) Role); - Gbl.Usrs.Connected.NumUsrs += (unsigned) NumRows; - Gbl.Usrs.Connected.NumUsrsToList += (unsigned) NumRows; + NumUsrs = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get list of connected users" + " who belong to this course", + "SELECT usr_connected.UsrCod," // row[0] + "usr_connected.LastCrsCod," // row[1] + "UNIX_TIMESTAMP()-UNIX_TIMESTAMP(usr_connected.LastTime) AS Dif" // row[2] + " FROM crs_users," + "usr_connected" + " WHERE crs_users.CrsCod=%ld" + " AND crs_users.Role=%u" + " AND crs_users.UsrCod=usr_connected.UsrCod" + " ORDER BY Dif", + Gbl.Hierarchy.Crs.CrsCod, + (unsigned) Role); + Gbl.Usrs.Connected.NumUsrs += NumUsrs; + Gbl.Usrs.Connected.NumUsrsToList += NumUsrs; if (Gbl.Usrs.Connected.NumUsrsToList > Cfg_MAX_CONNECTED_SHOWN) Gbl.Usrs.Connected.NumUsrsToList = Cfg_MAX_CONNECTED_SHOWN; diff --git a/swad_country.c b/swad_country.c index 73014cbd..9e59c0f1 100644 --- a/swad_country.c +++ b/swad_country.c @@ -753,26 +753,24 @@ void Cty_GetBasicListOfCountries (void) extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES]; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows = 0; unsigned NumCty; struct Cty_Countr *Cty; Lan_Language_t Lan; /***** Get countries from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get countries", - "SELECT CtyCod," // row[0] - "Alpha2," // row[1] - "Name_%s" // row[2] - " FROM cty_countrs" - " ORDER BY Name_%s", - Lan_STR_LANG_ID[Gbl.Prefs.Language], - Lan_STR_LANG_ID[Gbl.Prefs.Language]); - if (NumRows) // Countries found... + Gbl.Hierarchy.Ctys.Num = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get countries", + "SELECT CtyCod," // row[0] + "Alpha2," // row[1] + "Name_%s" // row[2] + " FROM cty_countrs" + " ORDER BY Name_%s", + Lan_STR_LANG_ID[Gbl.Prefs.Language], + Lan_STR_LANG_ID[Gbl.Prefs.Language]); + if (Gbl.Hierarchy.Ctys.Num) // Countries found... { - Gbl.Hierarchy.Ctys.Num = (unsigned) NumRows; - /***** Create list with countries *****/ - if ((Gbl.Hierarchy.Ctys.Lst = calloc (NumRows, + if ((Gbl.Hierarchy.Ctys.Lst = calloc ((size_t) Gbl.Hierarchy.Ctys.Num, sizeof (*Gbl.Hierarchy.Ctys.Lst))) == NULL) Lay_NotEnoughMemoryExit (); @@ -809,8 +807,6 @@ void Cty_GetBasicListOfCountries (void) Cty->NumUsrsWhoClaimToBelongToCty.Valid = false; } } - else - Gbl.Hierarchy.Ctys.Num = 0; /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -839,7 +835,6 @@ void Cty_GetFullListOfCountries (void) }; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows = 0; unsigned NumCty; struct Cty_Countr *Cty; Lan_Language_t Lan; @@ -870,39 +865,38 @@ void Cty_GetFullListOfCountries (void) Lay_NotEnoughMemoryExit (); /* Query database */ - NumRows = DB_QuerySELECT (&mysql_res,"can not get countries", - "(SELECT cty_countrs.CtyCod," // row[0] - "cty_countrs.Alpha2," // row[1] - "%s" // row[...] - "%s" // row[...] - "COUNT(*) AS NumUsrs" // row[...] - " FROM cty_countrs," - "usr_data" - " WHERE cty_countrs.CtyCod=usr_data.CtyCod" - " GROUP BY cty_countrs.CtyCod)" - " UNION " - "(SELECT CtyCod," // row[0] - "Alpha2," // row[1] - "%s" // row[...] - "%s" // row[...] - "0 AS NumUsrs" // row[...] - " FROM cty_countrs" - " WHERE CtyCod NOT IN" - " (SELECT DISTINCT CtyCod" - " FROM usr_data))" - " ORDER BY %s", - SubQueryNam1,SubQueryWWW1, - SubQueryNam2,SubQueryWWW2,OrderBySubQuery); + Gbl.Hierarchy.Ctys.Num = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get countries", + "(SELECT cty_countrs.CtyCod," // row[0] + "cty_countrs.Alpha2," // row[1] + "%s" // row[...] + "%s" // row[...] + "COUNT(*) AS NumUsrs" // row[...] + " FROM cty_countrs," + "usr_data" + " WHERE cty_countrs.CtyCod=usr_data.CtyCod" + " GROUP BY cty_countrs.CtyCod)" + " UNION " + "(SELECT CtyCod," // row[0] + "Alpha2," // row[1] + "%s" // row[...] + "%s" // row[...] + "0 AS NumUsrs" // row[...] + " FROM cty_countrs" + " WHERE CtyCod NOT IN" + " (SELECT DISTINCT CtyCod" + " FROM usr_data))" + " ORDER BY %s", + SubQueryNam1,SubQueryWWW1, + SubQueryNam2,SubQueryWWW2,OrderBySubQuery); /* Free memory for subquery */ free (OrderBySubQuery); - if (NumRows) // Countries found... + if (Gbl.Hierarchy.Ctys.Num) // Countries found... { - Gbl.Hierarchy.Ctys.Num = (unsigned) NumRows; - /***** Create list with countries *****/ - if ((Gbl.Hierarchy.Ctys.Lst = calloc (NumRows, + if ((Gbl.Hierarchy.Ctys.Lst = calloc ((size_t) Gbl.Hierarchy.Ctys.Num, sizeof (*Gbl.Hierarchy.Ctys.Lst))) == NULL) Lay_NotEnoughMemoryExit (); @@ -941,8 +935,6 @@ void Cty_GetFullListOfCountries (void) Cty->NumUsrsWhoClaimToBelongToCty.Valid = true; } } - else - Gbl.Hierarchy.Ctys.Num = 0; /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -1045,7 +1037,6 @@ bool Cty_GetDataOfCountryByCod (struct Cty_Countr *Cty) extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES]; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows = 0; Lan_Language_t Lan; bool CtyFound; @@ -1079,7 +1070,7 @@ bool Cty_GetDataOfCountryByCod (struct Cty_Countr *Cty) // Here Cty->CtyCod > 0 /***** Get data of a country from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a country", + if(DB_QuerySELECT (&mysql_res,"can not get data of a country", "SELECT Alpha2," // row[0] "Name_%s," // row[1] "WWW_%s" // row[2] @@ -1087,10 +1078,7 @@ bool Cty_GetDataOfCountryByCod (struct Cty_Countr *Cty) " WHERE CtyCod='%03ld'", Lan_STR_LANG_ID[Gbl.Prefs.Language], Lan_STR_LANG_ID[Gbl.Prefs.Language], - Cty->CtyCod); - - /***** Count number of rows in result *****/ - if (NumRows) // Country found... + Cty->CtyCod)) // Country found... { CtyFound = true; diff --git a/swad_course.c b/swad_course.c index 6a7200b6..5e0db7d4 100644 --- a/swad_course.c +++ b/swad_course.c @@ -237,8 +237,8 @@ static void Crs_WriteListMyCoursesToSelectOne (void) HTM_LI_End (); /***** Get my institutions in this country *****/ - NumInss = (unsigned) Usr_GetInssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod, - Hie.Cty.CtyCod,&mysql_resIns); + NumInss = Usr_GetInssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod, + Hie.Cty.CtyCod,&mysql_resIns); for (NumIns = 0; NumIns < NumInss; NumIns++) @@ -271,8 +271,8 @@ static void Crs_WriteListMyCoursesToSelectOne (void) HTM_LI_End (); /***** Get my centers in this institution *****/ - NumCtrs = (unsigned) Usr_GetCtrsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod, - Hie.Ins.InsCod,&mysql_resCtr); + NumCtrs = Usr_GetCtrsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod, + Hie.Ins.InsCod,&mysql_resCtr); for (NumCtr = 0; NumCtr < NumCtrs; NumCtr++) @@ -305,8 +305,8 @@ static void Crs_WriteListMyCoursesToSelectOne (void) HTM_LI_End (); /***** Get my degrees in this center *****/ - NumDegs = (unsigned) Usr_GetDegsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod, - Hie.Ctr.CtrCod,&mysql_resDeg); + NumDegs = Usr_GetDegsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod, + Hie.Ctr.CtrCod,&mysql_resDeg); for (NumDeg = 0; NumDeg < NumDegs; NumDeg++) @@ -339,8 +339,8 @@ static void Crs_WriteListMyCoursesToSelectOne (void) HTM_LI_End (); /***** Get my courses in this degree *****/ - NumCrss = (unsigned) Usr_GetCrssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod, - Hie.Deg.DegCod,&mysql_resCrs); + NumCrss = Usr_GetCrssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod, + Hie.Deg.DegCod,&mysql_resCrs); for (NumCrs = 0; NumCrs < NumCrss; NumCrs++) @@ -2992,8 +2992,8 @@ void Crs_RemoveOldCrss (void) unsigned MonthsWithoutAccess; unsigned long SecondsWithoutAccess; MYSQL_RES *mysql_res; - unsigned long NumCrs; - unsigned long NumCrss; + unsigned NumCrss; + unsigned NumCrs; unsigned NumCrssRemoved = 0; long CrsCod; @@ -3008,14 +3008,15 @@ void Crs_RemoveOldCrss (void) SecondsWithoutAccess = (unsigned long) MonthsWithoutAccess * Dat_SECONDS_IN_ONE_MONTH; /***** Get old courses from database *****/ - NumCrss = DB_QuerySELECT (&mysql_res,"can not get old courses", - "SELECT CrsCod" - " FROM crs_last" - " WHERE LastTime // For NULL #include // For FILE, vasprintf #include // For free +#include // For strlen #include "swad_config.h" #include "swad_database.h" @@ -3954,6 +3955,8 @@ void DB_QuerySELECTString (char *Str,size_t StrSize,const char *MsgError, va_list ap; int NumBytesPrinted; char *Query; + bool TooBig = false; + char ErrorTxt[256]; /***** Create query string *****/ va_start (ap,fmt); @@ -3963,16 +3966,27 @@ void DB_QuerySELECTString (char *Str,size_t StrSize,const char *MsgError, Lay_NotEnoughMemoryExit (); /***** Do SELECT query *****/ + Str[0] = '\0'; if (DB_QuerySELECTusingQueryStr (Query,&mysql_res,MsgError) == 1) // Row found { row = mysql_fetch_row (mysql_res); - Str_Copy (Str,row[0],StrSize); + + TooBig = (strlen (row[0]) > StrSize); + if (!TooBig) + Str_Copy (Str,row[0],StrSize); } - else - Str[0] = '\0'; /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); + + if (TooBig) + { + snprintf (ErrorTxt,sizeof (ErrorTxt), + "Too large string from database," + " it exceed the maximum allowed size (%zu bytes).", + StrSize); + Lay_ShowErrorAndExit (ErrorTxt); + } } /*****************************************************************************/ diff --git a/swad_degree.c b/swad_degree.c index e0261a92..9d83d756 100644 --- a/swad_degree.c +++ b/swad_degree.c @@ -1125,32 +1125,30 @@ void Deg_GetListDegsInCurrentCtr (void) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; unsigned NumDeg; struct Deg_Degree *Deg; /***** Get degrees of the current center from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get degrees of a center", - "SELECT DegCod," // row[0] - "CtrCod," // row[1] - "DegTypCod," // row[2] - "Status," // row[3] - "RequesterUsrCod," // row[4] - "ShortName," // row[5] - "FullName," // row[6] - "WWW" // row[7] - " FROM deg_degrees" - " WHERE CtrCod=%ld" - " ORDER BY FullName", - Gbl.Hierarchy.Ctr.CtrCod); + Gbl.Hierarchy.Degs.Num = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get degrees of a center", + "SELECT DegCod," // row[0] + "CtrCod," // row[1] + "DegTypCod," // row[2] + "Status," // row[3] + "RequesterUsrCod," // row[4] + "ShortName," // row[5] + "FullName," // row[6] + "WWW" // row[7] + " FROM deg_degrees" + " WHERE CtrCod=%ld" + " ORDER BY FullName", + Gbl.Hierarchy.Ctr.CtrCod); /***** Count number of rows in result *****/ - if (NumRows) // Degrees found... + if (Gbl.Hierarchy.Degs.Num) // Degrees found... { - Gbl.Hierarchy.Degs.Num = (unsigned) NumRows; - /***** Create list with degrees of this center *****/ - if ((Gbl.Hierarchy.Degs.Lst = calloc (Gbl.Hierarchy.Degs.Num, + if ((Gbl.Hierarchy.Degs.Lst = calloc ((size_t) Gbl.Hierarchy.Degs.Num, sizeof (*Gbl.Hierarchy.Degs.Lst))) == NULL) Lay_NotEnoughMemoryExit (); @@ -1166,8 +1164,6 @@ void Deg_GetListDegsInCurrentCtr (void) Deg_GetDataOfDegreeFromRow (Deg,row); } } - else - Gbl.Hierarchy.Degs.Num = 0; /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -1491,22 +1487,23 @@ long Deg_GetInsCodOfDegreeByCod (long DegCod) void Deg_RemoveDegreeCompletely (long DegCod) { MYSQL_RES *mysql_res; - unsigned long NumRows; - unsigned long NumRow; + unsigned NumCrss; + unsigned NumCrs; long CrsCod; char PathDeg[PATH_MAX + 1]; /***** Get courses of a degree from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get courses of a degree", - "SELECT CrsCod" // row[0] - " FROM crs_courses" - " WHERE DegCod=%ld", - DegCod); + NumCrss = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get courses of a degree", + "SELECT CrsCod" + " FROM crs_courses" + " WHERE DegCod=%ld", + DegCod); /* Get courses in this degree */ - for (NumRow = 0; - NumRow < NumRows; - NumRow++) + for (NumCrs = 0; + NumCrs < NumCrss; + NumCrs++) { /* Get next course */ if ((CrsCod = DB_GetNextCode (mysql_res)) < 0) diff --git a/swad_degree_type.c b/swad_degree_type.c index 3bfc4a63..b97ad8d7 100644 --- a/swad_degree_type.c +++ b/swad_degree_type.c @@ -901,21 +901,22 @@ bool DT_GetDataOfDegreeTypeByCod (struct DegreeType *DegTyp) static void DT_RemoveDegreeTypeCompletely (long DegTypCod) { MYSQL_RES *mysql_res; - unsigned long NumRows; - unsigned long NumRow; + unsigned NumDegs; + unsigned NumDeg; long DegCod; /***** Get degrees of a type from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get degrees of a type", - "SELECT DegCod" - " FROM deg_degrees" - " WHERE DegTypCod=%ld", - DegTypCod); + NumDegs = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get degrees of a type", + "SELECT DegCod" + " FROM deg_degrees" + " WHERE DegTypCod=%ld", + DegTypCod); /* Get degrees of this type */ - for (NumRow = 0; - NumRow < NumRows; - NumRow++) + for (NumDeg = 0; + NumDeg < NumDegs; + NumDeg++) { /* Get next degree */ if ((DegCod = DB_GetNextCode (mysql_res)) < 0) diff --git a/swad_department.c b/swad_department.c index a6c75dbe..26a09097 100644 --- a/swad_department.c +++ b/swad_department.c @@ -423,7 +423,6 @@ void Dpt_GetDataOfDepartmentByCod (struct Dpt_Department *Dpt) extern const char *Txt_Another_department; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; /***** Clear data *****/ Dpt->InsCod = -1L; @@ -439,38 +438,36 @@ void Dpt_GetDataOfDepartmentByCod (struct Dpt_Department *Dpt) else if (Dpt->DptCod > 0) { /***** Get data of a department from database *****/ - NumRows = - DB_QuerySELECT (&mysql_res,"can not get data of a department", - "(SELECT dpt_departments.InsCod," // row[0] - "dpt_departments.ShortName," // row[1] - "dpt_departments.FullName," // row[2] - "dpt_departments.WWW," // row[3] - "COUNT(DISTINCT usr_data.UsrCod) AS NumTchs" // row[4] - " FROM dpt_departments," - "usr_data," - "crs_users" - " WHERE dpt_departments.DptCod=%ld" - " AND dpt_departments.DptCod=usr_data.DptCod" - " AND usr_data.UsrCod=crs_users.UsrCod" - " AND crs_users.Role=%u" - " GROUP BY dpt_departments.DptCod)" - " UNION " - "(SELECT InsCod," // row[0] - "ShortName," // row[1] - "FullName," // row[2] - "WWW," // row[3] - "0" // row[4] - " FROM dpt_departments" - " WHERE DptCod=%ld" - " AND DptCod NOT IN" - " (SELECT DISTINCT usr_data.DptCod" - " FROM usr_data," - "crs_users" - " WHERE crs_users.Role=%u" - " AND crs_users.UsrCod=usr_data.UsrCod))", - Dpt->DptCod,(unsigned) Rol_TCH, - Dpt->DptCod,(unsigned) Rol_TCH); - if (NumRows) // Department found... + if (DB_QuerySELECT (&mysql_res,"can not get data of a department", + "(SELECT dpt_departments.InsCod," // row[0] + "dpt_departments.ShortName," // row[1] + "dpt_departments.FullName," // row[2] + "dpt_departments.WWW," // row[3] + "COUNT(DISTINCT usr_data.UsrCod) AS NumTchs" // row[4] + " FROM dpt_departments," + "usr_data," + "crs_users" + " WHERE dpt_departments.DptCod=%ld" + " AND dpt_departments.DptCod=usr_data.DptCod" + " AND usr_data.UsrCod=crs_users.UsrCod" + " AND crs_users.Role=%u" + " GROUP BY dpt_departments.DptCod)" + " UNION " + "(SELECT InsCod," // row[0] + "ShortName," // row[1] + "FullName," // row[2] + "WWW," // row[3] + "0" // row[4] + " FROM dpt_departments" + " WHERE DptCod=%ld" + " AND DptCod NOT IN" + " (SELECT DISTINCT usr_data.DptCod" + " FROM usr_data," + "crs_users" + " WHERE crs_users.Role=%u" + " AND crs_users.UsrCod=usr_data.UsrCod))", + Dpt->DptCod,(unsigned) Rol_TCH, + Dpt->DptCod,(unsigned) Rol_TCH)) // Department found... { /* Get row */ row = mysql_fetch_row (mysql_res); diff --git a/swad_duplicate.c b/swad_duplicate.c index fedea37a..dbd358b0 100644 --- a/swad_duplicate.c +++ b/swad_duplicate.c @@ -274,34 +274,36 @@ static void Dup_ListSimilarUsrs (void) /***** Make query *****/ if (Gbl.Usrs.Other.UsrDat.Surname1[0] && Gbl.Usrs.Other.UsrDat.FrstName[0]) // Name and surname 1 not empty - NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get similar users", - "SELECT DISTINCT UsrCod" - " FROM (SELECT DISTINCT UsrCod" - " FROM usr_ids" - " WHERE UsrID IN" - " (SELECT UsrID" - " FROM usr_ids" - " WHERE UsrCod=%ld)" - " UNION" - " SELECT UsrCod" - " FROM usr_data" - " WHERE Surname1='%s'" - " AND Surname2='%s'" - " AND FirstName='%s')" - " AS U", - Gbl.Usrs.Other.UsrDat.UsrCod, - Gbl.Usrs.Other.UsrDat.Surname1, - Gbl.Usrs.Other.UsrDat.Surname2, - Gbl.Usrs.Other.UsrDat.FrstName); + NumUsrs = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get similar users", + "SELECT DISTINCT UsrCod" + " FROM (SELECT DISTINCT UsrCod" + " FROM usr_ids" + " WHERE UsrID IN" + " (SELECT UsrID" + " FROM usr_ids" + " WHERE UsrCod=%ld)" + " UNION" + " SELECT UsrCod" + " FROM usr_data" + " WHERE Surname1='%s'" + " AND Surname2='%s'" + " AND FirstName='%s')" + " AS U", + Gbl.Usrs.Other.UsrDat.UsrCod, + Gbl.Usrs.Other.UsrDat.Surname1, + Gbl.Usrs.Other.UsrDat.Surname2, + Gbl.Usrs.Other.UsrDat.FrstName); else - NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get similar users", - "SELECT DISTINCT UsrCod" - " FROM usr_ids" - " WHERE UsrID IN" - " (SELECT UsrID" - " FROM usr_ids" - " WHERE UsrCod=%ld)", - Gbl.Usrs.Other.UsrDat.UsrCod); + NumUsrs = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get similar users", + "SELECT DISTINCT UsrCod" + " FROM usr_ids" + " WHERE UsrID IN" + " (SELECT UsrID" + " FROM usr_ids" + " WHERE UsrCod=%ld)", + Gbl.Usrs.Other.UsrDat.UsrCod); /***** List possible similar users *****/ if (NumUsrs) diff --git a/swad_enrolment.c b/swad_enrolment.c index caa22d04..ff135998 100644 --- a/swad_enrolment.c +++ b/swad_enrolment.c @@ -865,8 +865,8 @@ void Enr_RemoveOldUsrs (void) unsigned MonthsWithoutAccess; time_t SecondsWithoutAccess; MYSQL_RES *mysql_res; - unsigned long NumUsr; - unsigned long NumUsrs; + unsigned NumUsr; + unsigned NumUsrs; unsigned NumUsrsEliminated = 0; struct UsrData UsrDat; @@ -881,22 +881,23 @@ void Enr_RemoveOldUsrs (void) SecondsWithoutAccess = (time_t) MonthsWithoutAccess * Dat_SECONDS_IN_ONE_MONTH; /***** Get old users from database *****/ - NumUsrs = DB_QuerySELECT (&mysql_res,"can not get old users", - "SELECT UsrCod" - " FROM (SELECT UsrCod" - " FROM usr_last" - " WHERE LastTimeNum = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get exams", + "SELECT exa_exams.ExaCod," // row[0] + "MIN(exa_sessions.StartTime) AS StartTime," // row[1] + "MAX(exa_sessions.EndTime) AS EndTime" // row[2] + " FROM exa_exams" + " LEFT JOIN exa_sessions" + " ON exa_exams.ExaCod=exa_sessions.ExaCod" + " WHERE exa_exams.CrsCod=%ld" + "%s" + " GROUP BY exa_exams.ExaCod" + " ORDER BY %s", + Gbl.Hierarchy.Crs.CrsCod, + HiddenSubQuery, + OrderBySubQuery[SelectedOrder]); /***** Free allocated memory for subquery *****/ free (HiddenSubQuery); - if (NumRows) // Exams found... + if (Exams->Num) // Exams found... { - Exams->Num = (unsigned) NumRows; - /***** Create list of exams *****/ - if ((Exams->Lst = malloc (NumRows * sizeof (*Exams->Lst))) == NULL) + if ((Exams->Lst = malloc ((size_t) Exams->Num * + sizeof (*Exams->Lst))) == NULL) Lay_NotEnoughMemoryExit (); /***** Get the exams codes *****/ @@ -866,8 +865,6 @@ void Exa_GetListExams (struct Exa_Exams *Exams,Exa_Order_t SelectedOrder) Lay_ShowErrorAndExit ("Error: wrong exam code."); } } - else - Exams->Num = 0; /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -945,7 +942,6 @@ void Exa_GetDataOfExamByCod (struct Exa_Exam *Exam) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; /***** Trivial check *****/ if (Exam->ExaCod <= 0) @@ -956,18 +952,17 @@ void Exa_GetDataOfExamByCod (struct Exa_Exam *Exam) } /***** Get exam data from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get exam data", - "SELECT ExaCod," // row[0] - "CrsCod," // row[1] - "Hidden," // row[2] - "UsrCod," // row[3] - "MaxGrade," // row[4] - "Visibility," // row[5] - "Title" // row[6] - " FROM exa_exams" - " WHERE ExaCod=%ld", - Exam->ExaCod); - if (NumRows) // Exam found... + if (DB_QuerySELECT (&mysql_res,"can not get exam data", + "SELECT ExaCod," // row[0] + "CrsCod," // row[1] + "Hidden," // row[2] + "UsrCod," // row[3] + "MaxGrade," // row[4] + "Visibility," // row[5] + "Title" // row[6] + " FROM exa_exams" + " WHERE ExaCod=%ld", + Exam->ExaCod)) // Exam found... { /* Get row */ row = mysql_fetch_row (mysql_res); @@ -1017,13 +1012,12 @@ void Exa_GetDataOfExamByCod (struct Exa_Exam *Exam) if (Exam->ExaCod > 0) { /***** Get start and end times from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get exam data", - "SELECT UNIX_TIMESTAMP(MIN(StartTime))," // row[0] - "UNIX_TIMESTAMP(MAX(EndTime))" // row[1] - " FROM exa_sessions" - " WHERE ExaCod=%ld", - Exam->ExaCod); - if (NumRows) + if (DB_QuerySELECT (&mysql_res,"can not get exam data", + "SELECT UNIX_TIMESTAMP(MIN(StartTime))," // row[0] + "UNIX_TIMESTAMP(MAX(EndTime))" // row[1] + " FROM exa_sessions" + " WHERE ExaCod=%ld", + Exam->ExaCod)) { /* Get row */ row = mysql_fetch_row (mysql_res); @@ -1242,16 +1236,16 @@ static void Exa_RemoveAllMedFilesFromStemOfAllQstsInCrs (long CrsCod) unsigned NumMedia; /***** Get media codes associated to stems of exam questions from database *****/ - NumMedia = - (unsigned) DB_QuerySELECT (&mysql_res,"can not get media", - "SELECT exa_set_questions.MedCod" - " FROM exa_exams," - "exa_sets," - "exa_set_questions" - " WHERE exa_exams.CrsCod=%ld" - " AND exa_exams.ExaCod=exa_sets.ExaCod" - " AND exa_sets.SetCod=exa_set_questions.SetCod", - CrsCod); + NumMedia = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get media", + "SELECT exa_set_questions.MedCod" + " FROM exa_exams," + "exa_sets," + "exa_set_questions" + " WHERE exa_exams.CrsCod=%ld" + " AND exa_exams.ExaCod=exa_sets.ExaCod" + " AND exa_sets.SetCod=exa_set_questions.SetCod", + CrsCod); /***** Go over result removing media files *****/ Med_RemoveMediaFromAllRows (NumMedia,mysql_res); diff --git a/swad_exam_print.c b/swad_exam_print.c index 507c7dcd..ec9ae5cc 100644 --- a/swad_exam_print.c +++ b/swad_exam_print.c @@ -69,7 +69,7 @@ extern struct Globals Gbl; static void ExaPrn_GetDataOfPrint (struct ExaPrn_Print *Print, MYSQL_RES **mysql_res, - unsigned long NumRows); + unsigned NumPrints); static void ExaPrn_GetQuestionsForNewPrintFromDB (struct ExaPrn_Print *Print,long ExaCod); static unsigned ExaPrn_GetSomeQstsFromSetToPrint (struct ExaPrn_Print *Print, @@ -252,25 +252,26 @@ void ExaPrn_ShowExamPrint (void) void ExaPrn_GetDataOfPrintByPrnCod (struct ExaPrn_Print *Print) { MYSQL_RES *mysql_res; - unsigned long NumRows; + unsigned NumPrints; /***** Make database query *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get data of an exam print", - "SELECT PrnCod," // row[0] - "SesCod," // row[1] - "UsrCod," // row[2] - "UNIX_TIMESTAMP(StartTime)," // row[3] - "UNIX_TIMESTAMP(EndTime)," // row[4] - "NumQsts," // row[5] - "NumQstsNotBlank," // row[6] - "Sent," // row[7] - "Score" // row[8] - " FROM exa_prints" - " WHERE PrnCod=%ld", - Print->PrnCod); + NumPrints = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get data of an exam print", + "SELECT PrnCod," // row[0] + "SesCod," // row[1] + "UsrCod," // row[2] + "UNIX_TIMESTAMP(StartTime)," // row[3] + "UNIX_TIMESTAMP(EndTime)," // row[4] + "NumQsts," // row[5] + "NumQstsNotBlank," // row[6] + "Sent," // row[7] + "Score" // row[8] + " FROM exa_prints" + " WHERE PrnCod=%ld", + Print->PrnCod); /***** Get data of print *****/ - ExaPrn_GetDataOfPrint (Print,&mysql_res,NumRows); + ExaPrn_GetDataOfPrint (Print,&mysql_res,NumPrints); } /*****************************************************************************/ @@ -280,27 +281,28 @@ void ExaPrn_GetDataOfPrintByPrnCod (struct ExaPrn_Print *Print) void ExaPrn_GetDataOfPrintBySesCodAndUsrCod (struct ExaPrn_Print *Print) { MYSQL_RES *mysql_res; - unsigned long NumRows; + unsigned NumPrints; /***** Make database query *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get data of an exam print", - "SELECT PrnCod," // row[0] - "SesCod," // row[1] - "UsrCod," // row[2] - "UNIX_TIMESTAMP(StartTime)," // row[3] - "UNIX_TIMESTAMP(EndTime)," // row[4] - "NumQsts," // row[5] - "NumQstsNotBlank," // row[6] - "Sent," // row[7] - "Score" // row[8] - " FROM exa_prints" - " WHERE SesCod=%ld" - " AND UsrCod=%ld", - Print->SesCod, - Print->UsrCod); + NumPrints = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get data of an exam print", + "SELECT PrnCod," // row[0] + "SesCod," // row[1] + "UsrCod," // row[2] + "UNIX_TIMESTAMP(StartTime)," // row[3] + "UNIX_TIMESTAMP(EndTime)," // row[4] + "NumQsts," // row[5] + "NumQstsNotBlank," // row[6] + "Sent," // row[7] + "Score" // row[8] + " FROM exa_prints" + " WHERE SesCod=%ld" + " AND UsrCod=%ld", + Print->SesCod, + Print->UsrCod); /***** Get data of print *****/ - ExaPrn_GetDataOfPrint (Print,&mysql_res,NumRows); + ExaPrn_GetDataOfPrint (Print,&mysql_res,NumPrints); } /*****************************************************************************/ @@ -309,11 +311,11 @@ void ExaPrn_GetDataOfPrintBySesCodAndUsrCod (struct ExaPrn_Print *Print) static void ExaPrn_GetDataOfPrint (struct ExaPrn_Print *Print, MYSQL_RES **mysql_res, - unsigned long NumRows) + unsigned NumPrints) { MYSQL_ROW row; - if (NumRows) + if (NumPrints) { row = mysql_fetch_row (*mysql_res); diff --git a/swad_exam_result.c b/swad_exam_result.c index 57f27977..0c40648b 100644 --- a/swad_exam_result.c +++ b/swad_exam_result.c @@ -427,28 +427,29 @@ void ExaRes_ShowAllResultsInExa (void) static void ExaRes_ListAllResultsInExa (struct Exa_Exams *Exams,long ExaCod) { MYSQL_RES *mysql_res; - unsigned long NumUsrs; - unsigned long NumUsr; + unsigned NumUsrs; + unsigned NumUsr; /***** Table head *****/ ExaRes_ShowHeaderResults (Usr_OTHER); /***** Get all users who have answered any session question in this exam *****/ - NumUsrs = DB_QuerySELECT (&mysql_res,"can not get users in exam", - "SELECT users.UsrCod" // row[0] - " FROM (SELECT DISTINCT exa_prints.UsrCod AS UsrCod" - " FROM exa_prints,exa_sessions,exa_exams" - " WHERE exa_sessions.ExaCod=%ld" - " AND exa_sessions.SesCod=exa_prints.SesCod" - " AND exa_sessions.ExaCod=exa_exams.ExaCod" - " AND exa_exams.CrsCod=%ld) AS users," // Extra check - "usr_data" - " WHERE users.UsrCod=usr_data.UsrCod" - " ORDER BY usr_data.Surname1," - "usr_data.Surname2," - "usr_data.FirstName", - ExaCod, - Gbl.Hierarchy.Crs.CrsCod); + NumUsrs = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get users in exam", + "SELECT users.UsrCod" // row[0] + " FROM (SELECT DISTINCT exa_prints.UsrCod AS UsrCod" + " FROM exa_prints,exa_sessions,exa_exams" + " WHERE exa_sessions.ExaCod=%ld" + " AND exa_sessions.SesCod=exa_prints.SesCod" + " AND exa_sessions.ExaCod=exa_exams.ExaCod" + " AND exa_exams.CrsCod=%ld) AS users," // Extra check + "usr_data" + " WHERE users.UsrCod=usr_data.UsrCod" + " ORDER BY usr_data.Surname1," + "usr_data.Surname2," + "usr_data.FirstName", + ExaCod, + Gbl.Hierarchy.Crs.CrsCod); /***** List sessions results for each user *****/ for (NumUsr = 0; @@ -516,28 +517,29 @@ void ExaRes_ShowAllResultsInSes (void) static void ExaRes_ListAllResultsInSes (struct Exa_Exams *Exams,long SesCod) { MYSQL_RES *mysql_res; - unsigned long NumUsrs; - unsigned long NumUsr; + unsigned NumUsrs; + unsigned NumUsr; /***** Table head *****/ ExaRes_ShowHeaderResults (Usr_OTHER); /***** Get all users who have answered any session question in this exam *****/ - NumUsrs = DB_QuerySELECT (&mysql_res,"can not get users in session", - "SELECT users.UsrCod" // row[0] - " FROM (SELECT exa_prints.UsrCod AS UsrCod" // row[0] - " FROM exa_prints,exa_sessions,exa_exams" - " WHERE exa_prints.SesCod=%ld" - " AND exa_prints.SesCod=exa_sessions.SesCod" - " AND exa_sessions.ExaCod=exa_exams.ExaCod" - " AND exa_exams.CrsCod=%ld) AS users," // Extra check - "usr_data" - " WHERE users.UsrCod=usr_data.UsrCod" - " ORDER BY usr_data.Surname1," - "usr_data.Surname2," - "usr_data.FirstName", - SesCod, - Gbl.Hierarchy.Crs.CrsCod); + NumUsrs = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get users in session", + "SELECT users.UsrCod" // row[0] + " FROM (SELECT exa_prints.UsrCod AS UsrCod" // row[0] + " FROM exa_prints,exa_sessions,exa_exams" + " WHERE exa_prints.SesCod=%ld" + " AND exa_prints.SesCod=exa_sessions.SesCod" + " AND exa_sessions.ExaCod=exa_exams.ExaCod" + " AND exa_exams.CrsCod=%ld) AS users," // Extra check + "usr_data" + " WHERE users.UsrCod=usr_data.UsrCod" + " ORDER BY usr_data.Surname1," + "usr_data.Surname2," + "usr_data.FirstName", + SesCod, + Gbl.Hierarchy.Crs.CrsCod); /***** List sessions results for each user *****/ for (NumUsr = 0; @@ -905,25 +907,25 @@ static void ExaRes_ShowResults (struct Exa_Exams *Exams, /***** Make database query *****/ // Do not filter by groups, because a student who has changed groups // must be able to access exams taken in other groups - NumResults = - (unsigned) DB_QuerySELECT (&mysql_res,"can not get sessions results", - "SELECT exa_prints.PrnCod" // row[0] - " FROM exa_prints,exa_sessions,exa_exams" - " WHERE exa_prints.UsrCod=%ld" - "%s" // Session subquery - " AND exa_prints.SesCod=exa_sessions.SesCod" - "%s" // Hidden sessions subquery - "%s" // Exams subquery - " AND exa_sessions.ExaCod=exa_exams.ExaCod" - "%s" // Hidden exams subquery - " AND exa_exams.CrsCod=%ld" // Extra check - " ORDER BY exa_sessions.Title", - UsrDat->UsrCod, - SesSubQuery, - HidSesSubQuery, - ExaSubQuery, - HidExaSubQuery, - Gbl.Hierarchy.Crs.CrsCod); + NumResults = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get sessions results", + "SELECT exa_prints.PrnCod" // row[0] + " FROM exa_prints,exa_sessions,exa_exams" + " WHERE exa_prints.UsrCod=%ld" + "%s" // Session subquery + " AND exa_prints.SesCod=exa_sessions.SesCod" + "%s" // Hidden sessions subquery + "%s" // Exams subquery + " AND exa_sessions.ExaCod=exa_exams.ExaCod" + "%s" // Hidden exams subquery + " AND exa_exams.CrsCod=%ld" // Extra check + " ORDER BY exa_sessions.Title", + UsrDat->UsrCod, + SesSubQuery, + HidSesSubQuery, + ExaSubQuery, + HidExaSubQuery, + Gbl.Hierarchy.Crs.CrsCod); free (HidExaSubQuery); free (ExaSubQuery); free (HidSesSubQuery); diff --git a/swad_exam_session.c b/swad_exam_session.c index 39ff3ddc..149e6c36 100644 --- a/swad_exam_session.c +++ b/swad_exam_session.c @@ -291,7 +291,6 @@ void ExaSes_ListSessions (struct Exa_Exams *Exams, void ExaSes_GetDataOfSessionByCod (struct ExaSes_Session *Session) { MYSQL_RES *mysql_res; - unsigned long NumRows; /***** Trivial check *****/ if (Session->SesCod <= 0) @@ -302,26 +301,24 @@ void ExaSes_GetDataOfSessionByCod (struct ExaSes_Session *Session) } /***** Get exam data session from database *****/ - NumRows = (unsigned) - DB_QuerySELECT (&mysql_res,"can not get sessions", - "SELECT SesCod," // row[0] - "ExaCod," // row[1] - "Hidden," // row[2] - "UsrCod," // row[3] - "UNIX_TIMESTAMP(StartTime)," // row[4] - "UNIX_TIMESTAMP(EndTime)," // row[5] - "NOW() BETWEEN StartTime AND EndTime," // row[6] - "Title," // row[7] - "ShowUsrResults" // row[8] - " FROM exa_sessions" - " WHERE SesCod=%ld" - " AND ExaCod IN" // Extra check - " (SELECT ExaCod" - " FROM exa_exams" - " WHERE CrsCod='%ld')", - Session->SesCod, - Gbl.Hierarchy.Crs.CrsCod); - if (NumRows) // Session found... + if (DB_QuerySELECT (&mysql_res,"can not get sessions", + "SELECT SesCod," // row[0] + "ExaCod," // row[1] + "Hidden," // row[2] + "UsrCod," // row[3] + "UNIX_TIMESTAMP(StartTime)," // row[4] + "UNIX_TIMESTAMP(EndTime)," // row[5] + "NOW() BETWEEN StartTime AND EndTime," // row[6] + "Title," // row[7] + "ShowUsrResults" // row[8] + " FROM exa_sessions" + " WHERE SesCod=%ld" + " AND ExaCod IN" // Extra check + " (SELECT ExaCod" + " FROM exa_exams" + " WHERE CrsCod='%ld')", + Session->SesCod, + Gbl.Hierarchy.Crs.CrsCod)) // Session found... /* Get exam session data from row */ ExaSes_GetSessionDataFromRow (mysql_res,Session); else @@ -662,36 +659,37 @@ static void ExaSes_GetAndWriteNamesOfGrpsAssociatedToSession (const struct ExaSe extern const char *Txt_The_whole_course; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRow; - unsigned long NumRows; + unsigned NumGrps; + unsigned NumGrp; /***** Get groups associated to an exam session from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get groups of an exam session", - "SELECT grp_types.GrpTypName," // row[0] - "grp_groups.GrpName" // row[1] - " FROM exa_groups," - "grp_groups," - "grp_types" - " WHERE exa_groups.SesCod=%ld" - " AND exa_groups.GrpCod=grp_groups.GrpCod" - " AND grp_groups.GrpTypCod=grp_types.GrpTypCod" - " ORDER BY grp_types.GrpTypName," - "grp_groups.GrpName", - Session->SesCod); + NumGrps = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get groups of an exam session", + "SELECT grp_types.GrpTypName," // row[0] + "grp_groups.GrpName" // row[1] + " FROM exa_groups," + "grp_groups," + "grp_types" + " WHERE exa_groups.SesCod=%ld" + " AND exa_groups.GrpCod=grp_groups.GrpCod" + " AND grp_groups.GrpTypCod=grp_types.GrpTypCod" + " ORDER BY grp_types.GrpTypName," + "grp_groups.GrpName", + Session->SesCod); /***** Write heading *****/ HTM_DIV_Begin ("class=\"%s\"",Session->Hidden ? "ASG_GRP_LIGHT": "ASG_GRP"); - HTM_TxtColonNBSP (NumRows == 1 ? Txt_Group : + HTM_TxtColonNBSP (NumGrps == 1 ? Txt_Group : Txt_Groups); /***** Write groups *****/ - if (NumRows) // Groups found... + if (NumGrps) // Groups found... { /* Get and write the group types and names */ - for (NumRow = 0; - NumRow < NumRows; - NumRow++) + for (NumGrp = 0; + NumGrp < NumGrps; + NumGrp++) { /* Get next group */ row = mysql_fetch_row (mysql_res); @@ -699,12 +697,12 @@ static void ExaSes_GetAndWriteNamesOfGrpsAssociatedToSession (const struct ExaSe /* Write group type name and group name */ HTM_TxtF ("%s %s",row[0],row[1]); - if (NumRows >= 2) + if (NumGrps >= 2) { - if (NumRow == NumRows-2) + if (NumGrp == NumGrps - 2) HTM_TxtF (" %s ",Txt_and); - if (NumRows >= 3) - if (NumRow < NumRows-2) + if (NumGrps >= 3) + if (NumGrp < NumGrps - 2) HTM_Txt (", "); } } diff --git a/swad_figure.c b/swad_figure.c index d922f94f..040487fd 100644 --- a/swad_figure.c +++ b/swad_figure.c @@ -1394,40 +1394,40 @@ static void Fig_GetAndShowInssOrderedByNumUsrsWhoClaimToBelongToThem (void) switch (Gbl.Scope.Current) { case Hie_Lvl_SYS: - NumInss = - (unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions", - "SELECT InsCod," // row[0] - "COUNT(*) AS N" // row[1] - " FROM usr_data" - " WHERE InsCod>0" - " GROUP BY InsCod" - " ORDER BY N DESC"); + NumInss = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get institutions", + "SELECT InsCod," // row[0] + "COUNT(*) AS N" // row[1] + " FROM usr_data" + " WHERE InsCod>0" + " GROUP BY InsCod" + " ORDER BY N DESC"); break; case Hie_Lvl_CTY: - NumInss = - (unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions", - "SELECT usr_data.InsCod," // row[0] - "COUNT(*) AS N" // row[1] - " FROM ins_instits,usr_data" - " WHERE ins_instits.CtyCod=%ld" - " AND ins_instits.InsCod=usr_data.InsCod" - " GROUP BY usr_data.InsCod" - " ORDER BY N DESC", - Gbl.Hierarchy.Cty.CtyCod); + NumInss = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get institutions", + "SELECT usr_data.InsCod," // row[0] + "COUNT(*) AS N" // row[1] + " FROM ins_instits,usr_data" + " WHERE ins_instits.CtyCod=%ld" + " AND ins_instits.InsCod=usr_data.InsCod" + " GROUP BY usr_data.InsCod" + " ORDER BY N DESC", + Gbl.Hierarchy.Cty.CtyCod); break; case Hie_Lvl_INS: case Hie_Lvl_CTR: case Hie_Lvl_DEG: case Hie_Lvl_CRS: - NumInss = - (unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions", - "SELECT InsCod," // row[0] - "COUNT(*) AS N" // row[1] - " FROM usr_data" - " WHERE InsCod=%ld" - " GROUP BY InsCod" - " ORDER BY N DESC", - Gbl.Hierarchy.Ins.InsCod); + NumInss = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get institutions", + "SELECT InsCod," // row[0] + "COUNT(*) AS N" // row[1] + " FROM usr_data" + " WHERE InsCod=%ld" + " GROUP BY InsCod" + " ORDER BY N DESC", + Gbl.Hierarchy.Ins.InsCod); break; default: Lay_WrongScopeExit (); @@ -3552,8 +3552,8 @@ static void Fig_GetAndShowTimelineActivityStats (void) MYSQL_RES *mysql_res; MYSQL_ROW row; Tml_Not_NoteType_t NoteType; - unsigned long NumNotes; - unsigned long NumRows; + unsigned NumNotes; + unsigned NumRows; unsigned NumUsrs; unsigned NumUsrsTotal; @@ -3584,7 +3584,7 @@ static void Fig_GetAndShowTimelineActivityStats (void) switch (Gbl.Scope.Current) { case Hie_Lvl_SYS: - NumRows = + NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get number of social notes", "SELECT COUNT(*)," // row[0] "COUNT(DISTINCT UsrCod)" // row[1] @@ -3592,7 +3592,7 @@ static void Fig_GetAndShowTimelineActivityStats (void) NoteType); break; case Hie_Lvl_CTY: - NumRows = + NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get number of social notes", "SELECT COUNT(DISTINCT tml_notes.NotCod)," // row[0] "COUNT(DISTINCT tml_notes.UsrCod)" // row[1] @@ -3613,7 +3613,7 @@ static void Fig_GetAndShowTimelineActivityStats (void) (unsigned) NoteType); break; case Hie_Lvl_INS: - NumRows = + NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get number of social notes", "SELECT COUNT(DISTINCT tml_notes.NotCod)," // row[0] "COUNT(DISTINCT tml_notes.UsrCod)" // row[1] @@ -3632,7 +3632,7 @@ static void Fig_GetAndShowTimelineActivityStats (void) (unsigned) NoteType); break; case Hie_Lvl_CTR: - NumRows = + NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get number of social notes", "SELECT COUNT(DISTINCT tml_notes.NotCod)," // row[0] "COUNT(DISTINCT tml_notes.UsrCod)" // row[1] @@ -3649,7 +3649,7 @@ static void Fig_GetAndShowTimelineActivityStats (void) (unsigned) NoteType); break; case Hie_Lvl_DEG: - NumRows = + NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get number of social notes", "SELECT COUNT(DISTINCT tml_notes.NotCod)," // row[0] "COUNT(DISTINCT tml_notes.UsrCod)" // row[1] @@ -3664,7 +3664,7 @@ static void Fig_GetAndShowTimelineActivityStats (void) (unsigned) NoteType); break; case Hie_Lvl_CRS: - NumRows = + NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get number of social notes", "SELECT COUNT(DISTINCT tml_notes.NotCod)," // row[0] "COUNT(DISTINCT tml_notes.UsrCod)" // row[1] @@ -3691,7 +3691,7 @@ static void Fig_GetAndShowTimelineActivityStats (void) /* Get number of social notes */ if (row[0]) - if (sscanf (row[0],"%lu",&NumNotes) != 1) + if (sscanf (row[0],"%u",&NumNotes) != 1) NumNotes = 0; /* Get number of users */ @@ -3711,7 +3711,7 @@ static void Fig_GetAndShowTimelineActivityStats (void) HTM_TD_End (); HTM_TD_Begin ("class=\"DAT RM\""); - HTM_UnsignedLong (NumNotes); + HTM_Unsigned (NumNotes); HTM_TD_End (); HTM_TD_Begin ("class=\"DAT RM\""); @@ -3736,14 +3736,14 @@ static void Fig_GetAndShowTimelineActivityStats (void) switch (Gbl.Scope.Current) { case Hie_Lvl_SYS: - NumRows = + NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get number of social notes", "SELECT COUNT(*)," // row[0] "COUNT(DISTINCT UsrCod)" // row[1] " FROM tml_notes"); break; case Hie_Lvl_CTY: - NumRows = + NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get number of social notes", "SELECT COUNT(DISTINCT tml_notes.NotCod)," // row[0] "COUNT(DISTINCT tml_notes.UsrCod)" // row[1] @@ -3762,7 +3762,7 @@ static void Fig_GetAndShowTimelineActivityStats (void) Gbl.Hierarchy.Cty.CtyCod); break; case Hie_Lvl_INS: - NumRows = + NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get number of social notes", "SELECT COUNT(DISTINCT tml_notes.NotCod)," // row[0] "COUNT(DISTINCT tml_notes.UsrCod)" // row[1] @@ -3779,7 +3779,7 @@ static void Fig_GetAndShowTimelineActivityStats (void) Gbl.Hierarchy.Ins.InsCod); break; case Hie_Lvl_CTR: - NumRows = + NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get number of social notes", "SELECT COUNT(DISTINCT tml_notes.NotCod)," // row[0] "COUNT(DISTINCT tml_notes.UsrCod)" // row[1] @@ -3794,7 +3794,7 @@ static void Fig_GetAndShowTimelineActivityStats (void) Gbl.Hierarchy.Ctr.CtrCod); break; case Hie_Lvl_DEG: - NumRows = + NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get number of social notes", "SELECT COUNT(DISTINCT tml_notes.NotCod)," // row[0] "COUNT(DISTINCT tml_notes.UsrCod)" // row[1] @@ -3807,7 +3807,7 @@ static void Fig_GetAndShowTimelineActivityStats (void) Gbl.Hierarchy.Deg.DegCod); break; case Hie_Lvl_CRS: - NumRows = + NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get number of social notes", "SELECT COUNT(DISTINCT tml_notes.NotCod)," // row[0] "COUNT(DISTINCT tml_notes.UsrCod)" // row[1] @@ -3832,7 +3832,7 @@ static void Fig_GetAndShowTimelineActivityStats (void) /* Get number of social notes */ if (row[0]) - if (sscanf (row[0],"%lu",&NumNotes) != 1) + if (sscanf (row[0],"%u",&NumNotes) != 1) NumNotes = 0; /* Get number of users */ @@ -3852,7 +3852,7 @@ static void Fig_GetAndShowTimelineActivityStats (void) HTM_TD_End (); HTM_TD_Begin ("class=\"DAT_N LINE_TOP RM\""); - HTM_UnsignedLong (NumNotes); + HTM_Unsigned (NumNotes); HTM_TD_End (); HTM_TD_Begin ("class=\"DAT_N LINE_TOP RM\""); diff --git a/swad_file_browser.c b/swad_file_browser.c index 8be251ea..f96e96ff 100644 --- a/swad_file_browser.c +++ b/swad_file_browser.c @@ -2678,12 +2678,12 @@ bool Brw_CheckIfExistsFolderAssigmentForAnyUsr (const char *FolderName) bool FolderExists = false; /***** Get all the users belonging to current course from database *****/ - NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get users" - " from current course", - "SELECT UsrCod" // row[0] - " FROM crs_users" - " WHERE CrsCod=%ld", - Gbl.Hierarchy.Crs.CrsCod); + NumUsrs = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get users from current course", + "SELECT UsrCod" + " FROM crs_users" + " WHERE CrsCod=%ld", + Gbl.Hierarchy.Crs.CrsCod); /***** Check folders *****/ for (NumUsr = 0; @@ -2722,35 +2722,37 @@ static void Brw_CreateFoldersAssignmentsIfNotExist (long ZoneUsrCod) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; - unsigned long NumRow; + unsigned NumFolders; + unsigned NumFolder; char PathFolderAsg[PATH_MAX + 1 + PATH_MAX + 1]; /***** Get assignment folders from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get folders of assignments", - "SELECT Folder" // row[0] - " FROM asg_assignments" - " WHERE CrsCod=%ld" - " AND Hidden='N'" - " AND Folder<>''" - " AND (" - "AsgCod NOT IN" - " (SELECT AsgCod" - " FROM asg_groups)" - " OR " - "AsgCod IN" - " (SELECT asg_groups.AsgCod" - " FROM grp_users," - "asg_groups" - " WHERE grp_users.UsrCod=%ld" - " AND asg_groups.GrpCod=grp_users.GrpCod)" - ")", - Gbl.Hierarchy.Crs.CrsCod,ZoneUsrCod); + NumFolders = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get folders of assignments", + "SELECT Folder" // row[0] + " FROM asg_assignments" + " WHERE CrsCod=%ld" + " AND Hidden='N'" + " AND Folder<>''" + " AND (" + "AsgCod NOT IN" + " (SELECT AsgCod" + " FROM asg_groups)" + " OR " + "AsgCod IN" + " (SELECT asg_groups.AsgCod" + " FROM grp_users," + "asg_groups" + " WHERE grp_users.UsrCod=%ld" + " AND asg_groups.GrpCod=grp_users.GrpCod)" + ")", + Gbl.Hierarchy.Crs.CrsCod, + ZoneUsrCod); /***** Create one folder for each assignment *****/ - for (NumRow = 0; - NumRow < NumRows; - NumRow++) + for (NumFolder = 0; + NumFolder < NumFolders; + NumFolder++) { /* Get next assignment with folder */ row = mysql_fetch_row (mysql_res); @@ -5159,7 +5161,7 @@ static void Brw_GetAndUpdateDateLastAccFileBrowser (void) long Cod; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; + unsigned NumRows; /***** Get date of last accesss to a file browser from database *****/ switch (Gbl.FileBrowser.Type) @@ -5209,16 +5211,17 @@ static void Brw_GetAndUpdateDateLastAccFileBrowser (void) default: return; } - NumRows = DB_QuerySELECT (&mysql_res,"can not get date-time" - " of last access to a file browser", - "SELECT UNIX_TIMESTAMP(LastClick)" // row[0] - " FROM brw_last" - " WHERE UsrCod=%ld" - " AND FileBrowser=%u" - " AND Cod=%ld", - Gbl.Usrs.Me.UsrDat.UsrCod, - (unsigned) Brw_FileBrowserForDB_file_browser_last[Gbl.FileBrowser.Type], - Cod); + NumRows = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get date-time" + " of last access to a file browser", + "SELECT UNIX_TIMESTAMP(LastClick)" // row[0] + " FROM brw_last" + " WHERE UsrCod=%ld" + " AND FileBrowser=%u" + " AND Cod=%ld", + Gbl.Usrs.Me.UsrDat.UsrCod, + (unsigned) Brw_FileBrowserForDB_file_browser_last[Gbl.FileBrowser.Type], + Cod); if (NumRows == 0) // May be an administrator not belonging to this course Gbl.Usrs.Me.TimeLastAccToThisFileBrowser = LONG_MAX; // Initialize to a big value in order to show files as old @@ -5256,24 +5259,24 @@ static long Brw_GetGrpLastAccZone (const char *FieldNameDB) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; + unsigned NumGrps; long GrpCod = -1L; /***** Get the group of my last access to a common zone from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get the group" - " of your last access" - " to a file browser", - "SELECT %s" // row[0] - " FROM crs_user_settings" - " WHERE UsrCod=%ld" - " AND CrsCod=%ld", - FieldNameDB, - Gbl.Usrs.Me.UsrDat.UsrCod, - Gbl.Hierarchy.Crs.CrsCod); + NumGrps = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get the group of your last access" + " to a file browser", + "SELECT %s" // row[0] + " FROM crs_user_settings" + " WHERE UsrCod=%ld" + " AND CrsCod=%ld", + FieldNameDB, + Gbl.Usrs.Me.UsrDat.UsrCod, + Gbl.Hierarchy.Crs.CrsCod); - if (NumRows == 0) // May be an administrator not belonging to this course + if (NumGrps == 0) // May be an administrator not belonging to this course GrpCod = -1L; - else if (NumRows == 1) + else if (NumGrps == 1) { /* Get the group code (row[0]) */ row = mysql_fetch_row (mysql_res); @@ -11710,27 +11713,22 @@ static long Brw_GetPublisherOfSubtree (void) void Brw_RemoveZonesOfGroupsOfType (long GrpTypCod) { MYSQL_RES *mysql_res; - MYSQL_ROW row; - unsigned long NumRow; - unsigned long NumRows; + unsigned NumGrps; + unsigned NumGrp; long GrpCod; /***** Query database *****/ - if ((NumRows = Grp_GetGrpsOfType (GrpTypCod,&mysql_res))) // If there exists groups... - for (NumRow = 0; - NumRow < NumRows; - NumRow++) - { - /* Get next group */ - row = mysql_fetch_row (mysql_res); + NumGrps = Grp_GetGrpsOfType (GrpTypCod,&mysql_res); + for (NumGrp = 0; + NumGrp < NumGrps; + NumGrp++) + { + /* Get next group */ + GrpCod = DB_GetNextCode (mysql_res); - /* Group code is in row[0] */ - if (sscanf (row[0],"%ld",&GrpCod) != 1) - Lay_ShowErrorAndExit ("Wrong group code."); - - /* Remove file zones of this group */ - Brw_RemoveGrpZones (Gbl.Hierarchy.Crs.CrsCod,GrpCod); - } + /* Remove file zones of this group */ + Brw_RemoveGrpZones (Gbl.Hierarchy.Crs.CrsCod,GrpCod); + } /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -11783,27 +11781,27 @@ void Brw_RemoveUsrWorksInAllCrss (struct UsrData *UsrDat) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; - unsigned long NumRow; + unsigned long NumCrss; + unsigned long NumCrs; unsigned NumCrssWorksRemoved = 0; struct Crs_Course Crs; /***** Query database *****/ - if ((NumRows = Usr_GetCrssFromUsr (UsrDat->UsrCod,-1L,&mysql_res)) > 0) // If courses found + NumCrss = Usr_GetCrssFromUsr (UsrDat->UsrCod,-1L,&mysql_res); + + /***** Remove the zone of works of the user in the courses he/she belongs to *****/ + for (NumCrs = 0; + NumCrs < NumCrss; + NumCrs++) { - /***** Remove the zone of works of the user in the courses he/she belongs to *****/ - for (NumRow = 0; - NumRow < NumRows; - NumRow++) - { - /* Get the next course */ - row = mysql_fetch_row (mysql_res); - Crs.CrsCod = Str_ConvertStrCodToLongCod (row[0]); - /* Get data of course */ - Crs_GetDataOfCourseByCod (&Crs); - Brw_RemoveUsrWorksInCrs (UsrDat,&Crs); - NumCrssWorksRemoved++; - } + /* Get the next course */ + row = mysql_fetch_row (mysql_res); + Crs.CrsCod = Str_ConvertStrCodToLongCod (row[0]); + + /* Get data of course */ + Crs_GetDataOfCourseByCod (&Crs); + Brw_RemoveUsrWorksInCrs (UsrDat,&Crs); + NumCrssWorksRemoved++; } /***** Free structure that stores the query result *****/ diff --git a/swad_follow.c b/swad_follow.c index 79120a1d..1feac17d 100644 --- a/swad_follow.c +++ b/swad_follow.c @@ -77,9 +77,9 @@ extern struct Globals Gbl; /***************************** Private prototypes ****************************/ /*****************************************************************************/ -static unsigned long Fol_GetUsrsToFollow (unsigned long MaxUsrsToShow, - Fol_WhichUsersSuggestToFollowThem_t WhichUsersSuggestToFollowThem, - MYSQL_RES **mysql_res); +static unsigned Fol_GetUsrsToFollow (unsigned MaxUsrsToShow, + Fol_WhichUsersSuggestToFollowThem_t WhichUsersSuggestToFollowThem, + MYSQL_RES **mysql_res); static void Fol_PutIconsWhoToFollow (__attribute__((unused)) void *Args); static void Fol_PutIconToUpdateWhoToFollow (void); @@ -134,8 +134,8 @@ void Fol_SuggestUsrsToFollowMainZone (void) extern const char *Txt_No_user_to_whom_you_can_follow_Try_again_later; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumUsrs; - unsigned long NumUsr; + unsigned NumUsrs; + unsigned NumUsr; struct UsrData UsrDat; /***** Contextual menu *****/ @@ -262,9 +262,9 @@ void Fol_SuggestUsrsToFollowMainZoneOnRightColumn (void) /*************************** Get users to follow *****************************/ /*****************************************************************************/ -static unsigned long Fol_GetUsrsToFollow (unsigned long MaxUsrsToShow, - Fol_WhichUsersSuggestToFollowThem_t WhichUsersSuggestToFollowThem, - MYSQL_RES **mysql_res) +static unsigned Fol_GetUsrsToFollow (unsigned MaxUsrsToShow, + Fol_WhichUsersSuggestToFollowThem_t WhichUsersSuggestToFollowThem, + MYSQL_RES **mysql_res) { extern const char *Pri_VisibilityDB[Pri_NUM_OPTIONS_PRIVACY]; char SubQuery1[256]; @@ -311,115 +311,116 @@ static unsigned long Fol_GetUsrsToFollow (unsigned long MaxUsrsToShow, /***** Build query to get users to follow *****/ // Get only users with surname 1 and first name - return DB_QuerySELECT (mysql_res,"can not get users to follow", - "SELECT DISTINCT UsrCod FROM" - " (" - /***** Likely known users *****/ - "(SELECT DISTINCT UsrCod FROM" - " (" - // 1. Users followed by my followed - "(" - "SELECT DISTINCT usr_follow.FollowedCod AS UsrCod" - " FROM usr_follow," - "(SELECT FollowedCod" - " FROM usr_follow" - " WHERE FollowerCod=%ld) AS my_followed," - " usr_data" - " WHERE usr_follow.FollowerCod=my_followed.FollowedCod" - " AND usr_follow.FollowedCod<>%ld" - " AND usr_follow.FollowedCod=usr_data.UsrCod" - " AND usr_data.Surname1<>''" // Surname 1 not empty - " AND usr_data.FirstName<>''" // First name not empty - "%s" // SubQuery1 - ")" - " UNION " - // 2. Users who share any course with me - "(" - "SELECT DISTINCT crs_users.UsrCod" - " FROM crs_users," - "(SELECT CrsCod" - " FROM crs_users" - " WHERE UsrCod=%ld) AS my_crs," - " usr_data" - " WHERE crs_users.CrsCod=my_crs.CrsCod" - " AND crs_users.UsrCod<>%ld" - " AND crs_users.UsrCod=usr_data.UsrCod" - " AND usr_data.Surname1<>''" // Surname 1 not empty - " AND usr_data.FirstName<>''" // First name not empty - "%s" // SubQuery2 - ")" - " UNION " - // 3. Users who share any course with me with another role - "(" - "SELECT DISTINCT crs_users.UsrCod" - " FROM crs_users," - "(SELECT CrsCod,Role" - " FROM crs_users" - " WHERE UsrCod=%ld) AS my_crs_role," - " usr_data" - " WHERE crs_users.CrsCod=my_crs_role.CrsCod" - " AND crs_users.Role<>my_crs_role.Role" - " AND crs_users.UsrCod=usr_data.UsrCod" - " AND usr_data.Surname1<>''" // Surname 1 not empty - " AND usr_data.FirstName<>''" // First name not empty - "%s" // SubQuery3 - ")" - ") AS LikelyKnownUsrsToFollow" - // Do not select my followed - " WHERE UsrCod NOT IN" - " (SELECT FollowedCod FROM usr_follow" - " WHERE FollowerCod=%ld)" - // Get only MaxUsrsToShow * 3 users - " ORDER BY RAND() LIMIT %lu" - ")" - " UNION " - "(" - /***** Likely unknown userd *****/ - // 4. Add some likely unknown random user - // Be careful with the method to get some random users - // from the big table of users. - // It's much faster getting a random code and then get the first users - // with codes >= that random code - // that getting all users and then ordering by rand. - "SELECT usr_data.UsrCod" - " FROM usr_data," - "(SELECT ROUND(RAND()*(SELECT MAX(UsrCod)" - " FROM usr_data)) AS RandomUsrCod) AS random_usr" // a random user code - " WHERE usr_data.UsrCod<>%ld" - " AND usr_data.Surname1<>''" // Surname 1 not empty - " AND usr_data.FirstName<>''" // First name not empty - "%s" // SubQuery4 - // Do not select my followed - " AND usr_data.UsrCod NOT IN" - " (SELECT FollowedCod" - " FROM usr_follow" - " WHERE FollowerCod=%ld)" - " AND usr_data.UsrCod>=random_usr.RandomUsrCod" // random user code could not exists in table of users - // Get only MaxUsrsToShow users - " LIMIT %lu" - ")" - ") AS UsrsToFollow" - // Get only MaxUsrsToShow users - " ORDER BY RAND()" - " LIMIT %lu", + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get users to follow", + "SELECT DISTINCT UsrCod FROM" + " (" + /***** Likely known users *****/ + "(SELECT DISTINCT UsrCod FROM" + " (" + // 1. Users followed by my followed + "(" + "SELECT DISTINCT usr_follow.FollowedCod AS UsrCod" + " FROM usr_follow," + "(SELECT FollowedCod" + " FROM usr_follow" + " WHERE FollowerCod=%ld) AS my_followed," + " usr_data" + " WHERE usr_follow.FollowerCod=my_followed.FollowedCod" + " AND usr_follow.FollowedCod<>%ld" + " AND usr_follow.FollowedCod=usr_data.UsrCod" + " AND usr_data.Surname1<>''" // Surname 1 not empty + " AND usr_data.FirstName<>''" // First name not empty + "%s" // SubQuery1 + ")" + " UNION " + // 2. Users who share any course with me + "(" + "SELECT DISTINCT crs_users.UsrCod" + " FROM crs_users," + "(SELECT CrsCod" + " FROM crs_users" + " WHERE UsrCod=%ld) AS my_crs," + " usr_data" + " WHERE crs_users.CrsCod=my_crs.CrsCod" + " AND crs_users.UsrCod<>%ld" + " AND crs_users.UsrCod=usr_data.UsrCod" + " AND usr_data.Surname1<>''" // Surname 1 not empty + " AND usr_data.FirstName<>''" // First name not empty + "%s" // SubQuery2 + ")" + " UNION " + // 3. Users who share any course with me with another role + "(" + "SELECT DISTINCT crs_users.UsrCod" + " FROM crs_users," + "(SELECT CrsCod,Role" + " FROM crs_users" + " WHERE UsrCod=%ld) AS my_crs_role," + " usr_data" + " WHERE crs_users.CrsCod=my_crs_role.CrsCod" + " AND crs_users.Role<>my_crs_role.Role" + " AND crs_users.UsrCod=usr_data.UsrCod" + " AND usr_data.Surname1<>''" // Surname 1 not empty + " AND usr_data.FirstName<>''" // First name not empty + "%s" // SubQuery3 + ")" + ") AS LikelyKnownUsrsToFollow" + // Do not select my followed + " WHERE UsrCod NOT IN" + " (SELECT FollowedCod FROM usr_follow" + " WHERE FollowerCod=%ld)" + // Get only MaxUsrsToShow * 3 users + " ORDER BY RAND() LIMIT %u" + ")" + " UNION " + "(" + /***** Likely unknown userd *****/ + // 4. Add some likely unknown random user + // Be careful with the method to get some random users + // from the big table of users. + // It's much faster getting a random code and then get the first users + // with codes >= that random code + // that getting all users and then ordering by rand. + "SELECT usr_data.UsrCod" + " FROM usr_data," + "(SELECT ROUND(RAND()*(SELECT MAX(UsrCod)" + " FROM usr_data)) AS RandomUsrCod) AS random_usr" // a random user code + " WHERE usr_data.UsrCod<>%ld" + " AND usr_data.Surname1<>''" // Surname 1 not empty + " AND usr_data.FirstName<>''" // First name not empty + "%s" // SubQuery4 + // Do not select my followed + " AND usr_data.UsrCod NOT IN" + " (SELECT FollowedCod" + " FROM usr_follow" + " WHERE FollowerCod=%ld)" + " AND usr_data.UsrCod>=random_usr.RandomUsrCod" // random user code could not exists in table of users + // Get only MaxUsrsToShow users + " LIMIT %u" + ")" + ") AS UsrsToFollow" + // Get only MaxUsrsToShow users + " ORDER BY RAND()" + " LIMIT %u", - Gbl.Usrs.Me.UsrDat.UsrCod, - Gbl.Usrs.Me.UsrDat.UsrCod, - SubQuery1, - Gbl.Usrs.Me.UsrDat.UsrCod, - Gbl.Usrs.Me.UsrDat.UsrCod, - SubQuery2, - Gbl.Usrs.Me.UsrDat.UsrCod, - SubQuery3, - Gbl.Usrs.Me.UsrDat.UsrCod, - MaxUsrsToShow * 2, // 2/3 likely known users + Gbl.Usrs.Me.UsrDat.UsrCod, + Gbl.Usrs.Me.UsrDat.UsrCod, + SubQuery1, + Gbl.Usrs.Me.UsrDat.UsrCod, + Gbl.Usrs.Me.UsrDat.UsrCod, + SubQuery2, + Gbl.Usrs.Me.UsrDat.UsrCod, + SubQuery3, + Gbl.Usrs.Me.UsrDat.UsrCod, + MaxUsrsToShow * 2, // 2/3 likely known users - Gbl.Usrs.Me.UsrDat.UsrCod, - SubQuery4, - Gbl.Usrs.Me.UsrDat.UsrCod, - MaxUsrsToShow, // 1/3 likely unknown users + Gbl.Usrs.Me.UsrDat.UsrCod, + SubQuery4, + Gbl.Usrs.Me.UsrDat.UsrCod, + MaxUsrsToShow, // 1/3 likely unknown users - MaxUsrsToShow); + MaxUsrsToShow); } /*****************************************************************************/ @@ -675,20 +676,21 @@ static void Fol_ListFollowingUsr (struct UsrData *UsrDat) { extern const char *Txt_Following; MYSQL_RES *mysql_res; - unsigned long NumUsrs; - unsigned long NumUsr; + unsigned NumUsrs; + unsigned NumUsr; struct UsrData FollowingUsrDat; /***** Show user's profile *****/ if (Prf_ShowUserProfile (UsrDat)) { /***** Check if a user is a follower of another user *****/ - NumUsrs = DB_QuerySELECT (&mysql_res,"can not get followed users", - "SELECT FollowedCod" // row[0] - " FROM usr_follow" - " WHERE FollowerCod=%ld" - " ORDER BY FollowTime DESC", - UsrDat->UsrCod); + NumUsrs = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get followed users", + "SELECT FollowedCod" // row[0] + " FROM usr_follow" + " WHERE FollowerCod=%ld" + " ORDER BY FollowTime DESC", + UsrDat->UsrCod); if (NumUsrs) { @@ -755,8 +757,8 @@ static void Fol_ListFollowersUsr (struct UsrData *UsrDat) { extern const char *Txt_Followers; MYSQL_RES *mysql_res; - unsigned long NumUsrs; - unsigned long NumUsr; + unsigned NumUsrs; + unsigned NumUsr; struct UsrData FollowerUsrDat; bool ItsMe; @@ -764,12 +766,13 @@ static void Fol_ListFollowersUsr (struct UsrData *UsrDat) if (Prf_ShowUserProfile (UsrDat)) { /***** Check if a user is a follower of another user *****/ - NumUsrs = DB_QuerySELECT (&mysql_res,"can not get followers", - "SELECT FollowerCod" - " FROM usr_follow" - " WHERE FollowedCod=%ld" - " ORDER BY FollowTime DESC", - UsrDat->UsrCod); + NumUsrs = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get followers", + "SELECT FollowerCod" + " FROM usr_follow" + " WHERE FollowedCod=%ld" + " ORDER BY FollowTime DESC", + UsrDat->UsrCod); if (NumUsrs) { diff --git a/swad_forum.c b/swad_forum.c index 86b25970..837870f3 100644 --- a/swad_forum.c +++ b/swad_forum.c @@ -1018,8 +1018,7 @@ static void For_ShowPostsOfAThread (struct For_Forums *Forums, char FrameTitle[128 + Cns_MAX_BYTES_SUBJECT]; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRow; - unsigned long NumRows; + unsigned NumRow; unsigned NumPst = 0; // Initialized to avoid warning unsigned NumPsts; time_t ReadTimeUTC; // Read time of thread for the current user @@ -1056,15 +1055,15 @@ static void For_ShowPostsOfAThread (struct For_Forums *Forums, Hlp_COMMUNICATION_Forums_posts,Box_NOT_CLOSABLE); /***** Get posts of a thread from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get posts of a thread", - "SELECT PstCod," // row[0] - "UNIX_TIMESTAMP(CreatTime)" // row[1] - " FROM for_posts" - " WHERE ThrCod=%ld" - " ORDER BY PstCod", - Thread.ThrCod); + NumPsts = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get posts of a thread", + "SELECT PstCod," // row[0] + "UNIX_TIMESTAMP(CreatTime)" // row[1] + " FROM for_posts" + " WHERE ThrCod=%ld" + " ORDER BY PstCod", + Thread.ThrCod); - NumPsts = (unsigned) NumRows; LastSubject[0] = '\0'; if (NumPsts) // If there are posts... { @@ -1125,7 +1124,7 @@ static void For_ShowPostsOfAThread (struct For_Forums *Forums, CreatTimeUTC = Dat_GetUNIXTimeFromStr (row[1]); - NumPst = (unsigned) NumRow; + NumPst = NumRow; NewPst = (CreatTimeUTC > ReadTimeUTC); if (NewPst && NumRow == PaginationPsts.LastItemVisible) @@ -1140,7 +1139,7 @@ static void For_ShowPostsOfAThread (struct For_Forums *Forums, /* Show post */ For_ShowAForumPost (Forums,NumPst, - (NumRow == NumRows),LastSubject, + (NumRow == NumPsts),LastSubject, NewPst,ICanModerateForum); /* Mark possible notification as seen */ @@ -1367,10 +1366,9 @@ static void For_GetPstData (long PstCod,long *UsrCod,time_t *CreatTimeUTC, { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned NumRows; /***** Get data of a post from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a post", + if (DB_QuerySELECT (&mysql_res,"can not get data of a post", "SELECT UsrCod," // row[0] "UNIX_TIMESTAMP(CreatTime)," // row[1] "Subject," // row[2] @@ -1378,10 +1376,7 @@ static void For_GetPstData (long PstCod,long *UsrCod,time_t *CreatTimeUTC, "MedCod" // row[4] " FROM for_posts" " WHERE PstCod=%ld", - PstCod); - - /***** Result should have a unique row *****/ - if (NumRows != 1) + PstCod) != 1) Lay_ShowErrorAndExit ("Internal error in database when getting data of a post."); /***** Get number of rows *****/ @@ -1690,69 +1685,68 @@ static void For_ShowForumList (struct For_Forums *Forums) IsLastItemInLevel); /* Get my centers in this institution from database */ - if ((NumCtrs = Usr_GetCtrsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod, - InsCod, - &mysql_resCtr)) > 0) // Centers found in this institution - for (NumCtr = 0; - NumCtr < NumCtrs; - NumCtr++) - { - /* Get next center */ - row = mysql_fetch_row (mysql_resCtr); - CtrCod = Str_ConvertStrCodToLongCod (row[0]); + NumCtrs = Usr_GetCtrsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod, + InsCod,&mysql_resCtr); + for (NumCtr = 0; + NumCtr < NumCtrs; + NumCtr++) + { + /* Get next center */ + row = mysql_fetch_row (mysql_resCtr); + CtrCod = Str_ConvertStrCodToLongCod (row[0]); - /* Links to forums of this center */ - if (For_WriteLinksToCtrForums (Forums, - CtrCod, - (NumCtr == NumCtrs - 1), - IsLastItemInLevel) > 0) - { - /* Get my degrees in this institution from database */ - if ((NumDegs = Usr_GetDegsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod, - CtrCod, - &mysql_resDeg)) > 0) // Degrees found in this center - for (NumDeg = 0; - NumDeg < NumDegs; - NumDeg++) + /* Links to forums of this center */ + if (For_WriteLinksToCtrForums (Forums, + CtrCod, + (NumCtr == NumCtrs - 1), + IsLastItemInLevel) > 0) + { + /* Get my degrees in this institution from database */ + if ((NumDegs = Usr_GetDegsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod, + CtrCod, + &mysql_resDeg)) > 0) // Degrees found in this center + for (NumDeg = 0; + NumDeg < NumDegs; + NumDeg++) + { + /* Get next degree */ + row = mysql_fetch_row (mysql_resDeg); + DegCod = Str_ConvertStrCodToLongCod (row[0]); + + /* Links to forums of this degree */ + if (For_WriteLinksToDegForums (Forums, + DegCod, + (NumDeg == NumDegs - 1), + IsLastItemInLevel) > 0) { - /* Get next degree */ - row = mysql_fetch_row (mysql_resDeg); - DegCod = Str_ConvertStrCodToLongCod (row[0]); - - /* Links to forums of this degree */ - if (For_WriteLinksToDegForums (Forums, - DegCod, - (NumDeg == NumDegs - 1), - IsLastItemInLevel) > 0) + /* Get my courses in this degree from database */ + NumCrss = Usr_GetCrssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod, + DegCod, + &mysql_resCrs); + for (NumCrs = 0; + NumCrs < NumCrss; + NumCrs++) { - /* Get my courses in this degree from database */ - if ((NumCrss = Usr_GetCrssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod, - DegCod, - &mysql_resCrs)) > 0) // Courses found in this degree - for (NumCrs = 0; - NumCrs < NumCrss; - NumCrs++) - { - /* Get next course */ - row = mysql_fetch_row (mysql_resCrs); - CrsCod = Str_ConvertStrCodToLongCod (row[0]); + /* Get next course */ + row = mysql_fetch_row (mysql_resCrs); + CrsCod = Str_ConvertStrCodToLongCod (row[0]); - /* Links to forums of this course */ - For_WriteLinksToCrsForums (Forums, - CrsCod, - (NumCrs == NumCrss - 1), - IsLastItemInLevel); - } - - /* Free structure that stores the query result */ - DB_FreeMySQLResult (&mysql_resCrs); + /* Links to forums of this course */ + For_WriteLinksToCrsForums (Forums, + CrsCod, + (NumCrs == NumCrss - 1), + IsLastItemInLevel); } - } - /* Free structure that stores the query result */ - DB_FreeMySQLResult (&mysql_resDeg); - } - } + /* Free structure that stores the query result */ + DB_FreeMySQLResult (&mysql_resCrs); + } + } + + /* Free structure that stores the query result */ + DB_FreeMySQLResult (&mysql_resDeg); + } + } /* Free structure that stores the query result */ DB_FreeMySQLResult (&mysql_resCtr); @@ -2286,7 +2280,6 @@ static unsigned For_GetNumThrsWithNewPstsInForum (const struct For_Forum *Forum, char SubQuery[256]; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; unsigned NumThrsWithNewPosts = NumThreads; // By default, all the threads are new to me /***** Get last time I read this forum from database *****/ @@ -2294,17 +2287,18 @@ static unsigned For_GetNumThrsWithNewPstsInForum (const struct For_Forum *Forum, sprintf (SubQuery," AND for_threads.Location=%ld",Forum->Location); else SubQuery[0] = '\0'; - NumRows = DB_QuerySELECT (&mysql_res,"can not get the date of reading of a forum", - "SELECT IFNULL(MAX(for_read.ReadTime)," // row[0] - "FROM_UNIXTIME(0))" // row[1] - " FROM for_read," - "for_threads" - " WHERE for_read.UsrCod=%ld" - " AND for_read.ThrCod=for_threads.ThrCod" - " AND for_threads.ForumType=%u%s", - Gbl.Usrs.Me.UsrDat.UsrCod, - (unsigned) Forum->Type,SubQuery); - if (NumRows) + if (DB_QuerySELECT (&mysql_res,"can not get the date of reading of a forum", + "SELECT IFNULL(MAX(for_read.ReadTime)," // row[0] + "FROM_UNIXTIME(0))" // row[1] + " FROM for_read," + "for_threads" + " WHERE for_read.UsrCod=%ld" + " AND for_read.ThrCod=for_threads.ThrCod" + " AND for_threads.ForumType=%u" + "%s", + Gbl.Usrs.Me.UsrDat.UsrCod, + (unsigned) Forum->Type, + SubQuery)) { /***** Get number of threads with a last message modify time > newest read time (row[0]) *****/ row = mysql_fetch_row (mysql_res); @@ -2354,20 +2348,16 @@ static unsigned For_GetNumOfUnreadPostsInThr (long ThrCod,unsigned NumPostsInThr { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; unsigned NumUnreadPosts = NumPostsInThr; // By default, all the posts are unread by me /***** Get last time I read this thread from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get the date of reading" - " of a thread", - "SELECT ReadTime" // row[0] - " FROM for_read" - " WHERE ThrCod=%ld" - " AND UsrCod=%ld", - ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod); - - /***** Get if last time I read this thread exists in database *****/ - if (NumRows) + if (DB_QuerySELECT (&mysql_res,"can not get the date of reading of a thread", + "SELECT ReadTime" // row[0] + " FROM for_read" + " WHERE ThrCod=%ld" + " AND UsrCod=%ld", + ThrCod, + Gbl.Usrs.Me.UsrDat.UsrCod)) { /***** Get the number of posts in thread with a modify time > newest read time for me (row[0]) *****/ row = mysql_fetch_row (mysql_res); @@ -2472,24 +2462,30 @@ static void For_ShowForumThreadsHighlightingOneThread (struct For_Forums *Forums switch (Forums->ThreadsOrder) { case Dat_START_TIME: // First post time - NumThrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get thread of a forum", - "SELECT for_threads.ThrCod" // row[0] - " FROM for_threads," - "for_posts" - " WHERE for_threads.ForumType=%u%s" - " AND for_threads.FirstPstCod=for_posts.PstCod" - " ORDER BY for_posts.CreatTime DESC", - (unsigned) Forums->Forum.Type,SubQuery); + NumThrs = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get thread of a forum", + "SELECT for_threads.ThrCod" // row[0] + " FROM for_threads," + "for_posts" + " WHERE for_threads.ForumType=%u" + "%s" + " AND for_threads.FirstPstCod=for_posts.PstCod" + " ORDER BY for_posts.CreatTime DESC", + (unsigned) Forums->Forum.Type, + SubQuery); break; case Dat_END_TIME: // Last post time - NumThrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get thread of a forum", - "SELECT for_threads.ThrCod" // row[0] - " FROM for_threads," - "for_posts" - " WHERE for_threads.ForumType=%u%s" - " AND for_threads.LastPstCod=for_posts.PstCod" - " ORDER BY for_posts.CreatTime DESC", - (unsigned) Forums->Forum.Type,SubQuery); + NumThrs = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get thread of a forum", + "SELECT for_threads.ThrCod" // row[0] + " FROM for_threads," + "for_posts" + " WHERE for_threads.ForumType=%u" + "%s" + " AND for_threads.LastPstCod=for_posts.PstCod" + " ORDER BY for_posts.CreatTime DESC", + (unsigned) Forums->Forum.Type, + SubQuery); break; default: // Impossible return; @@ -3654,29 +3650,24 @@ static void For_GetThreadData (struct For_Thread *Thr) extern const char *Txt_no_subject; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; Dat_StartEndTime_t Order; /***** Get data of a thread from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get data" - " of a thread of a forum", - "SELECT m0.PstCod," // row[0] - "m1.PstCod," // row[1] - "m0.UsrCod," // row[2] - "m1.UsrCod," // row[3] - "UNIX_TIMESTAMP(m0.CreatTime)," // row[4] - "UNIX_TIMESTAMP(m1.CreatTime)," // row[5] - "m0.Subject" - " FROM for_threads," - "for_posts AS m0," - "for_posts AS m1" - " WHERE for_threads.ThrCod=%ld" - " AND for_threads.FirstPstCod=m0.PstCod" - " AND for_threads.LastPstCod=m1.PstCod", - Thr->ThrCod); - - /***** The result of the query should have one row *****/ - if (NumRows != 1) + if (DB_QuerySELECT (&mysql_res,"can not get data of a thread of a forum", + "SELECT m0.PstCod," // row[0] + "m1.PstCod," // row[1] + "m0.UsrCod," // row[2] + "m1.UsrCod," // row[3] + "UNIX_TIMESTAMP(m0.CreatTime)," // row[4] + "UNIX_TIMESTAMP(m1.CreatTime)," // row[5] + "m0.Subject" + " FROM for_threads," + "for_posts AS m0," + "for_posts AS m1" + " WHERE for_threads.ThrCod=%ld" + " AND for_threads.FirstPstCod=m0.PstCod" + " AND for_threads.LastPstCod=m1.PstCod", + Thr->ThrCod) != 1) Lay_ShowErrorAndExit ("Error when getting data of a thread of a forum."); row = mysql_fetch_row (mysql_res); diff --git a/swad_game.c b/swad_game.c index 21b70eac..e48c0395 100644 --- a/swad_game.c +++ b/swad_game.c @@ -866,7 +866,6 @@ void Gam_GetListGames (struct Gam_Games *Games,Gam_Order_t SelectedOrder) MYSQL_RES *mysql_res; MYSQL_ROW row; char *HiddenSubQuery; - unsigned long NumRows = 0; // Initialized to avoid warning unsigned NumGame; /***** Free list of games *****/ @@ -895,30 +894,30 @@ void Gam_GetListGames (struct Gam_Games *Games,Gam_Order_t SelectedOrder) } /***** Get list of games from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get games", - "SELECT gam_games.GamCod," // row[0] - "MIN(mch_matches.StartTime) AS StartTime," // row[1] - "MAX(mch_matches.EndTime) AS EndTime" // row[2] - " FROM gam_games" - " LEFT JOIN mch_matches" - " ON gam_games.GamCod=mch_matches.GamCod" - " WHERE gam_games.CrsCod=%ld" - "%s" - " GROUP BY gam_games.GamCod" - " ORDER BY %s", - Gbl.Hierarchy.Crs.CrsCod, - HiddenSubQuery, - OrderBySubQuery[SelectedOrder]); + Games->Num = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get games", + "SELECT gam_games.GamCod," // row[0] + "MIN(mch_matches.StartTime) AS StartTime," // row[1] + "MAX(mch_matches.EndTime) AS EndTime" // row[2] + " FROM gam_games" + " LEFT JOIN mch_matches" + " ON gam_games.GamCod=mch_matches.GamCod" + " WHERE gam_games.CrsCod=%ld" + "%s" + " GROUP BY gam_games.GamCod" + " ORDER BY %s", + Gbl.Hierarchy.Crs.CrsCod, + HiddenSubQuery, + OrderBySubQuery[SelectedOrder]); /***** Free allocated memory for subquery *****/ free (HiddenSubQuery); - if (NumRows) // Games found... + if (Games->Num) // Games found... { - Games->Num = (unsigned) NumRows; - /***** Create list of games *****/ - if ((Games->Lst = malloc (NumRows * sizeof (*Games->Lst))) == NULL) + if ((Games->Lst = malloc ((size_t) Games->Num * + sizeof (*Games->Lst))) == NULL) Lay_NotEnoughMemoryExit (); /***** Get the games codes *****/ @@ -932,8 +931,6 @@ void Gam_GetListGames (struct Gam_Games *Games,Gam_Order_t SelectedOrder) Lay_ShowErrorAndExit ("Error: wrong game code."); } } - else - Games->Num = 0; /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -1017,25 +1014,23 @@ void Gam_GetDataOfGameByCod (struct Gam_Game *Game) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; /***** Get data of game from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get game data", - "SELECT gam_games.GamCod," // row[0] - "gam_games.CrsCod," // row[1] - "gam_games.Hidden," // row[2] - "gam_games.UsrCod," // row[3] - "gam_games.MaxGrade," // row[4] - "gam_games.Visibility," // row[5] - "gam_games.Title" // row[6] - " FROM gam_games" - " LEFT JOIN mch_matches" - " ON gam_games.GamCod=mch_matches.GamCod" - " WHERE gam_games.GamCod=%ld" - " AND gam_games.CrsCod='%ld'", // Extra check - Game->GamCod, - Gbl.Hierarchy.Crs.CrsCod); - if (NumRows) // Game found... + if (DB_QuerySELECT (&mysql_res,"can not get game data", + "SELECT gam_games.GamCod," // row[0] + "gam_games.CrsCod," // row[1] + "gam_games.Hidden," // row[2] + "gam_games.UsrCod," // row[3] + "gam_games.MaxGrade," // row[4] + "gam_games.Visibility," // row[5] + "gam_games.Title" // row[6] + " FROM gam_games" + " LEFT JOIN mch_matches" + " ON gam_games.GamCod=mch_matches.GamCod" + " WHERE gam_games.GamCod=%ld" + " AND gam_games.CrsCod='%ld'", // Extra check + Game->GamCod, + Gbl.Hierarchy.Crs.CrsCod)) // Game found... { /* Get row */ row = mysql_fetch_row (mysql_res); @@ -1082,13 +1077,12 @@ void Gam_GetDataOfGameByCod (struct Gam_Game *Game) if (Game->GamCod > 0) { /***** Get start and end times from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get game data", - "SELECT UNIX_TIMESTAMP(MIN(StartTime))," // row[0] - "UNIX_TIMESTAMP(MAX(EndTime))" // row[1] - " FROM mch_matches" - " WHERE GamCod=%ld", - Game->GamCod); - if (NumRows) + if (DB_QuerySELECT (&mysql_res,"can not get game data", + "SELECT UNIX_TIMESTAMP(MIN(StartTime))," // row[0] + "UNIX_TIMESTAMP(MAX(EndTime))" // row[1] + " FROM mch_matches" + " WHERE GamCod=%ld", + Game->GamCod)) { /* Get row */ row = mysql_fetch_row (mysql_res); @@ -1935,13 +1929,13 @@ static void Gam_ListGameQuestions (struct Gam_Games *Games,struct Gam_Game *Game /***** Get data of questions from database *****/ NumQsts = (unsigned) - DB_QuerySELECT (&mysql_res,"can not get game questions", - "SELECT QstInd," // row[0] - "QstCod" // row[1] - " FROM gam_questions" - " WHERE GamCod=%ld" - " ORDER BY QstInd", - Game->GamCod); + DB_QuerySELECT (&mysql_res,"can not get game questions", + "SELECT QstInd," // row[0] + "QstCod" // row[1] + " FROM gam_questions" + " WHERE GamCod=%ld" + " ORDER BY QstInd", + Game->GamCod); /***** Begin box *****/ Games->GamCod = Game->GamCod; diff --git a/swad_group.c b/swad_group.c index 8377ab83..f2fdfd5f 100644 --- a/swad_group.c +++ b/swad_group.c @@ -2935,7 +2935,6 @@ void Grp_GetListGrpTypesAndGrpsInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes) unsigned NumGrp; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; struct GroupType *GrpTyp; struct Group *Grp; Rol_Role_t Role; @@ -2952,13 +2951,11 @@ void Grp_GetListGrpTypesAndGrpsInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes) if (GrpTyp->NumGrps) // If there are groups of this type... { /***** Query database *****/ - if ((NumRows = Grp_GetGrpsOfType (GrpTyp->GrpTypCod,&mysql_res)) > 0) // Groups found... + GrpTyp->NumGrps = Grp_GetGrpsOfType (GrpTyp->GrpTypCod,&mysql_res); + if (GrpTyp->NumGrps > 0) // Groups found... { - // NumRows should be equal to GrpTyp->NumGrps - GrpTyp->NumGrps = (unsigned) NumRows; - /***** Create list with groups of this type *****/ - if ((GrpTyp->LstGrps = calloc (GrpTyp->NumGrps, + if ((GrpTyp->LstGrps = calloc ((size_t) GrpTyp->NumGrps, sizeof (*GrpTyp->LstGrps))) == NULL) Lay_NotEnoughMemoryExit (); @@ -3005,9 +3002,6 @@ void Grp_GetListGrpTypesAndGrpsInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes) Grp->FileZones = (row[6][0] == 'Y'); } } - else // Error: groups should be found, but really they haven't be found. - // This never should happen. - GrpTyp->NumGrps = 0; /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -3085,24 +3079,25 @@ static unsigned Grp_CountNumGrpsInThisCrsOfType (long GrpTypCod) /******************** Get groups of a type in this course ********************/ /*****************************************************************************/ -unsigned long Grp_GetGrpsOfType (long GrpTypCod,MYSQL_RES **mysql_res) +unsigned Grp_GetGrpsOfType (long GrpTypCod,MYSQL_RES **mysql_res) { /***** Get groups of a type from database *****/ // Don't use INNER JOIN because there are groups without assigned room - return DB_QuerySELECT (mysql_res,"can not get groups of a type", - "SELECT grp_groups.GrpCod," // row[0] - "grp_groups.GrpName," // row[1] - "grp_groups.RooCod," // row[2] - "roo_rooms.ShortName," // row[3] - "grp_groups.MaxStudents," // row[4] - "grp_groups.Open," // row[5] - "grp_groups.FileZones" // row[6] - " FROM grp_groups" - " LEFT JOIN roo_rooms" - " ON grp_groups.RooCod=roo_rooms.RooCod" - " WHERE grp_groups.GrpTypCod=%ld" - " ORDER BY grp_groups.GrpName", - GrpTypCod); + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get groups of a type", + "SELECT grp_groups.GrpCod," // row[0] + "grp_groups.GrpName," // row[1] + "grp_groups.RooCod," // row[2] + "roo_rooms.ShortName," // row[3] + "grp_groups.MaxStudents," // row[4] + "grp_groups.Open," // row[5] + "grp_groups.FileZones" // row[6] + " FROM grp_groups" + " LEFT JOIN roo_rooms" + " ON grp_groups.RooCod=roo_rooms.RooCod" + " WHERE grp_groups.GrpTypCod=%ld" + " ORDER BY grp_groups.GrpName", + GrpTypCod); } /*****************************************************************************/ @@ -3177,7 +3172,6 @@ void Grp_GetDataOfGroupByCod (struct GroupData *GrpDat) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; /***** Reset values *****/ GrpDat->GrpTypCod = -1L; @@ -3195,26 +3189,24 @@ void Grp_GetDataOfGroupByCod (struct GroupData *GrpDat) if (GrpDat->GrpCod > 0) { /***** Get data of a group from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a group", - "SELECT grp_groups.GrpTypCod," // row[0] - "grp_types.CrsCod," // row[1] - "grp_types.GrpTypName," // row[2] - "grp_types.Multiple," // row[3] - "grp_groups.GrpName," // row[4] - "grp_groups.RooCod," // row[5] - "roo_rooms.ShortName," // row[6] - "grp_groups.MaxStudents," // row[7] - "grp_groups.Open," // row[8] - "grp_groups.FileZones" // row[9] - " FROM (grp_groups," - "grp_types)" - " LEFT JOIN roo_rooms" - " ON grp_groups.RooCod=roo_rooms.RooCod" - " WHERE grp_groups.GrpCod=%ld" - " AND grp_groups.GrpTypCod=grp_types.GrpTypCod", - GrpDat->GrpCod); - - if (NumRows == 1) + if (DB_QuerySELECT (&mysql_res,"can not get data of a group", + "SELECT grp_groups.GrpTypCod," // row[0] + "grp_types.CrsCod," // row[1] + "grp_types.GrpTypName," // row[2] + "grp_types.Multiple," // row[3] + "grp_groups.GrpName," // row[4] + "grp_groups.RooCod," // row[5] + "roo_rooms.ShortName," // row[6] + "grp_groups.MaxStudents," // row[7] + "grp_groups.Open," // row[8] + "grp_groups.FileZones" // row[9] + " FROM (grp_groups," + "grp_types)" + " LEFT JOIN roo_rooms" + " ON grp_groups.RooCod=roo_rooms.RooCod" + " WHERE grp_groups.GrpCod=%ld" + " AND grp_groups.GrpTypCod=grp_types.GrpTypCod", + GrpDat->GrpCod) == 1) { /***** Get data of group *****/ row = mysql_fetch_row (mysql_res); @@ -3735,34 +3727,35 @@ void Grp_GetNamesGrpsStdBelongsTo (long GrpTypCod,long UsrCod,char *GroupNames) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRow; - unsigned long NumRows; + unsigned NumGrps; + unsigned NumGrp; size_t MaxLength = (Grp_MAX_BYTES_GROUP_NAME + 2) * Gbl.Crs.Grps.GrpTypes.NumGrpsTotal; /***** Get the names of groups which a user belongs to, from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get the names of groups" - " a user belongs to", - "SELECT grp_groups.GrpName" // row[0] - " FROM grp_groups," - "grp_users" - " WHERE grp_groups.GrpTypCod=%ld" - " AND grp_groups.GrpCod=grp_users.GrpCod" - " AND grp_users.UsrCod=%ld" - " ORDER BY grp_groups.GrpName", - GrpTypCod,UsrCod); + NumGrps = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get names of groups a user belongs to", + "SELECT grp_groups.GrpName" // row[0] + " FROM grp_groups," + "grp_users" + " WHERE grp_groups.GrpTypCod=%ld" + " AND grp_groups.GrpCod=grp_users.GrpCod" + " AND grp_users.UsrCod=%ld" + " ORDER BY grp_groups.GrpName", + GrpTypCod, + UsrCod); /***** Get the groups *****/ GroupNames[0] = '\0'; - for (NumRow = 0; - NumRow < NumRows; - NumRow++) + for (NumGrp = 0; + NumGrp < NumGrps; + NumGrp++) { /* Get next group */ row = mysql_fetch_row (mysql_res); - /* El group name in row[0] */ - if (NumRow) + /* Group name is in row[0] */ + if (NumGrp) Str_Concat (GroupNames,", ",MaxLength); Str_Concat (GroupNames,row[0],MaxLength); } diff --git a/swad_group.h b/swad_group.h index dccd4a4f..38b6707e 100644 --- a/swad_group.h +++ b/swad_group.h @@ -194,7 +194,7 @@ void Grp_FreeListGrpTypesAndGrps (void); void Grp_OpenGroupsAutomatically (void); void Grp_GetListGrpTypesAndGrpsInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes); unsigned Grp_CountNumGrpsInCurrentCrs (void); -unsigned long Grp_GetGrpsOfType (long GrpTypCod,MYSQL_RES **mysql_res); +unsigned Grp_GetGrpsOfType (long GrpTypCod,MYSQL_RES **mysql_res); void Grp_GetDataOfGroupByCod (struct GroupData *GrpDat); bool Grp_CheckIfGroupExists (long GrpCod); bool Grp_CheckIfGroupBelongsToCourse (long GrpCod,long CrsCod); diff --git a/swad_info.c b/swad_info.c index 19906f33..294bb583 100644 --- a/swad_info.c +++ b/swad_info.c @@ -524,8 +524,8 @@ bool Inf_GetIfIMustReadAnyCrsInfoInThisCrs (void) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRow; - unsigned long NumRows; + unsigned NumInfos; + unsigned NumInfo; Inf_InfoType_t InfoType; /***** Reset must-be-read to false for all info types *****/ @@ -535,25 +535,25 @@ bool Inf_GetIfIMustReadAnyCrsInfoInThisCrs (void) Gbl.Crs.Info.MustBeRead[InfoType] = false; /***** Get info types where students must read info *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get if you must read" - " any course info", - "SELECT InfoType" // row[0] - " FROM crs_info_src" - " WHERE CrsCod=%ld" - " AND MustBeRead='Y'" - " AND InfoType NOT IN" - " (SELECT InfoType" - " FROM crs_info_read" - " WHERE UsrCod=%ld" - " AND CrsCod=%ld)", - Gbl.Hierarchy.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod, - Gbl.Hierarchy.Crs.CrsCod); + NumInfos = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get if you must read any course info", + "SELECT InfoType" // row[0] + " FROM crs_info_src" + " WHERE CrsCod=%ld" + " AND MustBeRead='Y'" + " AND InfoType NOT IN" + " (SELECT InfoType" + " FROM crs_info_read" + " WHERE UsrCod=%ld" + " AND CrsCod=%ld)", + Gbl.Hierarchy.Crs.CrsCod, + Gbl.Usrs.Me.UsrDat.UsrCod, + Gbl.Hierarchy.Crs.CrsCod); /***** Set must-be-read to true for each rown in result *****/ - for (NumRow = 0; - NumRow < NumRows; - NumRow++) + for (NumInfo = 0; + NumInfo < NumInfos; + NumInfo++) { row = mysql_fetch_row (mysql_res); @@ -566,7 +566,7 @@ bool Inf_GetIfIMustReadAnyCrsInfoInThisCrs (void) /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); - return (NumRows != 0); + return (NumInfos != 0); } /*****************************************************************************/ @@ -1500,24 +1500,20 @@ void Inf_GetAndCheckInfoSrcFromDB (struct Syl_Syllabus *Syllabus, { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; /***** Set default values *****/ *InfoSrc = Inf_INFO_SRC_NONE; *MustBeRead = false; /***** Get info source for a specific type of info from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get info source", - "SELECT InfoSrc," // row[0] - "MustBeRead" // row[1] - " FROM crs_info_src" - " WHERE CrsCod=%ld" - " AND InfoType='%s'", - CrsCod, - Inf_NamesInDBForInfoType[InfoType]); - - /***** The result of the query must have one row or none *****/ - if (NumRows == 1) + if (DB_QuerySELECT (&mysql_res,"can not get info source", + "SELECT InfoSrc," // row[0] + "MustBeRead" // row[1] + " FROM crs_info_src" + " WHERE CrsCod=%ld" + " AND InfoType='%s'", + CrsCod, + Inf_NamesInDBForInfoType[InfoType]) == 1) { /* Get row */ row = mysql_fetch_row (mysql_res); @@ -1528,13 +1524,12 @@ void Inf_GetAndCheckInfoSrcFromDB (struct Syl_Syllabus *Syllabus, /* Get if students must read info (row[1]) */ *MustBeRead = (row[1][0] == 'Y'); } + else + Lay_ShowErrorAndExit ("Error when getting info source."); /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); - if (NumRows > 1) - Lay_ShowErrorAndExit ("Error when getting info source."); - /***** If info is empty, return Inf_INFO_SRC_NONE *****/ switch (*InfoSrc) { @@ -1663,21 +1658,17 @@ void Inf_GetInfoTxtFromDB (long CrsCod,Inf_InfoType_t InfoType, { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; /***** Get info source for a specific type of course information (bibliography, FAQ, links or evaluation) from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get info text", + if (DB_QuerySELECT (&mysql_res,"can not get info text", "SELECT InfoTxtHTML," // row[0] "InfoTxtMD" // row[1] " FROM crs_info_txt" " WHERE CrsCod=%ld" " AND InfoType='%s'", CrsCod, - Inf_NamesInDBForInfoType[InfoType]); - - /***** The result of the query must have one row or none *****/ - if (NumRows == 1) + Inf_NamesInDBForInfoType[InfoType]) == 1) { /* Get info text */ row = mysql_fetch_row (mysql_res); @@ -1695,14 +1686,11 @@ void Inf_GetInfoTxtFromDB (long CrsCod,Inf_InfoType_t InfoType, if (InfoTxtHTML) InfoTxtHTML[0] = '\0'; if (InfoTxtMD) - InfoTxtMD [0] = '\0'; + InfoTxtMD [0] = '\0'; } /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); - - if (NumRows > 1) - Lay_ShowErrorAndExit ("Error when getting info text."); } /*****************************************************************************/ diff --git a/swad_institution.c b/swad_institution.c index 0eda8bfc..2ad88deb 100644 --- a/swad_institution.c +++ b/swad_institution.c @@ -628,31 +628,28 @@ void Ins_GetBasicListOfInstitutions (long CtyCod) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows = 0; // Initialized to avoid warning unsigned NumIns; struct Ins_Instit *Ins; /***** Get institutions from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get institutions", - "SELECT InsCod," // row[0] - "CtyCod," // row[1] - "Status," // row[2] - "RequesterUsrCod," // row[3] - "ShortName," // row[4] - "FullName," // row[5] - "WWW" // row[6] - " FROM ins_instits" - " WHERE CtyCod=%ld" - " ORDER BY FullName", - CtyCod); + Gbl.Hierarchy.Inss.Num = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get institutions", + "SELECT InsCod," // row[0] + "CtyCod," // row[1] + "Status," // row[2] + "RequesterUsrCod," // row[3] + "ShortName," // row[4] + "FullName," // row[5] + "WWW" // row[6] + " FROM ins_instits" + " WHERE CtyCod=%ld" + " ORDER BY FullName", + CtyCod); - if (NumRows) // Institutions found... + if (Gbl.Hierarchy.Inss.Num) // Institutions found... { - // NumRows should be equal to Deg->NumCourses - Gbl.Hierarchy.Inss.Num = (unsigned) NumRows; - /***** Create list with institutions *****/ - if ((Gbl.Hierarchy.Inss.Lst = calloc (NumRows, + if ((Gbl.Hierarchy.Inss.Lst = calloc ((size_t) Gbl.Hierarchy.Inss.Num, sizeof (*Gbl.Hierarchy.Inss.Lst))) == NULL) Lay_NotEnoughMemoryExit (); @@ -672,10 +669,7 @@ void Ins_GetBasicListOfInstitutions (long CtyCod) } } else - { - Gbl.Hierarchy.Inss.Num = 0; Gbl.Hierarchy.Inss.Lst = NULL; - } /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -695,52 +689,49 @@ void Ins_GetFullListOfInstitutions (long CtyCod) }; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows = 0; // Initialized to avoid warning unsigned NumIns; struct Ins_Instit *Ins; /***** Get institutions from database *****/ /* Query database */ - NumRows = DB_QuerySELECT (&mysql_res,"can not get institutions", - "(SELECT ins_instits.InsCod," // row[0] - "ins_instits.CtyCod," // row[1] - "ins_instits.Status," // row[2] - "ins_instits.RequesterUsrCod," // row[3] - "ins_instits.ShortName," // row[4] - "ins_instits.FullName," // row[5] - "ins_instits.WWW," // row[6] - "COUNT(*) AS NumUsrs" // row[7] - " FROM ins_instits," - "usr_data" - " WHERE ins_instits.CtyCod=%ld" - " AND ins_instits.InsCod=usr_data.InsCod" - " GROUP BY ins_instits.InsCod)" - " UNION " - "(SELECT InsCod," // row[0] - "CtyCod," // row[1] - "Status," // row[2] - "RequesterUsrCod," // row[3] - "ShortName," // row[4] - "FullName," // row[5] - "WWW," // row[6] - "0 AS NumUsrs" // row[7] - " FROM ins_instits" - " WHERE CtyCod=%ld" - " AND InsCod NOT IN" - " (SELECT DISTINCT InsCod" - " FROM usr_data))" - " ORDER BY %s", - CtyCod, - CtyCod, - OrderBySubQuery[Gbl.Hierarchy.Inss.SelectedOrder]); + Gbl.Hierarchy.Inss.Num = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get institutions", + "(SELECT ins_instits.InsCod," // row[0] + "ins_instits.CtyCod," // row[1] + "ins_instits.Status," // row[2] + "ins_instits.RequesterUsrCod," // row[3] + "ins_instits.ShortName," // row[4] + "ins_instits.FullName," // row[5] + "ins_instits.WWW," // row[6] + "COUNT(*) AS NumUsrs" // row[7] + " FROM ins_instits," + "usr_data" + " WHERE ins_instits.CtyCod=%ld" + " AND ins_instits.InsCod=usr_data.InsCod" + " GROUP BY ins_instits.InsCod)" + " UNION " + "(SELECT InsCod," // row[0] + "CtyCod," // row[1] + "Status," // row[2] + "RequesterUsrCod," // row[3] + "ShortName," // row[4] + "FullName," // row[5] + "WWW," // row[6] + "0 AS NumUsrs" // row[7] + " FROM ins_instits" + " WHERE CtyCod=%ld" + " AND InsCod NOT IN" + " (SELECT DISTINCT InsCod" + " FROM usr_data))" + " ORDER BY %s", + CtyCod, + CtyCod, + OrderBySubQuery[Gbl.Hierarchy.Inss.SelectedOrder]); - if (NumRows) // Institutions found... + if (Gbl.Hierarchy.Inss.Num) // Institutions found... { - // NumRows should be equal to Deg->NumCourses - Gbl.Hierarchy.Inss.Num = (unsigned) NumRows; - /***** Create list with institutions *****/ - if ((Gbl.Hierarchy.Inss.Lst = calloc (NumRows, + if ((Gbl.Hierarchy.Inss.Lst = calloc ((size_t) Gbl.Hierarchy.Inss.Num, sizeof (*Gbl.Hierarchy.Inss.Lst))) == NULL) Lay_NotEnoughMemoryExit (); @@ -762,10 +753,7 @@ void Ins_GetFullListOfInstitutions (long CtyCod) } } else - { - Gbl.Hierarchy.Inss.Num = 0; Gbl.Hierarchy.Inss.Lst = NULL; - } /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); diff --git a/swad_link.c b/swad_link.c index df40cbed..c2235ed7 100644 --- a/swad_link.c +++ b/swad_link.c @@ -287,27 +287,26 @@ void Lnk_GetListLinks (void) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; unsigned NumLnk; struct Link *Lnk; if (Gbl.DB.DatabaseIsOpen) { /***** Get institutional links from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get institutional links", - "SELECT LnkCod," // row[0] - "ShortName," // row[1] - "FullName," // row[2] - "WWW" // row[3] - " FROM lnk_links" - " ORDER BY ShortName"); + Gbl.Links.Num = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get institutional links", + "SELECT LnkCod," // row[0] + "ShortName," // row[1] + "FullName," // row[2] + "WWW" // row[3] + " FROM lnk_links" + " ORDER BY ShortName"); - if (NumRows) // Places found... + if (Gbl.Links.Num) // Places found... { - Gbl.Links.Num = (unsigned) NumRows; - /***** Create list with places *****/ - if ((Gbl.Links.Lst = calloc (NumRows,sizeof (*Gbl.Links.Lst))) == NULL) + if ((Gbl.Links.Lst = calloc ((size_t) Gbl.Links.Num, + sizeof (*Gbl.Links.Lst))) == NULL) Lay_NotEnoughMemoryExit (); /***** Get the links *****/ @@ -331,8 +330,6 @@ void Lnk_GetListLinks (void) Str_Copy (Lnk->WWW ,row[3],sizeof (Lnk->WWW ) - 1); } } - else - Gbl.Links.Num = 0; /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -347,7 +344,6 @@ void Lnk_GetDataOfLinkByCod (struct Link *Lnk) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; /***** Clear data *****/ Lnk->ShrtName[0] = Lnk->FullName[0] = Lnk->WWW[0] = '\0'; @@ -356,16 +352,13 @@ void Lnk_GetDataOfLinkByCod (struct Link *Lnk) if (Lnk->LnkCod > 0) { /***** Get data of an institutional link from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get data" - " of an institutional link", - "SELECT ShortName," // row[0] - "FullName," // row[1] - "WWW" // row[2] - " FROM lnk_links" - " WHERE LnkCod=%ld", - Lnk->LnkCod); - - if (NumRows) // Link found... + if (DB_QuerySELECT (&mysql_res,"can not get data of an institutional link", + "SELECT ShortName," // row[0] + "FullName," // row[1] + "WWW" // row[2] + " FROM lnk_links" + " WHERE LnkCod=%ld", + Lnk->LnkCod)) // Link found... { /* Get row */ row = mysql_fetch_row (mysql_res); diff --git a/swad_log.c b/swad_log.c index df333c1c..f1eff83a 100644 --- a/swad_log.c +++ b/swad_log.c @@ -256,8 +256,8 @@ void Log_GetAndShowLastClicks (void) extern const char *Txt_ROLES_SINGUL_Abc[Rol_NUM_ROLES][Usr_NUM_SEXS]; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRow; - unsigned long NumRows; + unsigned NumClicks; + unsigned NumClick; long ActCod; Act_Action_t Action; const char *ClassRow; @@ -265,19 +265,20 @@ void Log_GetAndShowLastClicks (void) struct Hie_Hierarchy Hie; /***** Get last clicks from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get last clicks", - "SELECT LogCod," // row[0] - "ActCod," // row[1] - "UNIX_TIMESTAMP()-" - "UNIX_TIMESTAMP(ClickTime)," // row[2] - "Role," // row[3] - "CtyCod," // row[4] - "InsCod," // row[5] - "CtrCod," // row[6] - "DegCod" // row[7] - " FROM log_recent" - " ORDER BY LogCod DESC" - " LIMIT 20"); + NumClicks = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get last clicks", + "SELECT LogCod," // row[0] + "ActCod," // row[1] + "UNIX_TIMESTAMP()-" + "UNIX_TIMESTAMP(ClickTime)," // row[2] + "Role," // row[3] + "CtyCod," // row[4] + "InsCod," // row[5] + "CtrCod," // row[6] + "DegCod" // row[7] + " FROM log_recent" + " ORDER BY LogCod DESC" + " LIMIT 20"); /***** Write list of connected users *****/ HTM_TABLE_BeginCenterPadding (1); @@ -294,9 +295,9 @@ void Log_GetAndShowLastClicks (void) HTM_TR_End (); - for (NumRow = 0; - NumRow < NumRows; - NumRow++) + for (NumClick = 0; + NumClick < NumClicks; + NumClick++) { row = mysql_fetch_row (mysql_res); diff --git a/swad_mail.c b/swad_mail.c index 15fe1fb9..0b4e0ceb 100644 --- a/swad_mail.c +++ b/swad_mail.c @@ -252,13 +252,18 @@ static void Mai_GetListMailDomainsAllowedForNotif (void) { static const char *OrderBySubQuery[Mai_NUM_ORDERS] = { - [Mai_ORDER_BY_DOMAIN] = "Domain,Info,N DESC", - [Mai_ORDER_BY_INFO ] = "Info,Domain,N DESC", - [Mai_ORDER_BY_USERS ] = "N DESC,Info,Domain", + [Mai_ORDER_BY_DOMAIN] = "Domain," + "Info," + "N DESC", + [Mai_ORDER_BY_INFO ] = "Info," + "Domain," + "N DESC", + [Mai_ORDER_BY_USERS ] = "N DESC," + "Info," + "Domain", }; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; unsigned NumMai; struct Mail *Mai; @@ -282,31 +287,31 @@ static void Mai_GetListMailDomainsAllowedForNotif (void) " FROM T1"); /***** Get mail domains from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get mail domains", - "(SELECT ntf_mail_domains.MaiCod," // row[0] - "ntf_mail_domains.Domain AS Domain," // row[1] - "ntf_mail_domains.Info AS Info," // row[2] - "T1.N AS N" // row[3] - " FROM ntf_mail_domains,T1" - " WHERE ntf_mail_domains.Domain=T1.Domain COLLATE 'latin1_bin')" - " UNION " - "(SELECT MaiCod," // row[0] - "Domain," // row[1] - "Info," // row[2] - "0 AS N" // row[3] - " FROM ntf_mail_domains" - " WHERE Domain NOT IN" - " (SELECT Domain COLLATE 'latin1_bin'" - " FROM T2))" - " ORDER BY %s", // COLLATE necessary to avoid error in comparisons - OrderBySubQuery[Gbl.Mails.SelectedOrder]); + Gbl.Mails.Num = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get mail domains", + "(SELECT ntf_mail_domains.MaiCod," // row[0] + "ntf_mail_domains.Domain AS Domain," // row[1] + "ntf_mail_domains.Info AS Info," // row[2] + "T1.N AS N" // row[3] + " FROM ntf_mail_domains,T1" + " WHERE ntf_mail_domains.Domain=T1.Domain COLLATE 'latin1_bin')" + " UNION " + "(SELECT MaiCod," // row[0] + "Domain," // row[1] + "Info," // row[2] + "0 AS N" // row[3] + " FROM ntf_mail_domains" + " WHERE Domain NOT IN" + " (SELECT Domain COLLATE 'latin1_bin'" + " FROM T2))" + " ORDER BY %s", // COLLATE necessary to avoid error in comparisons + OrderBySubQuery[Gbl.Mails.SelectedOrder]); - if (NumRows) // Mail domains found... + if (Gbl.Mails.Num) // Mail domains found... { - Gbl.Mails.Num = (unsigned) NumRows; - /***** Create list with places *****/ - if ((Gbl.Mails.Lst = calloc (NumRows,sizeof (*Gbl.Mails.Lst))) == NULL) + if ((Gbl.Mails.Lst = calloc ((size_t) Gbl.Mails.Num, + sizeof (*Gbl.Mails.Lst))) == NULL) Lay_NotEnoughMemoryExit (); /***** Get the mail domains *****/ @@ -332,15 +337,14 @@ static void Mai_GetListMailDomainsAllowedForNotif (void) Mai->NumUsrs = 0; } } - else - Gbl.Mails.Num = 0; /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); /***** Drop temporary table *****/ DB_Query ("can not remove temporary tables", - "DROP TEMPORARY TABLE IF EXISTS T1,T2"); + "DROP TEMPORARY TABLE IF EXISTS T1," + "T2"); } /*****************************************************************************/ @@ -424,7 +428,6 @@ void Mai_GetDataOfMailDomainByCod (struct Mail *Mai) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; /***** Clear data *****/ Mai->Domain[0] = Mai->Info[0] = '\0'; @@ -433,15 +436,12 @@ void Mai_GetDataOfMailDomainByCod (struct Mail *Mai) if (Mai->MaiCod > 0) { /***** Get data of a mail domain from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get data" - " of a mail domain", - "SELECT Domain," // row[0] - "Info" // row[1] - " FROM ntf_mail_domains" - " WHERE MaiCod=%ld", - Mai->MaiCod); - - if (NumRows) // Mail found... + if (DB_QuerySELECT (&mysql_res,"can not get data of a mail domain", + "SELECT Domain," // row[0] + "Info" // row[1] + " FROM ntf_mail_domains" + " WHERE MaiCod=%ld", + Mai->MaiCod)) // Mail found... { /* Get row */ row = mysql_fetch_row (mysql_res); @@ -1082,20 +1082,17 @@ bool Mai_GetEmailFromUsrCod (struct UsrData *UsrDat) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; bool Found; /***** Get current (last updated) user's nickname from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get email address", - "SELECT E_mail," // row[0] - "Confirmed" // row[1] - " FROM usr_emails" - " WHERE UsrCod=%ld" - " ORDER BY CreatTime DESC" - " LIMIT 1", - UsrDat->UsrCod); - - if (NumRows == 0) + if (DB_QuerySELECT (&mysql_res,"can not get email address", + "SELECT E_mail," // row[0] + "Confirmed" // row[1] + " FROM usr_emails" + " WHERE UsrCod=%ld" + " ORDER BY CreatTime DESC" + " LIMIT 1", + UsrDat->UsrCod) == 0) { UsrDat->Email[0] = '\0'; UsrDat->EmailConfirmed = false; diff --git a/swad_mark.c b/swad_mark.c index e39ef689..f86aae0b 100644 --- a/swad_mark.c +++ b/swad_mark.c @@ -169,32 +169,28 @@ static void Mrk_GetNumRowsHeaderAndFooter (struct MarksProperties *Marks) long Cod = Brw_GetCodForFiles (); MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; /***** Get number of rows of header and footer from database *****/ /* There should be a single file in database. If, due to an error, there is more than one file, get the number of rows of the more recent file. */ - NumRows = DB_QuerySELECT (&mysql_res,"can not get the number of rows" - " in header and footer", - "SELECT mrk_marks.%s," // row[0] - "mrk_marks.%s" // row[1] - " FROM brw_files," - "mrk_marks" - " WHERE brw_files.FileBrowser=%u" - " AND brw_files.Cod=%ld" - " AND brw_files.Path='%s'" - " AND brw_files.FilCod=mrk_marks.FilCod" - " ORDER BY brw_files.FilCod DESC" - " LIMIT 1", // On duplicate entries, get the more recent - Mrk_HeadOrFootStr[Brw_HEADER], - Mrk_HeadOrFootStr[Brw_FOOTER], - (unsigned) Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type], - Cod, - Gbl.FileBrowser.FilFolLnk.Full); - - /***** The result of the query must have only one row *****/ - if (NumRows == 1) + if (DB_QuerySELECT (&mysql_res,"can not get the number of rows" + " in header and footer", + "SELECT mrk_marks.%s," // row[0] + "mrk_marks.%s" // row[1] + " FROM brw_files," + "mrk_marks" + " WHERE brw_files.FileBrowser=%u" + " AND brw_files.Cod=%ld" + " AND brw_files.Path='%s'" + " AND brw_files.FilCod=mrk_marks.FilCod" + " ORDER BY brw_files.FilCod DESC" + " LIMIT 1", // On duplicate entries, get the more recent + Mrk_HeadOrFootStr[Brw_HEADER], + Mrk_HeadOrFootStr[Brw_FOOTER], + (unsigned) Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type], + Cod, + Gbl.FileBrowser.FilFolLnk.Full) == 1) { /***** Get number of header and footer rows *****/ row = mysql_fetch_row (mysql_res); diff --git a/swad_match.c b/swad_match.c index 26a7985c..27b8f295 100644 --- a/swad_match.c +++ b/swad_match.c @@ -404,7 +404,7 @@ void Mch_ListMatches (struct Gam_Games *Games, void Mch_GetDataOfMatchByCod (struct Mch_Match *Match) { MYSQL_RES *mysql_res; - unsigned long NumRows; + unsigned NumRows; /***** Get data of match from database *****/ NumRows = (unsigned) @@ -765,35 +765,36 @@ static void Mch_GetAndWriteNamesOfGrpsAssociatedToMatch (const struct Mch_Match extern const char *Txt_The_whole_course; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRow; - unsigned long NumRows; + unsigned NumGrps; + unsigned NumGrp; /***** Get groups associated to a match from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get groups of a match", - "SELECT grp_types.GrpTypName," // row[0] - "grp_groups.GrpName" // row[1] - " FROM mch_groups," - "grp_groups," - "grp_types" - " WHERE mch_groups.MchCod=%ld" - " AND mch_groups.GrpCod=grp_groups.GrpCod" - " AND grp_groups.GrpTypCod=grp_types.GrpTypCod" - " ORDER BY grp_types.GrpTypName," - "grp_groups.GrpName", - Match->MchCod); + NumGrps = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get groups of a match", + "SELECT grp_types.GrpTypName," // row[0] + "grp_groups.GrpName" // row[1] + " FROM mch_groups," + "grp_groups," + "grp_types" + " WHERE mch_groups.MchCod=%ld" + " AND mch_groups.GrpCod=grp_groups.GrpCod" + " AND grp_groups.GrpTypCod=grp_types.GrpTypCod" + " ORDER BY grp_types.GrpTypName," + "grp_groups.GrpName", + Match->MchCod); /***** Write heading *****/ HTM_DIV_Begin ("class=\"ASG_GRP\""); - HTM_TxtColonNBSP (NumRows == 1 ? Txt_Group : + HTM_TxtColonNBSP (NumGrps == 1 ? Txt_Group : Txt_Groups); /***** Write groups *****/ - if (NumRows) // Groups found... + if (NumGrps) // Groups found... { /* Get and write the group types and names */ - for (NumRow = 0; - NumRow < NumRows; - NumRow++) + for (NumGrp = 0; + NumGrp < NumGrps; + NumGrp++) { /* Get next group */ row = mysql_fetch_row (mysql_res); @@ -801,12 +802,12 @@ static void Mch_GetAndWriteNamesOfGrpsAssociatedToMatch (const struct Mch_Match /* Write group type name and group name */ HTM_TxtF ("%s %s",row[0],row[1]); - if (NumRows >= 2) + if (NumGrps >= 2) { - if (NumRow == NumRows-2) + if (NumGrp == NumGrps - 2) HTM_TxtF (" %s ",Txt_and); - if (NumRows >= 3) - if (NumRow < NumRows-2) + if (NumGrps >= 3) + if (NumGrp < NumGrps - 2) HTM_Txt (", "); } } @@ -1787,16 +1788,16 @@ static void Mch_CreateIndexes (long GamCod,long MchCod) /***** Get questions of the game *****/ NumQsts = (unsigned) - DB_QuerySELECT (&mysql_res,"can not get questions of a game", - "SELECT gam_questions.QstCod," // row[0] - "gam_questions.QstInd," // row[1] - "tst_questions.AnsType," // row[2] - "tst_questions.Shuffle" // row[3] - " FROM gam_questions,tst_questions" - " WHERE gam_questions.GamCod=%ld" - " AND gam_questions.QstCod=tst_questions.QstCod" - " ORDER BY gam_questions.QstInd", - GamCod); + DB_QuerySELECT (&mysql_res,"can not get questions of a game", + "SELECT gam_questions.QstCod," // row[0] + "gam_questions.QstInd," // row[1] + "tst_questions.AnsType," // row[2] + "tst_questions.Shuffle" // row[3] + " FROM gam_questions,tst_questions" + " WHERE gam_questions.GamCod=%ld" + " AND gam_questions.QstCod=tst_questions.QstCod" + " ORDER BY gam_questions.QstInd", + GamCod); /***** For each question in game... *****/ for (NumQst = 0; @@ -3511,14 +3512,14 @@ static void Mch_ShowMatchScore (const struct Mch_Match *Match) /***** Get scores from database *****/ NumScores = (unsigned) - DB_QuerySELECT (&mysql_res,"can not get scores", - "SELECT Score," // row[0] - "COUNT(*) AS NumUsrs" // row[1] - " FROM mch_results" - " WHERE MchCod=%ld" - " GROUP BY Score" - " ORDER BY Score DESC", - Match->MchCod); + DB_QuerySELECT (&mysql_res,"can not get scores", + "SELECT Score," // row[0] + "COUNT(*) AS NumUsrs" // row[1] + " FROM mch_results" + " WHERE MchCod=%ld" + " GROUP BY Score" + " ORDER BY Score DESC", + Match->MchCod); /***** Begin table ****/ HTM_TABLE_BeginWide (); diff --git a/swad_match_result.c b/swad_match_result.c index 48ea51d2..b038727a 100644 --- a/swad_match_result.c +++ b/swad_match_result.c @@ -393,30 +393,31 @@ void MchRes_ShowAllMchResultsInGam (void) static void MchRes_ListAllMchResultsInGam (struct Gam_Games *Games,long GamCod) { MYSQL_RES *mysql_res; - unsigned long NumUsrs; - unsigned long NumUsr; + unsigned NumUsrs; + unsigned NumUsr; /***** Table head *****/ MchRes_ShowHeaderMchResults (Usr_OTHER); /***** Get all users who have answered any match question in this game *****/ - NumUsrs = DB_QuerySELECT (&mysql_res,"can not get users in game", - "SELECT users.UsrCod" - " FROM (SELECT DISTINCT mch_results.UsrCod AS UsrCod" - " FROM mch_results," - "mch_matches," - "gam_games" - " WHERE mch_matches.GamCod=%ld" - " AND mch_matches.MchCod=mch_results.MchCod" - " AND mch_matches.GamCod=gam_games.GamCod" - " AND gam_games.CrsCod=%ld) AS users," // Extra check - "usr_data" - " WHERE users.UsrCod=usr_data.UsrCod" - " ORDER BY usr_data.Surname1," - "usr_data.Surname2," - "usr_data.FirstName", - GamCod, - Gbl.Hierarchy.Crs.CrsCod); + NumUsrs = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get users in game", + "SELECT users.UsrCod" + " FROM (SELECT DISTINCT mch_results.UsrCod AS UsrCod" + " FROM mch_results," + "mch_matches," + "gam_games" + " WHERE mch_matches.GamCod=%ld" + " AND mch_matches.MchCod=mch_results.MchCod" + " AND mch_matches.GamCod=gam_games.GamCod" + " AND gam_games.CrsCod=%ld) AS users," // Extra check + "usr_data" + " WHERE users.UsrCod=usr_data.UsrCod" + " ORDER BY usr_data.Surname1," + "usr_data.Surname2," + "usr_data.FirstName", + GamCod, + Gbl.Hierarchy.Crs.CrsCod); /***** List matches results for each user *****/ for (NumUsr = 0; @@ -482,30 +483,31 @@ void MchRes_ShowAllMchResultsInMch (void) static void MchRes_ListAllMchResultsInMch (struct Gam_Games *Games,long MchCod) { MYSQL_RES *mysql_res; - unsigned long NumUsrs; - unsigned long NumUsr; + unsigned NumUsrs; + unsigned NumUsr; /***** Table head *****/ MchRes_ShowHeaderMchResults (Usr_OTHER); /***** Get all users who have answered any match question in this game *****/ - NumUsrs = DB_QuerySELECT (&mysql_res,"can not get users in match", - "SELECT users.UsrCod" - " FROM (SELECT mch_results.UsrCod AS UsrCod" - " FROM mch_results," - "mch_matches," - "gam_games" - " WHERE mch_results.MchCod=%ld" - " AND mch_results.MchCod=mch_matches.MchCod" - " AND mch_matches.GamCod=gam_games.GamCod" - " AND gam_games.CrsCod=%ld) AS users," // Extra check - "usr_data" - " WHERE users.UsrCod=usr_data.UsrCod" - " ORDER BY usr_data.Surname1," - "usr_data.Surname2," - "usr_data.FirstName", - MchCod, - Gbl.Hierarchy.Crs.CrsCod); + NumUsrs = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get users in match", + "SELECT users.UsrCod" + " FROM (SELECT mch_results.UsrCod AS UsrCod" + " FROM mch_results," + "mch_matches," + "gam_games" + " WHERE mch_results.MchCod=%ld" + " AND mch_results.MchCod=mch_matches.MchCod" + " AND mch_matches.GamCod=gam_games.GamCod" + " AND gam_games.CrsCod=%ld) AS users," // Extra check + "usr_data" + " WHERE users.UsrCod=usr_data.UsrCod" + " ORDER BY usr_data.Surname1," + "usr_data.Surname2," + "usr_data.FirstName", + MchCod, + Gbl.Hierarchy.Crs.CrsCod); /***** List matches results for each user *****/ for (NumUsr = 0; diff --git a/swad_media.c b/swad_media.c index 22e24df2..1ca705f1 100644 --- a/swad_media.c +++ b/swad_media.c @@ -267,14 +267,15 @@ void Med_GetMediaDataByCod (struct Med_Media *Media) size_t Length; /***** Get data of a media from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get media", - "SELECT Type," // row[0] - "Name," // row[1] - "URL," // row[2] - "Title" // row[3] - " FROM med_media" - " WHERE MedCod=%ld", - Media->MedCod); + NumRows = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get media", + "SELECT Type," // row[0] + "Name," // row[1] + "URL," // row[2] + "Title" // row[3] + " FROM med_media" + " WHERE MedCod=%ld", + Media->MedCod); /***** Result should have a unique row *****/ if (NumRows == 0) // Media not found diff --git a/swad_message.c b/swad_message.c index c90bf0c7..27990598 100644 --- a/swad_message.c +++ b/swad_message.c @@ -116,7 +116,7 @@ static void Msg_ShowFormToShowOnlyUnreadMessages (const struct Msg_Messages *Mes static bool Msg_GetParamOnlyUnreadMsgs (void); static void Msg_ShowASentOrReceivedMessage (struct Msg_Messages *Messages, long MsgNum,long MsgCod); -static void Msg_GetStatusOfSentMsg (long MsgCod,bool *Expanded); +static bool Msg_GetStatusOfSentMsg (long MsgCod); static void Msg_GetStatusOfReceivedMsg (long MsgCod,bool *Open,bool *Replied,bool *Expanded); static long Msg_GetParamMsgCod (void); static void Msg_PutLinkToShowMorePotentialRecipients (const struct Msg_Messages *Messages); @@ -590,7 +590,6 @@ static void Msg_WriteFormSubjectAndContentMsgToUsrs (struct Msg_Messages *Messag extern const char *Txt_Original_message; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; long MsgCod; bool SubjectAndContentComeFromForm = (Messages->Subject[0] || Content[0]); @@ -614,15 +613,12 @@ static void Msg_WriteFormSubjectAndContentMsgToUsrs (struct Msg_Messages *Messag if (!SubjectAndContentComeFromForm) { /* Get subject and content of message from database */ - NumRows = DB_QuerySELECT (&mysql_res,"can not get message content", - "SELECT Subject," // row[0] - "Content" // row[1] - " FROM msg_content" - " WHERE MsgCod=%ld", - MsgCod); - - /* Result should have a unique row */ - if (NumRows != 1) + if (DB_QuerySELECT (&mysql_res,"can not get message content", + "SELECT Subject," // row[0] + "Content" // row[1] + " FROM msg_content" + " WHERE MsgCod=%ld", + MsgCod) != 1) Lay_ShowErrorAndExit ("Error when getting message."); row = mysql_fetch_row (mysql_res); @@ -2072,7 +2068,7 @@ static unsigned long Msg_GetSentOrReceivedMsgs (const struct Msg_Messages *Messa { char *SubQuery; const char *StrUnreadMsg; - unsigned long NumMsgs; + unsigned NumMsgs; if (Messages->FilterCrsCod > 0) // If origin course selected switch (Messages->TypeOfMessages) @@ -2244,21 +2240,23 @@ static unsigned long Msg_GetSentOrReceivedMsgs (const struct Msg_Messages *Messa if (Messages->FilterContent[0]) /* Match against the content written in filter form */ - NumMsgs = DB_QuerySELECT (mysql_res,"can not get messages", - "SELECT MsgCod" - " FROM msg_content" - " WHERE MsgCod IN" - " (SELECT MsgCod" - " FROM (%s) AS M)" - " AND MATCH (Subject,Content) AGAINST ('%s')" - " ORDER BY MsgCod DESC", // End the query ordering the result from most recent message to oldest - SubQuery, - Messages->FilterContent); + NumMsgs = (unsigned) + DB_QuerySELECT (mysql_res,"can not get messages", + "SELECT MsgCod" + " FROM msg_content" + " WHERE MsgCod IN" + " (SELECT MsgCod" + " FROM (%s) AS M)" + " AND MATCH (Subject,Content) AGAINST ('%s')" + " ORDER BY MsgCod DESC", // End the query ordering the result from most recent message to oldest + SubQuery, + Messages->FilterContent); else - NumMsgs = DB_QuerySELECT (mysql_res,"can not get messages", - "%s" - " ORDER BY MsgCod DESC", // End the query ordering the result from most recent message to oldest - SubQuery); + NumMsgs = (unsigned) + DB_QuerySELECT (mysql_res,"can not get messages", + "%s" + " ORDER BY MsgCod DESC", // End the query ordering the result from most recent message to oldest + SubQuery); /***** Free memory used for subquery *****/ free (SubQuery); @@ -2854,15 +2852,15 @@ static void Msg_GetDistinctCoursesInMyMessages (struct Msg_Messages *Messages) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRow; - unsigned long NumRows = 0; // Initialized to avoid warning + unsigned NumCrss = 0; // Initialized to avoid warning + unsigned NumCrs; struct Crs_Course Crs; /***** Get distinct courses in my messages from database *****/ switch (Messages->TypeOfMessages) { case Msg_RECEIVED: - NumRows = + NumCrss = (unsigned) DB_QuerySELECT (&mysql_res,"can not get distinct courses in your messages", "SELECT DISTINCT crs_courses.CrsCod," // row[0] "crs_courses.ShortName" // row[1] @@ -2876,7 +2874,7 @@ static void Msg_GetDistinctCoursesInMyMessages (struct Msg_Messages *Messages) Gbl.Usrs.Me.UsrDat.UsrCod); break; case Msg_SENT: - NumRows = + NumCrss = (unsigned) DB_QuerySELECT (&mysql_res,"can not get distinct courses in your messages", "SELECT DISTINCT crs_courses.CrsCod," // row[0] "crs_courses.ShortName" // row[1] @@ -2893,9 +2891,9 @@ static void Msg_GetDistinctCoursesInMyMessages (struct Msg_Messages *Messages) /***** Get distinct courses in messages from database *****/ Messages->NumCourses = 0; - for (NumRow = 0; - NumRow < NumRows; - NumRow++) + for (NumCrs = 0; + NumCrs < NumCrss; + NumCrs++) { /* Get next course */ row = mysql_fetch_row (mysql_res); @@ -3040,28 +3038,30 @@ static void Msg_GetMsgSntData (long MsgCod,long *CrsCod,long *UsrCod, { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; + unsigned NumRows; /***** Get data of message from table msg_snt *****/ *Deleted = false; - NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a message", - "SELECT CrsCod," // row[0] - "UsrCod," // row[1] - "UNIX_TIMESTAMP(CreatTime)" // row[2] - " FROM msg_snt" - " WHERE MsgCod=%ld", - MsgCod); + NumRows = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get data of a message", + "SELECT CrsCod," // row[0] + "UsrCod," // row[1] + "UNIX_TIMESTAMP(CreatTime)" // row[2] + " FROM msg_snt" + " WHERE MsgCod=%ld", + MsgCod); if (NumRows == 0) // If not result ==> sent message is deleted { /***** Get data of message from table msg_snt_deleted *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a message", - "SELECT CrsCod," // row[0] - "UsrCod," // row[1] - "UNIX_TIMESTAMP(CreatTime)" // row[2] - " FROM msg_snt_deleted" - " WHERE MsgCod=%ld", - MsgCod); + NumRows = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get data of a message", + "SELECT CrsCod," // row[0] + "UsrCod," // row[1] + "UNIX_TIMESTAMP(CreatTime)" // row[2] + " FROM msg_snt_deleted" + " WHERE MsgCod=%ld", + MsgCod); *Deleted = true; } @@ -3095,25 +3095,13 @@ static void Msg_GetMsgSntData (long MsgCod,long *CrsCod,long *UsrCod, static void Msg_GetMsgSubject (long MsgCod,char Subject[Cns_MAX_BYTES_SUBJECT + 1]) { - MYSQL_RES *mysql_res; - MYSQL_ROW row; - /***** Get subject of message from database *****/ - if (DB_QuerySELECT (&mysql_res,"can not get the subject of a message", - "SELECT Subject" // row[0] - " FROM msg_content" - " WHERE MsgCod=%ld", - MsgCod) == 1) // Result should have a unique row - { - /***** Get subject *****/ - row = mysql_fetch_row (mysql_res); - Str_Copy (Subject,row[0],Cns_MAX_BYTES_SUBJECT); - } - else - Subject[0] = '\0'; - - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); + DB_QuerySELECTString (Subject,Cns_MAX_BYTES_SUBJECT, + "can not get the subject of a message", + "SELECT Subject" // row[0] + " FROM msg_content" + " WHERE MsgCod=%ld", + MsgCod); } /*****************************************************************************/ @@ -3125,18 +3113,14 @@ static void Msg_GetMsgContent (long MsgCod,char Content[Cns_MAX_BYTES_LONG_TEXT { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; /***** Get content of message from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get the content of a message", + if (DB_QuerySELECT (&mysql_res,"can not get the content of a message", "SELECT Content," // row[0] "MedCod" // row[1] " FROM msg_content" " WHERE MsgCod=%ld", - MsgCod); - - /***** Result should have a unique row *****/ - if (NumRows != 1) + MsgCod) != 1) Lay_ShowErrorAndExit ("Error when getting content of a message."); /***** Get number of rows *****/ @@ -3157,60 +3141,44 @@ static void Msg_GetMsgContent (long MsgCod,char Content[Cns_MAX_BYTES_LONG_TEXT /********************** Get if a sent message is expanded ********************/ /*****************************************************************************/ -static void Msg_GetStatusOfSentMsg (long MsgCod,bool *Expanded) +static bool Msg_GetStatusOfSentMsg (long MsgCod) { - MYSQL_RES *mysql_res; - MYSQL_ROW row; - unsigned long NumRows; + char StrExpanded[1 + 1]; - /***** Get if sent message has been replied/expanded from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get if a sent message" - " has been replied/expanded", - "SELECT Expanded" // row[0] - " FROM msg_snt" - " WHERE MsgCod=%ld" - " AND UsrCod=%ld", - MsgCod, - Gbl.Usrs.Me.UsrDat.UsrCod); - - /***** Result should have a unique row *****/ - if (NumRows != 1) - Lay_ShowErrorAndExit ("Error when getting if a sent message has been replied/expanded."); - - /***** Get number of rows *****/ - row = mysql_fetch_row (mysql_res); + /***** Get if sent message has been expanded from database *****/ + DB_QuerySELECTString (StrExpanded,1, + "can not get if a sent message has been expanded", + "SELECT Expanded" // row[0] + " FROM msg_snt" + " WHERE MsgCod=%ld" + " AND UsrCod=%ld", + MsgCod, + Gbl.Usrs.Me.UsrDat.UsrCod); /***** Get if message is expanded *****/ - *Expanded = (row[0][0] == 'Y'); - - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); + return (StrExpanded[0] == 'Y'); } /*****************************************************************************/ -/***************** Get if a received message has been replied ****************/ +/********* Get if a received message has been open/replied/expanded **********/ /*****************************************************************************/ static void Msg_GetStatusOfReceivedMsg (long MsgCod,bool *Open,bool *Replied,bool *Expanded) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; - /***** Get if received message has been replied/expanded from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get if a received message" - " has been replied/expanded", - "SELECT Open," // row[0] - "Replied," // row[1] - "Expanded" // row[2] - " FROM msg_rcv" - " WHERE MsgCod=%ld" - " AND UsrCod=%ld", - MsgCod, - Gbl.Usrs.Me.UsrDat.UsrCod); - - /***** Result should have a unique row *****/ - if (NumRows != 1) + /***** Get if received message has been open/replied/expanded from database *****/ + if (DB_QuerySELECT (&mysql_res,"can not get if a received message" + " has been replied/expanded", + "SELECT Open," // row[0] + "Replied," // row[1] + "Expanded" // row[2] + " FROM msg_rcv" + " WHERE MsgCod=%ld" + " AND UsrCod=%ld", + MsgCod, + Gbl.Usrs.Me.UsrDat.UsrCod) != 1) Lay_ShowErrorAndExit ("Error when getting if a received message has been replied/expanded."); /***** Get number of rows *****/ @@ -3273,7 +3241,7 @@ static void Msg_ShowASentOrReceivedMessage (struct Msg_Messages *Messages, Msg_GetStatusOfReceivedMsg (MsgCod,&Open,&Replied,&Expanded); break; case Msg_SENT: - Msg_GetStatusOfSentMsg (MsgCod,&Expanded); + Expanded = Msg_GetStatusOfSentMsg (MsgCod); break; default: break; @@ -3781,34 +3749,34 @@ static void Msg_WriteMsgTo (struct Msg_Messages *Messages,long MsgCod) MsgCod); /***** Get recipients of a message from database *****/ - NumRecipientsKnown = - (unsigned) DB_QuerySELECT (&mysql_res,"can not get recipients of a message", - "(SELECT msg_rcv.UsrCod," // row[0] - "'N'," // row[1] - "msg_rcv.Open," // row[2] - "usr_data.Surname1 AS S1," // row[3] - "usr_data.Surname2 AS S2," // row[4] - "usr_data.FirstName AS FN" // row[5] - " FROM msg_rcv," - "usr_data" - " WHERE msg_rcv.MsgCod=%ld" - " AND msg_rcv.UsrCod=usr_data.UsrCod)" - " UNION " - "(SELECT msg_rcv_deleted.UsrCod," // row[0] - "'Y'," // row[1] - "msg_rcv_deleted.Open," // row[2] - "usr_data.Surname1 AS S1," // row[3] - "usr_data.Surname2 AS S2," // row[4] - "usr_data.FirstName AS FN" // row[5] - " FROM msg_rcv_deleted," - "usr_data" - " WHERE msg_rcv_deleted.MsgCod=%ld" - " AND msg_rcv_deleted.UsrCod=usr_data.UsrCod)" - " ORDER BY S1," - "S2," - "FN", - MsgCod, - MsgCod); + NumRecipientsKnown = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get recipients of a message", + "(SELECT msg_rcv.UsrCod," // row[0] + "'N'," // row[1] + "msg_rcv.Open," // row[2] + "usr_data.Surname1 AS S1," // row[3] + "usr_data.Surname2 AS S2," // row[4] + "usr_data.FirstName AS FN" // row[5] + " FROM msg_rcv," + "usr_data" + " WHERE msg_rcv.MsgCod=%ld" + " AND msg_rcv.UsrCod=usr_data.UsrCod)" + " UNION " + "(SELECT msg_rcv_deleted.UsrCod," // row[0] + "'Y'," // row[1] + "msg_rcv_deleted.Open," // row[2] + "usr_data.Surname1 AS S1," // row[3] + "usr_data.Surname2 AS S2," // row[4] + "usr_data.FirstName AS FN" // row[5] + " FROM msg_rcv_deleted," + "usr_data" + " WHERE msg_rcv_deleted.MsgCod=%ld" + " AND msg_rcv_deleted.UsrCod=usr_data.UsrCod)" + " ORDER BY S1," + "S2," + "FN", + MsgCod, + MsgCod); /***** Check number of recipients *****/ if (NumRecipientsTotal) diff --git a/swad_role.c b/swad_role.c index d32209bb..4cdb6d4b 100644 --- a/swad_role.c +++ b/swad_role.c @@ -435,28 +435,27 @@ void Rol_GetRolesInAllCrssIfNotYetGot (struct UsrData *UsrDat) unsigned NumRole; unsigned NumRoles; - /***** If roles is already filled ==> nothing to do *****/ - if (UsrDat->Roles.InCrss < 0) // Not yet filled - { - /***** Get distinct roles in all courses of the user from database *****/ - NumRoles = - (unsigned) DB_QuerySELECT (&mysql_res,"can not get the roles of a user" - " in all his/her courses", - "SELECT DISTINCT(Role)" // row[0] - " FROM crs_users" - " WHERE UsrCod=%ld", - UsrDat->UsrCod); - for (NumRole = 0, UsrDat->Roles.InCrss = 0; - NumRole < NumRoles; - NumRole++) - { - row = mysql_fetch_row (mysql_res); - UsrDat->Roles.InCrss |= (int) (1 << Rol_ConvertUnsignedStrToRole (row[0])); - } + /***** Trivial check: if already filled, nothing to do *****/ + if (UsrDat->Roles.InCrss >= 0) + return; - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); + /***** Get distinct roles in all courses of the user from database *****/ + NumRoles = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get user's roles in all courses", + "SELECT DISTINCT(Role)" // row[0] + " FROM crs_users" + " WHERE UsrCod=%ld", + UsrDat->UsrCod); + for (NumRole = 0, UsrDat->Roles.InCrss = 0; + NumRole < NumRoles; + NumRole++) + { + row = mysql_fetch_row (mysql_res); + UsrDat->Roles.InCrss |= (int) (1 << Rol_ConvertUnsignedStrToRole (row[0])); } + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); } /*****************************************************************************/ @@ -637,27 +636,14 @@ unsigned Rol_GetSelectedRoles (void) Rol_Role_t Rol_GetRequestedRole (long UsrCod) { - MYSQL_RES *mysql_res; - MYSQL_ROW row; - Rol_Role_t Role = Rol_UNK; - /***** Get requested role from database *****/ - if (DB_QuerySELECT (&mysql_res,"can not get requested role", - "SELECT Role" // row[0] - " FROM crs_requests" - " WHERE CrsCod=%ld" - " AND UsrCod=%ld", - Gbl.Hierarchy.Crs.CrsCod,UsrCod)) - { - /***** Get role *****/ - row = mysql_fetch_row (mysql_res); - Role = Rol_ConvertUnsignedStrToRole (row[0]); - } - - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); - - return Role; + return DB_QuerySELECTRole ("can not get requested role", + "SELECT Role" + " FROM crs_requests" + " WHERE CrsCod=%ld" + " AND UsrCod=%ld", + Gbl.Hierarchy.Crs.CrsCod, + UsrCod); } /*****************************************************************************/ diff --git a/swad_room.c b/swad_room.c index 01a7c3c9..244d5755 100644 --- a/swad_room.c +++ b/swad_room.c @@ -358,7 +358,7 @@ static unsigned Roo_GetMACAddresses (long RooCod,MYSQL_RES **mysql_res) { /***** Get MAC addresses from database *****/ return (unsigned) DB_QuerySELECT (mysql_res,"can not get MAC addresses", - "SELECT MAC" // row[0] + "SELECT MAC" // row[0] " FROM roo_macs" " WHERE RooCod=%ld" " ORDER BY MAC", diff --git a/swad_search.c b/swad_search.c index 161aa2fb..5b27592b 100644 --- a/swad_search.c +++ b/swad_search.c @@ -704,106 +704,115 @@ static unsigned Sch_SearchOpenDocumentsInDB (const char *RangeQuery) /***** Query database *****/ NumDocs = DB_QuerySELECT (&mysql_res,"can not get files", - "SELECT * FROM " - "(" - "SELECT brw_files.FilCod," // Institution - "SUBSTRING(brw_files.Path,LOCATE('/',brw_files.Path)) AS PathFromRoot," - "ins_instits.InsCod," - "ins_instits.ShortName AS InsShortName," - "-1 AS CtrCod," - "'' AS CtrShortName," - "-1 AS DegCod," - "'' AS DegShortName," - "-1 AS CrsCod," - "'' AS CrsShortName," - "-1 AS GrpCod" - " FROM brw_files," - "crs_courses," - "deg_degrees," - "ctr_centers," - "ins_instits," - "cty_countrs" - " WHERE brw_files.Public='Y'" - " AND %s" - " AND brw_files.FileBrowser IN (%u,%u)" - " AND brw_files.Cod=ins_instits.InsCod" - " AND ins_instits.CtyCod=cty_countrs.CtyCod" - "%s" - " UNION " - "SELECT brw_files.FilCod," // Center - "SUBSTRING(brw_files.Path,LOCATE('/',brw_files.Path)) AS PathFromRoot," - "ins_instits.InsCod," - "ins_instits.ShortName AS InsShortName," - "ctr_centers.CtrCod," - "ctr_centers.ShortName AS CtrShortName," - "-1 AS DegCod," - "'' AS DegShortName," - "-1 AS CrsCod," - "'' AS CrsShortName," - "-1 AS GrpCod" - " FROM brw_files," - "crs_courses," - "deg_degrees," - "ctr_centers," - "ins_instits," - "cty_countrs" - " WHERE brw_files.Public='Y' AND %s" - " AND brw_files.FileBrowser IN (%u,%u)" - " AND brw_files.Cod=ctr_centers.CtrCod" - " AND ctr_centers.InsCod=ins_instits.InsCod" - " AND ins_instits.CtyCod=cty_countrs.CtyCod" - "%s" - " UNION " - "SELECT brw_files.FilCod," // Degree - "SUBSTRING(brw_files.Path,LOCATE('/',brw_files.Path)) AS PathFromRoot," - "ins_instits.InsCod," - "ins_instits.ShortName AS InsShortName," - "ctr_centers.CtrCod," - "ctr_centers.ShortName AS CtrShortName," - "deg_degrees.DegCod," - "deg_degrees.ShortName AS DegShortName," - "-1,'' AS CrsShortName," - "-1" - " FROM brw_files," - "crs_courses," - "deg_degrees," - "ctr_centers," - "ins_instits," - "cty_countrs" - " WHERE brw_files.Public='Y' AND %s" - " AND brw_files.FileBrowser IN (%u,%u)" - " AND brw_files.Cod=deg_degrees.DegCod" - " AND deg_degrees.CtrCod=ctr_centers.CtrCod" - " AND ctr_centers.InsCod=ins_instits.InsCod" - " AND ins_instits.CtyCod=cty_countrs.CtyCod" - "%s" - " UNION " - "SELECT brw_files.FilCod," // Course - "SUBSTRING(brw_files.Path,LOCATE('/',brw_files.Path)) AS PathFromRoot," - "ins_instits.InsCod," - "ins_instits.ShortName AS InsShortName," - "ctr_centers.CtrCod," - "ctr_centers.ShortName AS CtrShortName," - "deg_degrees.DegCod," - "deg_degrees.ShortName AS DegShortName," - "crs_courses.CrsCod," - "crs_courses.ShortName AS CrsShortName," - "-1" - " FROM brw_files," - "crs_courses," - "deg_degrees," - "ctr_centers," - "ins_instits," - "cty_countrs" - " WHERE brw_files.Public='Y' AND %s" - " AND brw_files.FileBrowser IN (%u,%u)" - " AND brw_files.Cod=crs_courses.CrsCod" - " AND crs_courses.DegCod=deg_degrees.DegCod" - " AND deg_degrees.CtrCod=ctr_centers.CtrCod" - " AND ctr_centers.InsCod=ins_instits.InsCod" - " AND ins_instits.CtyCod=cty_countrs.CtyCod" - "%s" - ") AS selected_files" + "SELECT *" + " FROM " + // Institution + "(SELECT brw_files.FilCod," // row[ 0] + "SUBSTRING(brw_files.Path," + "LOCATE('/',brw_files.Path)) AS PathFromRoot," // row[ 1] + "ins_instits.InsCod," // row[ 2] + "ins_instits.ShortName AS InsShortName," // row[ 3] + "-1 AS CtrCod," // row[ 4] + "'' AS CtrShortName," // row[ 5] + "-1 AS DegCod," // row[ 6] + "'' AS DegShortName," // row[ 7] + "-1 AS CrsCod," // row[ 8] + "'' AS CrsShortName," // row[ 9] + "-1 AS GrpCod" // row[10] + " FROM brw_files," + "crs_courses," + "deg_degrees," + "ctr_centers," + "ins_instits," + "cty_countrs" + " WHERE brw_files.Public='Y'" + " AND %s" + " AND brw_files.FileBrowser IN (%u,%u)" + " AND brw_files.Cod=ins_instits.InsCod" + " AND ins_instits.CtyCod=cty_countrs.CtyCod" + "%s" + " UNION " + // Center ------------------------------------- + "SELECT brw_files.FilCod," // row[ 0] + "SUBSTRING(brw_files.Path," + "LOCATE('/',brw_files.Path)) AS PathFromRoot," // row[ 1] + "ins_instits.InsCod," // row[ 2] + "ins_instits.ShortName AS InsShortName," // row[ 3] + "ctr_centers.CtrCod," // row[ 4] + "ctr_centers.ShortName AS CtrShortName," // row[ 5] + "-1 AS DegCod," // row[ 6] + "'' AS DegShortName," // row[ 7] + "-1 AS CrsCod," // row[ 8] + "'' AS CrsShortName," // row[ 9] + "-1 AS GrpCod" // row[10] + " FROM brw_files," + "crs_courses," + "deg_degrees," + "ctr_centers," + "ins_instits," + "cty_countrs" + " WHERE brw_files.Public='Y' AND %s" + " AND brw_files.FileBrowser IN (%u,%u)" + " AND brw_files.Cod=ctr_centers.CtrCod" + " AND ctr_centers.InsCod=ins_instits.InsCod" + " AND ins_instits.CtyCod=cty_countrs.CtyCod" + "%s" + " UNION " + // Degree ------------------------------------- + "SELECT brw_files.FilCod," // row[ 0] + "SUBSTRING(brw_files.Path," + "LOCATE('/',brw_files.Path)) AS PathFromRoot," // row[ 1] + "ins_instits.InsCod," // row[ 2] + "ins_instits.ShortName AS InsShortName," // row[ 3] + "ctr_centers.CtrCod," // row[ 4] + "ctr_centers.ShortName AS CtrShortName," // row[ 5] + "deg_degrees.DegCod," // row[ 6] + "deg_degrees.ShortName AS DegShortName," // row[ 7] + "-1 AS CrsCod," // row[ 8] + "'' AS CrsShortName," // row[ 9] + "-1 AS GrpCod" // row[10] + " FROM brw_files," + "crs_courses," + "deg_degrees," + "ctr_centers," + "ins_instits," + "cty_countrs" + " WHERE brw_files.Public='Y' AND %s" + " AND brw_files.FileBrowser IN (%u,%u)" + " AND brw_files.Cod=deg_degrees.DegCod" + " AND deg_degrees.CtrCod=ctr_centers.CtrCod" + " AND ctr_centers.InsCod=ins_instits.InsCod" + " AND ins_instits.CtyCod=cty_countrs.CtyCod" + "%s" + " UNION " + // Course ------------------------------------- + "SELECT brw_files.FilCod," // row[ 0] + "SUBSTRING(brw_files.Path," + "LOCATE('/',brw_files.Path)) AS PathFromRoot," // row[ 1] + "ins_instits.InsCod," // row[ 2] + "ins_instits.ShortName AS InsShortName," // row[ 3] + "ctr_centers.CtrCod," // row[ 4] + "ctr_centers.ShortName AS CtrShortName," // row[ 5] + "deg_degrees.DegCod," // row[ 6] + "deg_degrees.ShortName AS DegShortName," // row[ 7] + "crs_courses.CrsCod," // row[ 8] + "crs_courses.ShortName AS CrsShortName," // row[ 9] + "-1 AS GrpCod" // row[10] + " FROM brw_files," + "crs_courses," + "deg_degrees," + "ctr_centers," + "ins_instits," + "cty_countrs" + " WHERE brw_files.Public='Y' AND %s" + " AND brw_files.FileBrowser IN (%u,%u)" + " AND brw_files.Cod=crs_courses.CrsCod" + " AND crs_courses.DegCod=deg_degrees.DegCod" + " AND deg_degrees.CtrCod=ctr_centers.CtrCod" + " AND ctr_centers.InsCod=ins_instits.InsCod" + " AND ins_instits.CtyCod=cty_countrs.CtyCod" + "%s" + ") AS selected_files" " WHERE PathFromRoot<>''" " ORDER BY InsShortName," "CtrShortName," @@ -859,11 +868,13 @@ static unsigned Sch_SearchDocumentsInMyCoursesInDB (const char *RangeQuery) /***** Create temporary table with codes of files in documents and shared areas accessible by me. It is necessary to speed up the second query *****/ DB_Query ("can not remove temporary table", - "DROP TEMPORARY TABLE IF EXISTS my_files_crs,my_files_grp"); + "DROP TEMPORARY TABLE IF EXISTS my_files_crs," + "my_files_grp"); DB_Query ("can not create temporary table", "CREATE TEMPORARY TABLE my_files_crs" - " (FilCod INT NOT NULL,UNIQUE INDEX(FilCod))" + " (FilCod INT NOT NULL," + "UNIQUE INDEX(FilCod))" " ENGINE=MEMORY" " SELECT brw_files.FilCod" " FROM crs_users," @@ -879,7 +890,8 @@ static unsigned Sch_SearchDocumentsInMyCoursesInDB (const char *RangeQuery) DB_Query ("can not create temporary table", "CREATE TEMPORARY TABLE my_files_grp" - " (FilCod INT NOT NULL,UNIQUE INDEX(FilCod))" + " (FilCod INT NOT NULL," + "UNIQUE INDEX(FilCod))" " ENGINE=MEMORY" " SELECT brw_files.FilCod" " FROM grp_users," @@ -896,70 +908,76 @@ static unsigned Sch_SearchDocumentsInMyCoursesInDB (const char *RangeQuery) /***** Build the query *****/ NumDocs = DB_QuerySELECT (&mysql_res,"can not get files", - "SELECT * FROM " - "(" - "SELECT brw_files.FilCod," - "SUBSTRING(brw_files.Path,LOCATE('/',brw_files.Path)) AS PathFromRoot," - "ins_instits.InsCod," - "ins_instits.ShortName AS InsShortName," - "ctr_centers.CtrCod," - "ctr_centers.ShortName AS CtrShortName," - "deg_degrees.DegCod," - "deg_degrees.ShortName AS DegShortName," - "crs_courses.CrsCod," - "crs_courses.ShortName AS CrsShortName," - "-1 AS GrpCod" - " FROM brw_files," - "crs_courses," - "deg_degrees," - "ctr_centers," - "ins_instits," - "cty_countrs" - " WHERE brw_files.FilCod IN" - " (SELECT FilCod" - " FROM my_files_crs)" - " AND %s" - " AND brw_files.FileBrowser IN (%u,%u,%u,%u)" - " AND brw_files.Cod=crs_courses.CrsCod" - " AND crs_courses.DegCod=deg_degrees.DegCod" - " AND deg_degrees.CtrCod=ctr_centers.CtrCod" - " AND ctr_centers.InsCod=ins_instits.InsCod" - " AND ins_instits.CtyCod=cty_countrs.CtyCod" - "%s" - " UNION " - "SELECT brw_files.FilCod," - "SUBSTRING(brw_files.Path,LOCATE('/',brw_files.Path)) AS PathFromRoot," - "ins_instits.InsCod," - "ins_instits.ShortName AS InsShortName," - "ctr_centers.CtrCod," - "ctr_centers.ShortName AS CtrShortName," - "deg_degrees.DegCod," - "deg_degrees.ShortName AS DegShortName," - "crs_courses.CrsCod," - "crs_courses.ShortName AS CrsShortName," - "grp_groups.GrpCod" - " FROM brw_files," - "grp_groups," - "grp_types," - "crs_courses," - "deg_degrees," - "ctr_centers," - "ins_instits," - "cty_countrs" - " WHERE brw_files.FilCod IN" - " (SELECT FilCod" - " FROM my_files_grp)" - " AND %s" - " AND brw_files.FileBrowser IN (%u,%u,%u,%u)" - " AND brw_files.Cod=grp_groups.GrpCod" - " AND grp_groups.GrpTypCod=grp_types.GrpTypCod" - " AND grp_types.CrsCod=crs_courses.CrsCod" - " AND crs_courses.DegCod=deg_degrees.DegCod" - " AND deg_degrees.CtrCod=ctr_centers.CtrCod" - " AND ctr_centers.InsCod=ins_instits.InsCod" - " AND ins_instits.CtyCod=cty_countrs.CtyCod" - "%s" - ") AS selected_files" + "SELECT *" + " FROM (" + // Files in course zones ---------------------- + "SELECT brw_files.FilCod," // row[ 0] + "SUBSTRING(brw_files.Path," + "LOCATE('/'," + "brw_files.Path)) AS PathFromRoot," // row[ 1] + "ins_instits.InsCod," // row[ 2] + "ins_instits.ShortName AS InsShortName," // row[ 3] + "ctr_centers.CtrCod," // row[ 4] + "ctr_centers.ShortName AS CtrShortName," // row[ 5] + "deg_degrees.DegCod," // row[ 6] + "deg_degrees.ShortName AS DegShortName," // row[ 7] + "crs_courses.CrsCod," // row[ 8] + "crs_courses.ShortName AS CrsShortName," // row[ 9] + "-1 AS GrpCod" // row[10] + " FROM brw_files," + "crs_courses," + "deg_degrees," + "ctr_centers," + "ins_instits," + "cty_countrs" + " WHERE brw_files.FilCod IN" + " (SELECT FilCod" + " FROM my_files_crs)" + " AND %s" + " AND brw_files.FileBrowser IN (%u,%u,%u,%u)" + " AND brw_files.Cod=crs_courses.CrsCod" + " AND crs_courses.DegCod=deg_degrees.DegCod" + " AND deg_degrees.CtrCod=ctr_centers.CtrCod" + " AND ctr_centers.InsCod=ins_instits.InsCod" + " AND ins_instits.CtyCod=cty_countrs.CtyCod" + "%s" + " UNION " + // Files in group zones ----------------------- + "SELECT brw_files.FilCod," // row[ 0] + "SUBSTRING(brw_files.Path," + "LOCATE('/'," + "brw_files.Path)) AS PathFromRoot," // row[ 1] + "ins_instits.InsCod," // row[ 2] + "ins_instits.ShortName AS InsShortName," // row[ 3] + "ctr_centers.CtrCod," // row[ 4] + "ctr_centers.ShortName AS CtrShortName," // row[ 5] + "deg_degrees.DegCod," // row[ 6] + "deg_degrees.ShortName AS DegShortName," // row[ 7] + "crs_courses.CrsCod," // row[ 8] + "crs_courses.ShortName AS CrsShortName," // row[ 9] + "grp_groups.GrpCod" // row[10] + " FROM brw_files," + "grp_groups," + "grp_types," + "crs_courses," + "deg_degrees," + "ctr_centers," + "ins_instits," + "cty_countrs" + " WHERE brw_files.FilCod IN" + " (SELECT FilCod" + " FROM my_files_grp)" + " AND %s" + " AND brw_files.FileBrowser IN (%u,%u,%u,%u)" + " AND brw_files.Cod=grp_groups.GrpCod" + " AND grp_groups.GrpTypCod=grp_types.GrpTypCod" + " AND grp_types.CrsCod=crs_courses.CrsCod" + " AND crs_courses.DegCod=deg_degrees.DegCod" + " AND deg_degrees.CtrCod=ctr_centers.CtrCod" + " AND ctr_centers.InsCod=ins_instits.InsCod" + " AND ins_instits.CtyCod=cty_countrs.CtyCod" + "%s" + ") AS selected_files" " WHERE PathFromRoot<>''" " ORDER BY InsShortName," "CtrShortName," @@ -986,7 +1004,8 @@ static unsigned Sch_SearchDocumentsInMyCoursesInDB (const char *RangeQuery) /***** Drop temporary table *****/ DB_Query ("can not remove temporary table", - "DROP TEMPORARY TABLE IF EXISTS my_files_crs,my_files_grp"); + "DROP TEMPORARY TABLE IF EXISTS my_files_crs," + "my_files_grp"); return (unsigned) NumDocs; } @@ -1015,156 +1034,174 @@ static unsigned Sch_SearchMyDocumentsInDB (const char *RangeQuery) /***** Build the query *****/ NumDocs = DB_QuerySELECT (&mysql_res,"can not get files", - "SELECT * FROM " - "(" - "SELECT brw_files.FilCod," // Institution - "SUBSTRING(brw_files.Path,LOCATE('/',brw_files.Path)) AS PathFromRoot," - "ins_instits.InsCod," - "ins_instits.ShortName AS InsShortName," - "-1 AS CtrCod," - "'' AS CtrShortName," - "-1 AS DegCod," - "'' AS DegShortName," - "-1 AS CrsCod," - "'' AS CrsShortName," - "-1 AS GrpCod" - " FROM brw_files," - "crs_courses," - "deg_degrees," - "ctr_centers," - "ins_instits," - "cty_countrs" - " WHERE brw_files.PublisherUsrCod=%ld" - " AND %s" - " AND brw_files.FileBrowser IN (%u,%u)" - " AND brw_files.Cod=ins_instits.InsCod" - " AND ins_instits.CtyCod=cty_countrs.CtyCod" - "%s" - " UNION " - "SELECT brw_files.FilCod," // Center - "SUBSTRING(brw_files.Path,LOCATE('/',brw_files.Path)) AS PathFromRoot," - "ins_instits.InsCod," - "ins_instits.ShortName AS InsShortName," - "ctr_centers.CtrCod," - "ctr_centers.ShortName AS CtrShortName," - "-1 AS DegCod," - "'' AS DegShortName," - "-1 AS CrsCod," - "'' AS CrsShortName," - "-1 AS GrpCod" - " FROM brw_files," - "crs_courses," - "deg_degrees," - "ctr_centers," - "ins_instits," - "cty_countrs" - " WHERE brw_files.PublisherUsrCod=%ld AND %s" - " AND brw_files.FileBrowser IN (%u,%u)" - " AND brw_files.Cod=ctr_centers.CtrCod" - " AND ctr_centers.InsCod=ins_instits.InsCod" - " AND ins_instits.CtyCod=cty_countrs.CtyCod" - "%s" - " UNION " - "SELECT brw_files.FilCod," // Degree - "SUBSTRING(brw_files.Path,LOCATE('/',brw_files.Path)) AS PathFromRoot," - "ins_instits.InsCod," - "ins_instits.ShortName AS InsShortName," - "ctr_centers.CtrCod," - "ctr_centers.ShortName AS CtrShortName," - "deg_degrees.DegCod," - "deg_degrees.ShortName AS DegShortName," - "-1 AS CrsCod," - "'' AS CrsShortName," - "-1 AS GrpCod" - " FROM brw_files," - "crs_courses," - "deg_degrees," - "ctr_centers," - "ins_instits," - "cty_countrs" - " WHERE brw_files.PublisherUsrCod=%ld" - " AND %s" - " AND brw_files.FileBrowser IN (%u,%u)" - " AND brw_files.Cod=deg_degrees.DegCod" - " AND deg_degrees.CtrCod=ctr_centers.CtrCod" - " AND ctr_centers.InsCod=ins_instits.InsCod" - " AND ins_instits.CtyCod=cty_countrs.CtyCod" - "%s" - " UNION " - "SELECT brw_files.FilCod," // Course - "SUBSTRING(brw_files.Path,LOCATE('/',brw_files.Path)) AS PathFromRoot," - "ins_instits.InsCod," - "ins_instits.ShortName AS InsShortName," - "ctr_centers.CtrCod," - "ctr_centers.ShortName AS CtrShortName," - "deg_degrees.DegCod," - "deg_degrees.ShortName AS DegShortName," - "crs_courses.CrsCod," - "crs_courses.ShortName AS CrsShortName," - "-1 AS GrpCod" - " FROM brw_files," - "crs_courses," - "deg_degrees," - "ctr_centers," - "ins_instits," - "cty_countrs" - " WHERE brw_files.PublisherUsrCod=%ld" - " AND %s" - " AND brw_files.FileBrowser IN (%u,%u,%u,%u)" - " AND brw_files.Cod=crs_courses.CrsCod" - " AND crs_courses.DegCod=deg_degrees.DegCod" - " AND deg_degrees.CtrCod=ctr_centers.CtrCod" - " AND ctr_centers.InsCod=ins_instits.InsCod" - " AND ins_instits.CtyCod=cty_countrs.CtyCod" - "%s" - " UNION " - "SELECT brw_files.FilCod," // Group - "SUBSTRING(brw_files.Path,LOCATE('/',brw_files.Path)) AS PathFromRoot," - "ins_instits.InsCod," - "ins_instits.ShortName AS InsShortName," - "ctr_centers.CtrCod," - "ctr_centers.ShortName AS CtrShortName," - "deg_degrees.DegCod," - "deg_degrees.ShortName AS DegShortName," - "crs_courses.CrsCod," - "crs_courses.ShortName AS CrsShortName," - "grp_groups.GrpCod" - " FROM brw_files," - "grp_groups," - "grp_types," - "crs_courses," - "deg_degrees," - "ctr_centers," - "ins_instits," - "cty_countrs" - " WHERE brw_files.PublisherUsrCod=%ld" - " AND %s" - " AND brw_files.FileBrowser IN (%u,%u,%u,%u)" - " AND brw_files.Cod=grp_groups.GrpCod" - " AND grp_groups.GrpTypCod=grp_types.GrpTypCod" - " AND grp_types.CrsCod=crs_courses.CrsCod" - " AND crs_courses.DegCod=deg_degrees.DegCod" - " AND deg_degrees.CtrCod=ctr_centers.CtrCod" - " AND ctr_centers.InsCod=ins_instits.InsCod" - " AND ins_instits.CtyCod=cty_countrs.CtyCod" - "%s" - " UNION " - "SELECT brw_files.FilCod," // Briefcase - "SUBSTRING(brw_files.Path,LOCATE('/',brw_files.Path)) AS PathFromRoot," - "-1 AS InsCod," - "'' AS InsShortName," - "-1 AS CtrCod," - "'' AS CtrShortName," - "-1 AS DegCod," - "'' AS DegShortName," - "-1 AS CrsCod," - "'' AS CrsShortName," - "-1 AS GrpCod" - " FROM brw_files" - " WHERE brw_files.PublisherUsrCod=%ld" - " AND %s" - " AND brw_files.FileBrowser=%u" - ") AS selected_files" + "SELECT *" + " FROM (" + // Institution -------------------------------- + "SELECT brw_files.FilCod," // row[ 0] + "SUBSTRING(brw_files.Path," + "LOCATE('/'," + "brw_files.Path)) AS PathFromRoot," // row[ 1] + "ins_instits.InsCod," // row[ 2] + "ins_instits.ShortName AS InsShortName," // row[ 3] + "-1 AS CtrCod," // row[ 4] + "'' AS CtrShortName," // row[ 5] + "-1 AS DegCod," // row[ 6] + "'' AS DegShortName," // row[ 7] + "-1 AS CrsCod," // row[ 8] + "'' AS CrsShortName," // row[ 9] + "-1 AS GrpCod" // row[10] + " FROM brw_files," + "crs_courses," + "deg_degrees," + "ctr_centers," + "ins_instits," + "cty_countrs" + " WHERE brw_files.PublisherUsrCod=%ld" + " AND %s" + " AND brw_files.FileBrowser IN (%u,%u)" + " AND brw_files.Cod=ins_instits.InsCod" + " AND ins_instits.CtyCod=cty_countrs.CtyCod" + "%s" + " UNION " + // Center ------------------------------------- + "SELECT brw_files.FilCod," // row[ 0] + "SUBSTRING(brw_files.Path," + "LOCATE('/'," + "brw_files.Path)) AS PathFromRoot," // row[ 1] + "ins_instits.InsCod," // row[ 2] + "ins_instits.ShortName AS InsShortName," // row[ 3] + "ctr_centers.CtrCod," // row[ 4] + "ctr_centers.ShortName AS CtrShortName," // row[ 5] + "-1 AS DegCod," // row[ 6] + "'' AS DegShortName," // row[ 7] + "-1 AS CrsCod," // row[ 8] + "'' AS CrsShortName," // row[ 9] + "-1 AS GrpCod" // row[10] + " FROM brw_files," + "crs_courses," + "deg_degrees," + "ctr_centers," + "ins_instits," + "cty_countrs" + " WHERE brw_files.PublisherUsrCod=%ld AND %s" + " AND brw_files.FileBrowser IN (%u,%u)" + " AND brw_files.Cod=ctr_centers.CtrCod" + " AND ctr_centers.InsCod=ins_instits.InsCod" + " AND ins_instits.CtyCod=cty_countrs.CtyCod" + "%s" + " UNION " + // Degree ------------------------------------- + "SELECT brw_files.FilCod," // row[ 0] + "SUBSTRING(brw_files.Path," + "LOCATE('/'," + "brw_files.Path)) AS PathFromRoot," // row[ 1] + "ins_instits.InsCod," // row[ 2] + "ins_instits.ShortName AS InsShortName," // row[ 3] + "ctr_centers.CtrCod," // row[ 4] + "ctr_centers.ShortName AS CtrShortName," // row[ 5] + "deg_degrees.DegCod," // row[ 6] + "deg_degrees.ShortName AS DegShortName," // row[ 7] + "-1 AS CrsCod," // row[ 8] + "'' AS CrsShortName," // row[ 9] + "-1 AS GrpCod" // row[10] + " FROM brw_files," + "crs_courses," + "deg_degrees," + "ctr_centers," + "ins_instits," + "cty_countrs" + " WHERE brw_files.PublisherUsrCod=%ld" + " AND %s" + " AND brw_files.FileBrowser IN (%u,%u)" + " AND brw_files.Cod=deg_degrees.DegCod" + " AND deg_degrees.CtrCod=ctr_centers.CtrCod" + " AND ctr_centers.InsCod=ins_instits.InsCod" + " AND ins_instits.CtyCod=cty_countrs.CtyCod" + "%s" + " UNION " + // Course ------------------------------------- + "SELECT brw_files.FilCod," // row[ 0] + "SUBSTRING(brw_files.Path," + "LOCATE('/'," + "brw_files.Path)) AS PathFromRoot," // row[ 1] + "ins_instits.InsCod," // row[ 2] + "ins_instits.ShortName AS InsShortName," // row[ 3] + "ctr_centers.CtrCod," // row[ 4] + "ctr_centers.ShortName AS CtrShortName," // row[ 5] + "deg_degrees.DegCod," // row[ 6] + "deg_degrees.ShortName AS DegShortName," // row[ 7] + "crs_courses.CrsCod," // row[ 8] + "crs_courses.ShortName AS CrsShortName," // row[ 9] + "-1 AS GrpCod" // row[10] + " FROM brw_files," + "crs_courses," + "deg_degrees," + "ctr_centers," + "ins_instits," + "cty_countrs" + " WHERE brw_files.PublisherUsrCod=%ld" + " AND %s" + " AND brw_files.FileBrowser IN (%u,%u,%u,%u)" + " AND brw_files.Cod=crs_courses.CrsCod" + " AND crs_courses.DegCod=deg_degrees.DegCod" + " AND deg_degrees.CtrCod=ctr_centers.CtrCod" + " AND ctr_centers.InsCod=ins_instits.InsCod" + " AND ins_instits.CtyCod=cty_countrs.CtyCod" + "%s" + " UNION " + // Group -------------------------------------- + "SELECT brw_files.FilCod," // row[ 0] + "SUBSTRING(brw_files.Path," + "LOCATE('/'," + "brw_files.Path)) AS PathFromRoot," // row[ 1] + "ins_instits.InsCod," // row[ 2] + "ins_instits.ShortName AS InsShortName," // row[ 3] + "ctr_centers.CtrCod," // row[ 4] + "ctr_centers.ShortName AS CtrShortName," // row[ 5] + "deg_degrees.DegCod," // row[ 6] + "deg_degrees.ShortName AS DegShortName," // row[ 7] + "crs_courses.CrsCod," // row[ 8] + "crs_courses.ShortName AS CrsShortName," // row[ 9] + "grp_groups.GrpCod" // row[10] + " FROM brw_files," + "grp_groups," + "grp_types," + "crs_courses," + "deg_degrees," + "ctr_centers," + "ins_instits," + "cty_countrs" + " WHERE brw_files.PublisherUsrCod=%ld" + " AND %s" + " AND brw_files.FileBrowser IN (%u,%u,%u,%u)" + " AND brw_files.Cod=grp_groups.GrpCod" + " AND grp_groups.GrpTypCod=grp_types.GrpTypCod" + " AND grp_types.CrsCod=crs_courses.CrsCod" + " AND crs_courses.DegCod=deg_degrees.DegCod" + " AND deg_degrees.CtrCod=ctr_centers.CtrCod" + " AND ctr_centers.InsCod=ins_instits.InsCod" + " AND ins_instits.CtyCod=cty_countrs.CtyCod" + "%s" + " UNION " + // Briefcase ---------------------------------- + "SELECT brw_files.FilCod," // row[ 0] + "SUBSTRING(brw_files.Path," + "LOCATE('/'," + "brw_files.Path)) AS PathFromRoot," // row[ 1] + "-1 AS InsCod," // row[ 2] + "'' AS InsShortName," // row[ 3] + "-1 AS CtrCod," // row[ 4] + "'' AS CtrShortName," // row[ 5] + "-1 AS DegCod," // row[ 6] + "'' AS DegShortName," // row[ 7] + "-1 AS CrsCod," // row[ 8] + "'' AS CrsShortName," // row[ 9] + "-1 AS GrpCod" // row[10] + " FROM brw_files" + " WHERE brw_files.PublisherUsrCod=%ld" + " AND %s" + " AND brw_files.FileBrowser=%u" + ") AS selected_files" " WHERE PathFromRoot<>''" " ORDER BY InsShortName," "CtrShortName," diff --git a/swad_session.c b/swad_session.c index 1a48310b..2fc86037 100644 --- a/swad_session.c +++ b/swad_session.c @@ -423,50 +423,20 @@ static bool Ses_CheckIfParamIsAlreadyInDB (const char *ParamName) /*****************************************************************************/ /***************** Get session parameter from the database *******************/ /*****************************************************************************/ +// StrSize is the size of the parameter value, not including the ending '\0' -void Ses_GetParamFromDB (const char *ParamName,char *ParamValue,size_t MaxBytes) +void Ses_GetParamFromDB (const char *ParamName,char *ParamValue,size_t StrSize) { - MYSQL_RES *mysql_res; - MYSQL_ROW row; - unsigned long NumRows; - bool ParameterIsTooBig = false; - char ErrorTxt[256]; - ParamValue[0] = '\0'; if (Gbl.Session.IsOpen) // If the session is open, get parameter from DB - { /***** Get a session parameter from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get a session parameter", - "SELECT ParamValue" // row[0] - " FROM ses_params" - " WHERE SessionId='%s'" - " AND ParamName='%s'", - Gbl.Session.Id, - ParamName); - - /***** Check if the parameter is found in database *****/ - if (NumRows) - { - /***** Get the value del parameter *****/ - row = mysql_fetch_row (mysql_res); - - ParameterIsTooBig = (strlen (row[0]) > MaxBytes); - if (!ParameterIsTooBig) - Str_Copy (ParamValue,row[0],MaxBytes); - } - - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); - } - - if (ParameterIsTooBig) - { - snprintf (ErrorTxt,sizeof (ErrorTxt), - "Session parameter %s too large," - " it exceed the maximum allowed size (%lu bytes).", - ParamName,(unsigned long) MaxBytes); - Lay_ShowErrorAndExit (ErrorTxt); - } + DB_QuerySELECTString (ParamValue,StrSize,"can not get a session parameter", + "SELECT ParamValue" // row[0] + " FROM ses_params" + " WHERE SessionId='%s'" + " AND ParamName='%s'", + Gbl.Session.Id, + ParamName); } /*****************************************************************************/ diff --git a/swad_session.h b/swad_session.h index bff63364..d581fa4b 100644 --- a/swad_session.h +++ b/swad_session.h @@ -50,7 +50,7 @@ bool Ses_GetSessionData (void); void Ses_InsertParamInDB (const char *ParamName,const char *ParamValue); void Ses_RemoveParamFromThisSession (void); void Ses_RemoveParamsFromExpiredSessions (void); -void Ses_GetParamFromDB (const char *ParamName,char *ParamValue,size_t MaxBytes); +void Ses_GetParamFromDB (const char *ParamName,char *ParamValue,size_t StrSize); bool Ses_GetPublicDirFromCache (const char *FullPathMediaPriv, char TmpPubDir[PATH_MAX + 1]); diff --git a/swad_statistic.c b/swad_statistic.c index 785b8ac6..0110b7e1 100644 --- a/swad_statistic.c +++ b/swad_statistic.c @@ -1784,23 +1784,19 @@ static void Sta_ShowDetailedAccessesList (const struct Sta_Stats *Stats, static void Sta_WriteLogComments (long LogCod) { - MYSQL_RES *mysql_res; - MYSQL_ROW row; + char Comments[Cns_MAX_BYTES_TEXT + 1]; /***** Get log comments from database *****/ - if (DB_QuerySELECT (&mysql_res,"can not get log comments", - "SELECT Comments" // row[0] - " FROM log_comments" - " WHERE LogCod=%ld", - LogCod)) - { - /***** Get and write comments *****/ - row = mysql_fetch_row (mysql_res); - HTM_Txt (row[0]); - } + DB_QuerySELECTString (Comments,sizeof (Comments) - 1, + "can not get log comments", + "SELECT Comments" + " FROM log_comments" + " WHERE LogCod=%ld", + LogCod); - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); + /***** Write comments *****/ + if (Comments[0]) + HTM_Txt (Comments); } /*****************************************************************************/ diff --git a/swad_survey.c b/swad_survey.c index 76e1ce46..2e4e9441 100644 --- a/swad_survey.c +++ b/swad_survey.c @@ -3187,37 +3187,17 @@ void Svy_ReceiveQst (void) } /*****************************************************************************/ -/******************* Get next question index in a survey *********************/ +/************ Get question index from question code in a survey **************/ /*****************************************************************************/ static unsigned Svy_GetQstIndFromQstCod (long QstCod) { - MYSQL_RES *mysql_res; - MYSQL_ROW row; - unsigned long NumRows; - unsigned QstInd = 0; - - /***** Get number of surveys with a field value from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get question index", - "SELECT QstInd" // row[0] - " FROM svy_questions" - " WHERE QstCod=%ld", - QstCod); - - /***** Get number of users *****/ - if (NumRows) - { - row = mysql_fetch_row (mysql_res); - if (sscanf (row[0],"%u",&QstInd) != 1) - Lay_ShowErrorAndExit ("Error when getting question index."); - } - else - Lay_ShowErrorAndExit ("Error when getting question index."); - - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); - - return QstInd; + /***** Get question index from database *****/ + return DB_QuerySELECTUnsigned ("can not get question index", + "SELECT QstInd" + " FROM svy_questions" + " WHERE QstCod=%ld", + QstCod); } /*****************************************************************************/ diff --git a/swad_system_config.c b/swad_system_config.c index 05ac2d87..60bf9c5f 100644 --- a/swad_system_config.c +++ b/swad_system_config.c @@ -254,7 +254,7 @@ static void SysCfg_Map (void) /* Get centers with coordinates */ NumCtrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get centers with coordinates", - "SELECT CtrCod" // row[0] + "SELECT CtrCod" " FROM ctr_centers" " WHERE ctr_centers.Latitude<>0" " AND ctr_centers.Longitude<>0"); diff --git a/swad_test.c b/swad_test.c index 2097f67e..20d22cd1 100644 --- a/swad_test.c +++ b/swad_test.c @@ -1355,15 +1355,16 @@ bool Tst_CheckIfCourseHaveTestsAndPluggableIsUnknown (void) extern const char *TstCfg_PluggableDB[TstCfg_NUM_OPTIONS_PLUGGABLE]; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; + unsigned NumRows; TstCfg_Pluggable_t Pluggable; /***** Get pluggability of tests for current course from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get configuration of test", - "SELECT Pluggable" // row[0] - " FROM tst_config" - " WHERE CrsCod=%ld", - Gbl.Hierarchy.Crs.CrsCod); + NumRows = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get configuration of test", + "SELECT Pluggable" // row[0] + " FROM tst_config" + " WHERE CrsCod=%ld", + Gbl.Hierarchy.Crs.CrsCod); if (NumRows == 0) TstCfg_SetConfigPluggable (TstCfg_PLUGGABLE_UNKNOWN); @@ -2908,18 +2909,20 @@ void Tst_CheckIfNumberOfAnswersIsOne (const struct Tst_Question *Question) /************************* Get tags of a test question ***********************/ /*****************************************************************************/ -unsigned long Tst_GetTagsQst (long QstCod,MYSQL_RES **mysql_res) +unsigned Tst_GetTagsQst (long QstCod,MYSQL_RES **mysql_res) { /***** Get the tags of a question from database *****/ - return DB_QuerySELECT (mysql_res,"can not get the tags of a question", - "SELECT tst_tags.TagTxt" // row[0] - " FROM tst_question_tags," - "tst_tags" - " WHERE tst_question_tags.QstCod=%ld" - " AND tst_question_tags.TagCod=tst_tags.TagCod" - " AND tst_tags.CrsCod=%ld" - " ORDER BY tst_question_tags.TagInd", - QstCod,Gbl.Hierarchy.Crs.CrsCod); + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get the tags of a question", + "SELECT tst_tags.TagTxt" // row[0] + " FROM tst_question_tags," + "tst_tags" + " WHERE tst_question_tags.QstCod=%ld" + " AND tst_question_tags.TagCod=tst_tags.TagCod" + " AND tst_tags.CrsCod=%ld" + " ORDER BY tst_question_tags.TagInd", + QstCod, + Gbl.Hierarchy.Crs.CrsCod); } /*****************************************************************************/ @@ -2929,18 +2932,18 @@ unsigned long Tst_GetTagsQst (long QstCod,MYSQL_RES **mysql_res) void Tst_GetAndWriteTagsQst (long QstCod) { extern const char *Txt_no_tags; - unsigned long NumRow; - unsigned long NumRows; + unsigned NumTags; + unsigned NumTag; MYSQL_RES *mysql_res; MYSQL_ROW row; - if ((NumRows = Tst_GetTagsQst (QstCod,&mysql_res))) + if ((NumTags = Tst_GetTagsQst (QstCod,&mysql_res))) { /***** Write the tags *****/ HTM_UL_Begin ("class=\"TEST_TAG_LIST DAT_SMALL\""); - for (NumRow = 0; - NumRow < NumRows; - NumRow++) + for (NumTag = 0; + NumTag < NumTags; + NumTag++) { row = mysql_fetch_row (mysql_res); HTM_LI_Begin (NULL); @@ -3813,26 +3816,16 @@ static void Tst_FreeMediaOfQuestion (struct Tst_Question *Question) Tst_AnswerType_t Tst_GetQstAnswerTypeFromDB (long QstCod) { - MYSQL_RES *mysql_res; - MYSQL_ROW row; - Tst_AnswerType_t AnswerType; + char StrAnsTypeDB[256]; /***** Get type of answer from database *****/ - if (!DB_QuerySELECT (&mysql_res,"can not get the type of a question", - "SELECT AnsType" // row[0] - " FROM tst_questions" - " WHERE QstCod=%ld", - QstCod)) - Lay_ShowErrorAndExit ("Question does not exist."); - - /* Get type of answer */ - row = mysql_fetch_row (mysql_res); - AnswerType = Tst_ConvertFromStrAnsTypDBToAnsTyp (row[0]); - - /* Free structure that stores the query result */ - DB_FreeMySQLResult (&mysql_res); - - return AnswerType; + DB_QuerySELECTString (StrAnsTypeDB,sizeof (StrAnsTypeDB) - 1, + "can not get the type of a question", + "SELECT AnsType" + " FROM tst_questions" + " WHERE QstCod=%ld", + QstCod); + return Tst_ConvertFromStrAnsTypDBToAnsTyp (StrAnsTypeDB); } /*****************************************************************************/ @@ -3844,8 +3837,8 @@ bool Tst_GetQstDataFromDB (struct Tst_Question *Question) MYSQL_RES *mysql_res; MYSQL_ROW row; bool QuestionExists; - unsigned long NumRows; - unsigned long NumRow; + unsigned NumTags; + unsigned NumTag; unsigned NumOpt; /***** Get question data from database *****/ @@ -3914,14 +3907,14 @@ bool Tst_GetQstDataFromDB (struct Tst_Question *Question) DB_FreeMySQLResult (&mysql_res); /***** Get the tags from the database *****/ - NumRows = Tst_GetTagsQst (Question->QstCod,&mysql_res); - for (NumRow = 0; - NumRow < NumRows; - NumRow++) + NumTags = Tst_GetTagsQst (Question->QstCod,&mysql_res); + for (NumTag = 0; + NumTag < NumTags; + NumTag++) { row = mysql_fetch_row (mysql_res); - Str_Copy (Question->Tags.Txt[NumRow],row[0], - sizeof (Question->Tags.Txt[NumRow]) - 1); + Str_Copy (Question->Tags.Txt[NumTag],row[0], + sizeof (Question->Tags.Txt[NumTag]) - 1); } /* Free structure that stores the query result */ @@ -4049,16 +4042,17 @@ static void Tst_GetMediaFromDB (long CrsCod,long QstCod,int NumOpt, /** Convert a string with the type of answer in database to type of answer ***/ /*****************************************************************************/ -Tst_AnswerType_t Tst_ConvertFromStrAnsTypDBToAnsTyp (const char *StrAnsTypeBD) +Tst_AnswerType_t Tst_ConvertFromStrAnsTypDBToAnsTyp (const char *StrAnsTypeDB) { Tst_AnswerType_t AnsType; - if (StrAnsTypeBD != NULL) - for (AnsType = (Tst_AnswerType_t) 0; - AnsType <= (Tst_AnswerType_t) (Tst_NUM_ANS_TYPES - 1); - AnsType++) - if (!strcmp (StrAnsTypeBD,Tst_StrAnswerTypesDB[AnsType])) - return AnsType; + if (StrAnsTypeDB != NULL) + if (StrAnsTypeDB[0]) + for (AnsType = (Tst_AnswerType_t) 0; + AnsType <= (Tst_AnswerType_t) (Tst_NUM_ANS_TYPES - 1); + AnsType++) + if (!strcmp (StrAnsTypeDB,Tst_StrAnswerTypesDB[AnsType])) + return AnsType; return Tst_ANS_UNKNOWN; } @@ -5223,18 +5217,18 @@ static void Tst_RemoveMediaFromAllAnsOfQst (long CrsCod,long QstCod) unsigned NumMedia; /***** Get media codes associated to answers of test questions from database *****/ - NumMedia = - (unsigned) DB_QuerySELECT (&mysql_res,"can not get media", - "SELECT tst_answers.MedCod" // row[0] - " FROM tst_answers," - "tst_questions" - " WHERE tst_answers.QstCod=%ld" - " AND tst_answers.QstCod=tst_questions.QstCod" - " AND tst_questions.CrsCod=%ld" // Extra check - " AND tst_questions.QstCod=%ld", // Extra check - QstCod, - CrsCod, - QstCod); + NumMedia = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get media", + "SELECT tst_answers.MedCod" + " FROM tst_answers," + "tst_questions" + " WHERE tst_answers.QstCod=%ld" + " AND tst_answers.QstCod=tst_questions.QstCod" + " AND tst_questions.CrsCod=%ld" // Extra check + " AND tst_questions.QstCod=%ld", // Extra check + QstCod, + CrsCod, + QstCod); /***** Go over result removing media *****/ Med_RemoveMediaFromAllRows (NumMedia,mysql_res); @@ -5277,14 +5271,14 @@ static void Tst_RemoveAllMedFilesFromAnsOfAllQstsInCrs (long CrsCod) unsigned NumMedia; /***** Get names of media files associated to answers of test questions from database *****/ - NumMedia = - (unsigned) DB_QuerySELECT (&mysql_res,"can not get media", - "SELECT tst_answers.MedCod" // row[0] - " FROM tst_questions," - "tst_answers" - " WHERE tst_questions.CrsCod=%ld" - " AND tst_questions.QstCod=tst_answers.QstCod", - CrsCod); + NumMedia = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get media", + "SELECT tst_answers.MedCod" + " FROM tst_questions," + "tst_answers" + " WHERE tst_questions.CrsCod=%ld" + " AND tst_questions.QstCod=tst_answers.QstCod", + CrsCod); /***** Go over result removing media files *****/ Med_RemoveMediaFromAllRows (NumMedia,mysql_res); diff --git a/swad_test.h b/swad_test.h index 59473c59..84b7990d 100644 --- a/swad_test.h +++ b/swad_test.h @@ -143,7 +143,7 @@ void Tst_WriteParamQstCod (unsigned NumQst,long QstCod); void Tst_CheckIfNumberOfAnswersIsOne (const struct Tst_Question *Question); -unsigned long Tst_GetTagsQst (long QstCod,MYSQL_RES **mysql_res); +unsigned Tst_GetTagsQst (long QstCod,MYSQL_RES **mysql_res); void Tst_GetAndWriteTagsQst (long QstCod); void Tst_ShowFormConfig (void); @@ -161,7 +161,7 @@ bool Tst_AllocateTextChoiceAnswer (struct Tst_Question *Question,unsigned NumOpt Tst_AnswerType_t Tst_GetQstAnswerTypeFromDB (long QstCod); bool Tst_GetQstDataFromDB (struct Tst_Question *Question); -Tst_AnswerType_t Tst_ConvertFromStrAnsTypDBToAnsTyp (const char *StrAnsTypeBD); +Tst_AnswerType_t Tst_ConvertFromStrAnsTypDBToAnsTyp (const char *StrAnsTypeDB); void Tst_ReceiveQst (void); bool Tst_CheckIfQstFormatIsCorrectAndCountNumOptions (struct Tst_Question *Question); diff --git a/swad_test_import.c b/swad_test_import.c index a24c12b5..a5f214a8 100644 --- a/swad_test_import.c +++ b/swad_test_import.c @@ -301,16 +301,16 @@ static void TsI_ExportQuestion (struct Tst_Question *Question,FILE *FileXML) static void TsI_GetAndWriteTagsXML (long QstCod,FILE *FileXML) { extern const char *Txt_NEW_LINE; - unsigned long NumRow; - unsigned long NumRows; + unsigned NumTags; + unsigned NumTag; MYSQL_RES *mysql_res; MYSQL_ROW row; - if ((NumRows = Tst_GetTagsQst (QstCod,&mysql_res))) // Result: TagTxt + if ((NumTags = Tst_GetTagsQst (QstCod,&mysql_res))) // Result: TagTxt /***** Write the tags *****/ - for (NumRow = 1; - NumRow <= NumRows; - NumRow++) + for (NumTag = 1; + NumTag <= NumTags; + NumTag++) { row = mysql_fetch_row (mysql_res); fprintf (FileXML,"%s%s", diff --git a/swad_test_print.c b/swad_test_print.c index 68385fa3..4b04ed0c 100644 --- a/swad_test_print.c +++ b/swad_test_print.c @@ -872,12 +872,12 @@ static void TstPrn_GetCorrectIntAnswerFromDB (struct Tst_Question *Question) MYSQL_ROW row; /***** Query database *****/ - Question->Answer.NumOptions = - (unsigned) DB_QuerySELECT (&mysql_res,"can not get answers of a question", - "SELECT Answer" // row[0] - " FROM tst_answers" - " WHERE QstCod=%ld", - Question->QstCod); + Question->Answer.NumOptions = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get answers of a question", + "SELECT Answer" // row[0] + " FROM tst_answers" + " WHERE QstCod=%ld", + Question->QstCod); /***** Check if number of rows is correct *****/ Tst_CheckIfNumberOfAnswersIsOne (Question); @@ -899,12 +899,12 @@ static void TstPrn_GetCorrectFltAnswerFromDB (struct Tst_Question *Question) double Tmp; /***** Query database *****/ - Question->Answer.NumOptions = - (unsigned) DB_QuerySELECT (&mysql_res,"can not get answers of a question", - "SELECT Answer" // row[0] - " FROM tst_answers" - " WHERE QstCod=%ld", - Question->QstCod); + Question->Answer.NumOptions = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get answers of a question", + "SELECT Answer" // row[0] + " FROM tst_answers" + " WHERE QstCod=%ld", + Question->QstCod); /***** Check if number of rows is correct *****/ if (Question->Answer.NumOptions != 2) @@ -937,12 +937,12 @@ static void TstPrn_GetCorrectTF_AnswerFromDB (struct Tst_Question *Question) MYSQL_ROW row; /***** Query database *****/ - Question->Answer.NumOptions = - (unsigned) DB_QuerySELECT (&mysql_res,"can not get answers of a question", - "SELECT Answer" // row[0] - " FROM tst_answers" - " WHERE QstCod=%ld", - Question->QstCod); + Question->Answer.NumOptions = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get answers of a question", + "SELECT Answer" // row[0] + " FROM tst_answers" + " WHERE QstCod=%ld", + Question->QstCod); /***** Check if number of rows is correct *****/ Tst_CheckIfNumberOfAnswersIsOne (Question); @@ -962,13 +962,13 @@ static void TstPrn_GetCorrectChoAnswerFromDB (struct Tst_Question *Question) unsigned NumOpt; /***** Query database *****/ - Question->Answer.NumOptions = - (unsigned) DB_QuerySELECT (&mysql_res,"can not get answers of a question", - "SELECT Correct" // row[0] - " FROM tst_answers" - " WHERE QstCod=%ld" - " ORDER BY AnsInd", - Question->QstCod); + Question->Answer.NumOptions = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get answers of a question", + "SELECT Correct" // row[0] + " FROM tst_answers" + " WHERE QstCod=%ld" + " ORDER BY AnsInd", + Question->QstCod); for (NumOpt = 0; NumOpt < Question->Answer.NumOptions; NumOpt++) @@ -991,12 +991,12 @@ static void TstPrn_GetCorrectTxtAnswerFromDB (struct Tst_Question *Question) unsigned NumOpt; /***** Query database *****/ - Question->Answer.NumOptions = - (unsigned) DB_QuerySELECT (&mysql_res,"can not get answers of a question", - "SELECT Answer" // row[0] - " FROM tst_answers" - " WHERE QstCod=%ld", - Question->QstCod); + Question->Answer.NumOptions = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get answers of a question", + "SELECT Answer" // row[0] + " FROM tst_answers" + " WHERE QstCod=%ld", + Question->QstCod); /***** Get text and correctness of answers for this question from database (one row per answer) *****/ for (NumOpt = 0; @@ -2067,19 +2067,19 @@ static void TstPrn_ShowUsrPrints (struct UsrData *UsrDat) -----|______Exam_|_____|-----------------|_____|_Exam______|-----> time Start | End Start | End */ - NumPrints = - (unsigned) DB_QuerySELECT (&mysql_res,"can not get test exams of a user", - "SELECT ExaCod" // row[0] - " FROM tst_exams" - " WHERE CrsCod=%ld" - " AND UsrCod=%ld" - " AND EndTime>=FROM_UNIXTIME(%ld)" - " AND StartTime<=FROM_UNIXTIME(%ld)" - " ORDER BY ExaCod", - Gbl.Hierarchy.Crs.CrsCod, - UsrDat->UsrCod, - (long) Gbl.DateRange.TimeUTC[Dat_START_TIME], - (long) Gbl.DateRange.TimeUTC[Dat_END_TIME ]); + NumPrints = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get test exams of a user", + "SELECT ExaCod" // row[0] + " FROM tst_exams" + " WHERE CrsCod=%ld" + " AND UsrCod=%ld" + " AND EndTime>=FROM_UNIXTIME(%ld)" + " AND StartTime<=FROM_UNIXTIME(%ld)" + " ORDER BY ExaCod", + Gbl.Hierarchy.Crs.CrsCod, + UsrDat->UsrCod, + (long) Gbl.DateRange.TimeUTC[Dat_START_TIME], + (long) Gbl.DateRange.TimeUTC[Dat_END_TIME ]); /***** Show user's data *****/ HTM_TR_Begin (NULL); @@ -2752,17 +2752,16 @@ void TstPrn_GetPrintQuestionsFromDB (struct TstPrn_Print *Print) unsigned NumQst; /***** Get questions of a test exam print from database *****/ - NumQsts = - (unsigned) DB_QuerySELECT (&mysql_res,"can not get questions" - " of a test exam", - "SELECT QstCod," // row[0] - "Score," // row[1] - "Indexes," // row[2] - "Answers" // row[3] - " FROM tst_exam_questions" - " WHERE ExaCod=%ld" - " ORDER BY QstInd", - Print->PrnCod); + NumQsts = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get questions of a test exam", + "SELECT QstCod," // row[0] + "Score," // row[1] + "Indexes," // row[2] + "Answers" // row[3] + " FROM tst_exam_questions" + " WHERE ExaCod=%ld" + " ORDER BY QstInd", + Print->PrnCod); /***** Get questions *****/ if (NumQsts == Print->NumQsts.All) diff --git a/swad_timetable.c b/swad_timetable.c index ec462e04..5bbe355b 100644 --- a/swad_timetable.c +++ b/swad_timetable.c @@ -691,8 +691,8 @@ static void Tmt_FillTimeTableFromDB (struct Tmt_Timetable *Timetable, extern const char *Txt_Incomplete_timetable_for_lack_of_space; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows = 0; // Initialized to avoid warning - unsigned long NumRow; + unsigned NumRows = 0; // Initialized to avoid warning + unsigned NumRow; unsigned Weekday; unsigned Interval; unsigned i; // To iterate through intervals @@ -715,7 +715,7 @@ static void Tmt_FillTimeTableFromDB (struct Tmt_Timetable *Timetable, switch (Gbl.Crs.Grps.WhichGrps) { case Grp_MY_GROUPS: - NumRows = + NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get timetable", "SELECT tmt_courses.Weekday," // row[0] "TIME_TO_SEC(tmt_courses.StartTime) AS S," // row[1] @@ -763,7 +763,7 @@ static void Tmt_FillTimeTableFromDB (struct Tmt_Timetable *Timetable, UsrCod); break; case Grp_ALL_GROUPS: - NumRows = + NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get timetable", "SELECT tmt_courses.Weekday," // row[0] "TIME_TO_SEC(tmt_courses.StartTime) AS S," // row[1] @@ -802,7 +802,7 @@ static void Tmt_FillTimeTableFromDB (struct Tmt_Timetable *Timetable, if (Gbl.Crs.Grps.WhichGrps == Grp_ALL_GROUPS || Gbl.Action.Act == ActEdiCrsTT || Gbl.Action.Act == ActChgCrsTT) // If we are editing, all groups are shown - NumRows = + NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get timetable", "SELECT Weekday," // row[0] "TIME_TO_SEC(StartTime) AS S," // row[1] @@ -820,7 +820,7 @@ static void Tmt_FillTimeTableFromDB (struct Tmt_Timetable *Timetable, "D DESC", Gbl.Hierarchy.Crs.CrsCod); else - NumRows = + NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get timetable", "SELECT tmt_courses.Weekday," // row[0] "TIME_TO_SEC(tmt_courses.StartTime) AS S," // row[1] @@ -856,7 +856,7 @@ static void Tmt_FillTimeTableFromDB (struct Tmt_Timetable *Timetable, Gbl.Hierarchy.Crs.CrsCod,UsrCod); break; case Tmt_TUTORING_TIMETABLE: - NumRows = + NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get timetable", "SELECT Weekday," // row[0] "TIME_TO_SEC(StartTime) AS S," // row[1] diff --git a/swad_user.c b/swad_user.c index 10fdbad3..ce785ba8 100644 --- a/swad_user.c +++ b/swad_user.c @@ -457,17 +457,15 @@ void Usr_GetUsrCodFromEncryptedUsrCod (struct UsrData *UsrDat) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; if (UsrDat->EnUsrCod[0]) { /***** Get user's code from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get user's code", - "SELECT UsrCod" - " FROM usr_data" - " WHERE EncryptedUsrCod='%s'", - UsrDat->EnUsrCod); - if (NumRows != 1) + if (DB_QuerySELECT (&mysql_res,"can not get user's code", + "SELECT UsrCod" + " FROM usr_data" + " WHERE EncryptedUsrCod='%s'", + UsrDat->EnUsrCod) != 1) Lay_ShowErrorAndExit ("Error when getting user's code."); /***** Get user's code *****/ @@ -494,7 +492,7 @@ void Usr_GetUsrDataFromUsrCod (struct UsrData *UsrDat,Usr_GetPrefs_t GetPrefs) extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES]; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; + unsigned NumRows; The_Theme_t Theme; Ico_IconSet_t IconSet; Lan_Language_t Lan; @@ -503,76 +501,78 @@ void Usr_GetUsrDataFromUsrCod (struct UsrData *UsrDat,Usr_GetPrefs_t GetPrefs) switch (GetPrefs) { case Usr_DONT_GET_PREFS: - NumRows = DB_QuerySELECT (&mysql_res,"can not get user's data", - "SELECT EncryptedUsrCod," // row[ 0] - "Password," // row[ 1] - "Surname1," // row[ 2] - "Surname2," // row[ 3] - "FirstName," // row[ 4] - "Sex," // row[ 5] - "Photo," // row[ 6] - "PhotoVisibility," // row[ 7] - "BaPrfVisibility," // row[ 8] - "ExPrfVisibility," // row[ 9] - "CtyCod," // row[10] - "InsCtyCod," // row[11] - "InsCod," // row[12] - "DptCod," // row[13] - "CtrCod," // row[14] - "Office," // row[15] - "OfficePhone," // row[16] - "LocalPhone," // row[17] - "FamilyPhone," // row[18] - "DATE_FORMAT(Birthday," - "'%%Y%%m%%d')," // row[19] - "Comments," // row[20] - "NotifNtfEvents," // row[21] - "EmailNtfEvents" // row[22] - " FROM usr_data" - " WHERE UsrCod=%ld", - UsrDat->UsrCod); + NumRows = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get user's data", + "SELECT EncryptedUsrCod," // row[ 0] + "Password," // row[ 1] + "Surname1," // row[ 2] + "Surname2," // row[ 3] + "FirstName," // row[ 4] + "Sex," // row[ 5] + "Photo," // row[ 6] + "PhotoVisibility," // row[ 7] + "BaPrfVisibility," // row[ 8] + "ExPrfVisibility," // row[ 9] + "CtyCod," // row[10] + "InsCtyCod," // row[11] + "InsCod," // row[12] + "DptCod," // row[13] + "CtrCod," // row[14] + "Office," // row[15] + "OfficePhone," // row[16] + "LocalPhone," // row[17] + "FamilyPhone," // row[18] + "DATE_FORMAT(Birthday," + "'%%Y%%m%%d')," // row[19] + "Comments," // row[20] + "NotifNtfEvents," // row[21] + "EmailNtfEvents" // row[22] + " FROM usr_data" + " WHERE UsrCod=%ld", + UsrDat->UsrCod); break; case Usr_GET_PREFS: default: - NumRows = DB_QuerySELECT (&mysql_res,"can not get user's data", - "SELECT EncryptedUsrCod," // row[ 0] - "Password," // row[ 1] - "Surname1," // row[ 2] - "Surname2," // row[ 3] - "FirstName," // row[ 4] - "Sex," // row[ 5] - "Photo," // row[ 6] - "PhotoVisibility," // row[ 7] - "BaPrfVisibility," // row[ 8] - "ExPrfVisibility," // row[ 9] - "CtyCod," // row[10] - "InsCtyCod," // row[11] - "InsCod," // row[12] - "DptCod," // row[13] - "CtrCod," // row[14] - "Office," // row[15] - "OfficePhone," // row[16] - "LocalPhone," // row[17] - "FamilyPhone," // row[18] - "DATE_FORMAT(Birthday," - "'%%Y%%m%%d')," // row[19] - "Comments," // row[20] - "NotifNtfEvents," // row[21] - "EmailNtfEvents," // row[22] + NumRows = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get user's data", + "SELECT EncryptedUsrCod," // row[ 0] + "Password," // row[ 1] + "Surname1," // row[ 2] + "Surname2," // row[ 3] + "FirstName," // row[ 4] + "Sex," // row[ 5] + "Photo," // row[ 6] + "PhotoVisibility," // row[ 7] + "BaPrfVisibility," // row[ 8] + "ExPrfVisibility," // row[ 9] + "CtyCod," // row[10] + "InsCtyCod," // row[11] + "InsCod," // row[12] + "DptCod," // row[13] + "CtrCod," // row[14] + "Office," // row[15] + "OfficePhone," // row[16] + "LocalPhone," // row[17] + "FamilyPhone," // row[18] + "DATE_FORMAT(Birthday," + "'%%Y%%m%%d')," // row[19] + "Comments," // row[20] + "NotifNtfEvents," // row[21] + "EmailNtfEvents," // row[22] - // Settings (usually not necessary - // when getting another user's data) - "Language," // row[23] - "FirstDayOfWeek," // row[24] - "DateFormat," // row[25] - "Theme," // row[26] - "IconSet," // row[27] - "Menu," // row[28] - "SideCols," // row[29] - "ThirdPartyCookies" // row[30] - " FROM usr_data" - " WHERE UsrCod=%ld", - UsrDat->UsrCod); + // Settings (usually not necessary + // when getting another user's data) + "Language," // row[23] + "FirstDayOfWeek," // row[24] + "DateFormat," // row[25] + "Theme," // row[26] + "IconSet," // row[27] + "Menu," // row[28] + "SideCols," // row[29] + "ThirdPartyCookies" // row[30] + " FROM usr_data" + " WHERE UsrCod=%ld", + UsrDat->UsrCod); break; } @@ -743,22 +743,23 @@ static void Usr_GetMyLastData (void) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; + unsigned NumRows; unsigned UnsignedNum; long ActCod; /***** Get user's last data from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get user's last data", - "SELECT WhatToSearch," // row[0] - "LastSco," // row[1] - "LastCod," // row[2] - "LastAct," // row[3] - "LastRole," // row[4] - "UNIX_TIMESTAMP(LastTime)," // row[5] - "UNIX_TIMESTAMP(LastAccNotif)" // row[6] - " FROM usr_last" - " WHERE UsrCod=%ld", - Gbl.Usrs.Me.UsrDat.UsrCod); + NumRows = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get user's last data", + "SELECT WhatToSearch," // row[0] + "LastSco," // row[1] + "LastCod," // row[2] + "LastAct," // row[3] + "LastRole," // row[4] + "UNIX_TIMESTAMP(LastTime)," // row[5] + "UNIX_TIMESTAMP(LastAccNotif)" // row[6] + " FROM usr_last" + " WHERE UsrCod=%ld", + Gbl.Usrs.Me.UsrDat.UsrCod); if (NumRows == 0) { /***** Free structure that stores the query result *****/ @@ -1551,26 +1552,26 @@ void Usr_GetMyCountrs (void) Gbl.Usrs.Me.MyCtys.Num = 0; /***** Get my institutions from database *****/ - if ((NumCtys = (unsigned) Usr_GetCtysFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,&mysql_res)) > 0) // Countries found - for (NumCty = 0; - NumCty < NumCtys; - NumCty++) - { - /* Get next country */ - row = mysql_fetch_row (mysql_res); + NumCtys = Usr_GetCtysFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,&mysql_res); + for (NumCty = 0; + NumCty < NumCtys; + NumCty++) + { + /* Get next country */ + row = mysql_fetch_row (mysql_res); - /* Get country code */ - if ((CtyCod = Str_ConvertStrCodToLongCod (row[0])) > 0) - { - if (Gbl.Usrs.Me.MyCtys.Num == Cty_MAX_COUNTRS_PER_USR) - Lay_ShowErrorAndExit ("Maximum number of countries of a user exceeded."); + /* Get country code */ + if ((CtyCod = Str_ConvertStrCodToLongCod (row[0])) > 0) + { + if (Gbl.Usrs.Me.MyCtys.Num == Cty_MAX_COUNTRS_PER_USR) + Lay_ShowErrorAndExit ("Maximum number of countries of a user exceeded."); - Gbl.Usrs.Me.MyCtys.Ctys[Gbl.Usrs.Me.MyCtys.Num].CtyCod = CtyCod; - Gbl.Usrs.Me.MyCtys.Ctys[Gbl.Usrs.Me.MyCtys.Num].MaxRole = Rol_ConvertUnsignedStrToRole (row[1]); + Gbl.Usrs.Me.MyCtys.Ctys[Gbl.Usrs.Me.MyCtys.Num].CtyCod = CtyCod; + Gbl.Usrs.Me.MyCtys.Ctys[Gbl.Usrs.Me.MyCtys.Num].MaxRole = Rol_ConvertUnsignedStrToRole (row[1]); - Gbl.Usrs.Me.MyCtys.Num++; - } - } + Gbl.Usrs.Me.MyCtys.Num++; + } + } /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -1598,26 +1599,26 @@ void Usr_GetMyInstits (void) Gbl.Usrs.Me.MyInss.Num = 0; /***** Get my institutions from database *****/ - if ((NumInss = (unsigned) Usr_GetInssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,-1L,&mysql_res)) > 0) // Institutions found - for (NumIns = 0; - NumIns < NumInss; - NumIns++) - { - /* Get next institution */ - row = mysql_fetch_row (mysql_res); + NumInss = Usr_GetInssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,-1L,&mysql_res); + for (NumIns = 0; + NumIns < NumInss; + NumIns++) + { + /* Get next institution */ + row = mysql_fetch_row (mysql_res); - /* Get institution code */ - if ((InsCod = Str_ConvertStrCodToLongCod (row[0])) > 0) - { - if (Gbl.Usrs.Me.MyInss.Num == Ins_MAX_INSTITS_PER_USR) - Lay_ShowErrorAndExit ("Maximum number of institutions of a user exceeded."); + /* Get institution code */ + if ((InsCod = Str_ConvertStrCodToLongCod (row[0])) > 0) + { + if (Gbl.Usrs.Me.MyInss.Num == Ins_MAX_INSTITS_PER_USR) + Lay_ShowErrorAndExit ("Maximum number of institutions of a user exceeded."); - Gbl.Usrs.Me.MyInss.Inss[Gbl.Usrs.Me.MyInss.Num].InsCod = InsCod; - Gbl.Usrs.Me.MyInss.Inss[Gbl.Usrs.Me.MyInss.Num].MaxRole = Rol_ConvertUnsignedStrToRole (row[1]); + Gbl.Usrs.Me.MyInss.Inss[Gbl.Usrs.Me.MyInss.Num].InsCod = InsCod; + Gbl.Usrs.Me.MyInss.Inss[Gbl.Usrs.Me.MyInss.Num].MaxRole = Rol_ConvertUnsignedStrToRole (row[1]); - Gbl.Usrs.Me.MyInss.Num++; - } - } + Gbl.Usrs.Me.MyInss.Num++; + } + } /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -1645,26 +1646,26 @@ void Usr_GetMyCenters (void) Gbl.Usrs.Me.MyCtrs.Num = 0; /***** Get my centers from database *****/ - if ((NumCtrs = (unsigned) Usr_GetCtrsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,-1L,&mysql_res)) > 0) // Centers found - for (NumCtr = 0; - NumCtr < NumCtrs; - NumCtr++) - { - /* Get next center */ - row = mysql_fetch_row (mysql_res); + NumCtrs = Usr_GetCtrsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,-1L,&mysql_res); + for (NumCtr = 0; + NumCtr < NumCtrs; + NumCtr++) + { + /* Get next center */ + row = mysql_fetch_row (mysql_res); - /* Get center code */ - if ((CtrCod = Str_ConvertStrCodToLongCod (row[0])) > 0) - { - if (Gbl.Usrs.Me.MyCtrs.Num == Ctr_MAX_CENTERS_PER_USR) - Lay_ShowErrorAndExit ("Maximum number of centers of a user exceeded."); + /* Get center code */ + if ((CtrCod = Str_ConvertStrCodToLongCod (row[0])) > 0) + { + if (Gbl.Usrs.Me.MyCtrs.Num == Ctr_MAX_CENTERS_PER_USR) + Lay_ShowErrorAndExit ("Maximum number of centers of a user exceeded."); - Gbl.Usrs.Me.MyCtrs.Ctrs[Gbl.Usrs.Me.MyCtrs.Num].CtrCod = CtrCod; - Gbl.Usrs.Me.MyCtrs.Ctrs[Gbl.Usrs.Me.MyCtrs.Num].MaxRole = Rol_ConvertUnsignedStrToRole (row[1]); + Gbl.Usrs.Me.MyCtrs.Ctrs[Gbl.Usrs.Me.MyCtrs.Num].CtrCod = CtrCod; + Gbl.Usrs.Me.MyCtrs.Ctrs[Gbl.Usrs.Me.MyCtrs.Num].MaxRole = Rol_ConvertUnsignedStrToRole (row[1]); - Gbl.Usrs.Me.MyCtrs.Num++; - } - } + Gbl.Usrs.Me.MyCtrs.Num++; + } + } /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -1692,26 +1693,26 @@ void Usr_GetMyDegrees (void) Gbl.Usrs.Me.MyDegs.Num = 0; /***** Get my degrees from database *****/ - if ((NumDegs = (unsigned) Usr_GetDegsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,-1L,&mysql_res)) > 0) // Degrees found - for (NumDeg = 0; - NumDeg < NumDegs; - NumDeg++) - { - /* Get next degree */ - row = mysql_fetch_row (mysql_res); + NumDegs = Usr_GetDegsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,-1L,&mysql_res); + for (NumDeg = 0; + NumDeg < NumDegs; + NumDeg++) + { + /* Get next degree */ + row = mysql_fetch_row (mysql_res); - /* Get degree code */ - if ((DegCod = Str_ConvertStrCodToLongCod (row[0])) > 0) - { - if (Gbl.Usrs.Me.MyDegs.Num == Deg_MAX_DEGREES_PER_USR) - Lay_ShowErrorAndExit ("Maximum number of degrees of a user exceeded."); + /* Get degree code */ + if ((DegCod = Str_ConvertStrCodToLongCod (row[0])) > 0) + { + if (Gbl.Usrs.Me.MyDegs.Num == Deg_MAX_DEGREES_PER_USR) + Lay_ShowErrorAndExit ("Maximum number of degrees of a user exceeded."); - Gbl.Usrs.Me.MyDegs.Degs[Gbl.Usrs.Me.MyDegs.Num].DegCod = DegCod; - Gbl.Usrs.Me.MyDegs.Degs[Gbl.Usrs.Me.MyDegs.Num].MaxRole = Rol_ConvertUnsignedStrToRole (row[1]); + Gbl.Usrs.Me.MyDegs.Degs[Gbl.Usrs.Me.MyDegs.Num].DegCod = DegCod; + Gbl.Usrs.Me.MyDegs.Degs[Gbl.Usrs.Me.MyDegs.Num].MaxRole = Rol_ConvertUnsignedStrToRole (row[1]); - Gbl.Usrs.Me.MyDegs.Num++; - } - } + Gbl.Usrs.Me.MyDegs.Num++; + } + } /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -1764,13 +1765,12 @@ void Usr_GetMyCourses (void) Gbl.Usrs.Me.UsrDat.UsrCod); /***** Get my courses from database *****/ - NumCrss = - (unsigned) DB_QuerySELECT (&mysql_res,"can not get which courses" - " you belong to", - "SELECT CrsCod," // row[0] - "Role," // row[1] - "DegCod" // row[2] - " FROM my_courses_tmp"); + NumCrss = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get which courses you belong to", + "SELECT CrsCod," // row[0] + "Role," // row[1] + "DegCod" // row[2] + " FROM my_courses_tmp"); for (NumCrs = 0; NumCrs < NumCrss; NumCrs++) @@ -2264,46 +2264,47 @@ unsigned Usr_GetCtysFromUsr (long UsrCod,MYSQL_RES **mysql_res) /*****************************************************************************/ // Returns the number of rows of the result -unsigned long Usr_GetInssFromUsr (long UsrCod,long CtyCod,MYSQL_RES **mysql_res) +unsigned Usr_GetInssFromUsr (long UsrCod,long CtyCod,MYSQL_RES **mysql_res) { /***** Get the institutions a user belongs to from database *****/ if (CtyCod > 0) - return DB_QuerySELECT (mysql_res,"can not get the institutions" - " a user belongs to", - "SELECT ins_instits.InsCod," // row[0] - "MAX(crs_users.Role)" // row[1] - " FROM crs_users," - "crs_courses," - "deg_degrees," - "ctr_centers," - "ins_instits" - " WHERE crs_users.UsrCod=%ld" - " AND crs_users.CrsCod=crs_courses.CrsCod" - " AND crs_courses.DegCod=deg_degrees.DegCod" - " AND deg_degrees.CtrCod=ctr_centers.CtrCod" - " AND ctr_centers.InsCod=ins_instits.InsCod" - " AND ins_instits.CtyCod=%ld" - " GROUP BY ins_instits.InsCod" - " ORDER BY ins_instits.ShortName", - UsrCod,CtyCod); + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get the institutions a user belongs to", + "SELECT ins_instits.InsCod," // row[0] + "MAX(crs_users.Role)" // row[1] + " FROM crs_users," + "crs_courses," + "deg_degrees," + "ctr_centers," + "ins_instits" + " WHERE crs_users.UsrCod=%ld" + " AND crs_users.CrsCod=crs_courses.CrsCod" + " AND crs_courses.DegCod=deg_degrees.DegCod" + " AND deg_degrees.CtrCod=ctr_centers.CtrCod" + " AND ctr_centers.InsCod=ins_instits.InsCod" + " AND ins_instits.CtyCod=%ld" + " GROUP BY ins_instits.InsCod" + " ORDER BY ins_instits.ShortName", + UsrCod, + CtyCod); else - return DB_QuerySELECT (mysql_res,"can not get the ins_instits" - " a user belongs to", - "SELECT ins_instits.InsCod," // row[0] - "MAX(crs_users.Role)" // row[1] - " FROM crs_users," - "crs_courses," - "deg_degrees," - "ctr_centers," - "ins_instits" - " WHERE crs_users.UsrCod=%ld" - " AND crs_users.CrsCod=crs_courses.CrsCod" - " AND crs_courses.DegCod=deg_degrees.DegCod" - " AND deg_degrees.CtrCod=ctr_centers.CtrCod" - " AND ctr_centers.InsCod=ins_instits.InsCod" - " GROUP BY ins_instits.InsCod" - " ORDER BY ins_instits.ShortName", - UsrCod); + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get the institutions a user belongs to", + "SELECT ins_instits.InsCod," // row[0] + "MAX(crs_users.Role)" // row[1] + " FROM crs_users," + "crs_courses," + "deg_degrees," + "ctr_centers," + "ins_instits" + " WHERE crs_users.UsrCod=%ld" + " AND crs_users.CrsCod=crs_courses.CrsCod" + " AND crs_courses.DegCod=deg_degrees.DegCod" + " AND deg_degrees.CtrCod=ctr_centers.CtrCod" + " AND ctr_centers.InsCod=ins_instits.InsCod" + " GROUP BY ins_instits.InsCod" + " ORDER BY ins_instits.ShortName", + UsrCod); } /*****************************************************************************/ @@ -2311,42 +2312,43 @@ unsigned long Usr_GetInssFromUsr (long UsrCod,long CtyCod,MYSQL_RES **mysql_res) /*****************************************************************************/ // Returns the number of rows of the result -unsigned long Usr_GetCtrsFromUsr (long UsrCod,long InsCod,MYSQL_RES **mysql_res) +unsigned Usr_GetCtrsFromUsr (long UsrCod,long InsCod,MYSQL_RES **mysql_res) { /***** Get from database the centers a user belongs to *****/ if (InsCod > 0) - return DB_QuerySELECT (mysql_res,"can not check the centers" - " a user belongs to", - "SELECT ctr_centers.CtrCod," // row[0] - "MAX(crs_users.Role)" // row[1] - " FROM crs_users," - "crs_courses," - "deg_degrees," - "ctr_centers" - " WHERE crs_users.UsrCod=%ld" - " AND crs_users.CrsCod=crs_courses.CrsCod" - " AND crs_courses.DegCod=deg_degrees.DegCod" - " AND deg_degrees.CtrCod=ctr_centers.CtrCod" - " AND ctr_centers.InsCod=%ld" - " GROUP BY ctr_centers.CtrCod" - " ORDER BY ctr_centers.ShortName", - UsrCod,InsCod); + return (unsigned) + DB_QuerySELECT (mysql_res,"can not check the centers a user belongs to", + "SELECT ctr_centers.CtrCod," // row[0] + "MAX(crs_users.Role)" // row[1] + " FROM crs_users," + "crs_courses," + "deg_degrees," + "ctr_centers" + " WHERE crs_users.UsrCod=%ld" + " AND crs_users.CrsCod=crs_courses.CrsCod" + " AND crs_courses.DegCod=deg_degrees.DegCod" + " AND deg_degrees.CtrCod=ctr_centers.CtrCod" + " AND ctr_centers.InsCod=%ld" + " GROUP BY ctr_centers.CtrCod" + " ORDER BY ctr_centers.ShortName", + UsrCod, + InsCod); else - return DB_QuerySELECT (mysql_res,"can not check the centers" - " a user belongs to", - "SELECT deg_degrees.CtrCod," // row[0] - "MAX(crs_users.Role)" // row[1] - " FROM crs_users," - "crs_courses," - "deg_degrees," - "ctr_centers" - " WHERE crs_users.UsrCod=%ld" - " AND crs_users.CrsCod=crs_courses.CrsCod" - " AND crs_courses.DegCod=deg_degrees.DegCod" - " AND deg_degrees.CtrCod=ctr_centers.CtrCod" - " GROUP BY ctr_centers.CtrCod" - " ORDER BY ctr_centers.ShortName", - UsrCod); + return (unsigned) + DB_QuerySELECT (mysql_res,"can not check the centers a user belongs to", + "SELECT deg_degrees.CtrCod," // row[0] + "MAX(crs_users.Role)" // row[1] + " FROM crs_users," + "crs_courses," + "deg_degrees," + "ctr_centers" + " WHERE crs_users.UsrCod=%ld" + " AND crs_users.CrsCod=crs_courses.CrsCod" + " AND crs_courses.DegCod=deg_degrees.DegCod" + " AND deg_degrees.CtrCod=ctr_centers.CtrCod" + " GROUP BY ctr_centers.CtrCod" + " ORDER BY ctr_centers.ShortName", + UsrCod); } /*****************************************************************************/ @@ -2354,38 +2356,39 @@ unsigned long Usr_GetCtrsFromUsr (long UsrCod,long InsCod,MYSQL_RES **mysql_res) /*****************************************************************************/ // Returns the number of rows of the result -unsigned long Usr_GetDegsFromUsr (long UsrCod,long CtrCod,MYSQL_RES **mysql_res) +unsigned Usr_GetDegsFromUsr (long UsrCod,long CtrCod,MYSQL_RES **mysql_res) { /***** Get from database the degrees a user belongs to *****/ if (CtrCod > 0) - return DB_QuerySELECT (mysql_res,"can not check the degrees" - " a user belongs to", - "SELECT deg_degrees.DegCod," // row[0] - "MAX(crs_users.Role)" // row[1] - " FROM crs_users," - "crs_courses," - "deg_degrees" - " WHERE crs_users.UsrCod=%ld" - " AND crs_users.CrsCod=crs_courses.CrsCod" - " AND crs_courses.DegCod=deg_degrees.DegCod" - " AND deg_degrees.CtrCod=%ld" - " GROUP BY deg_degrees.DegCod" - " ORDER BY deg_degrees.ShortName", - UsrCod,CtrCod); + return (unsigned) + DB_QuerySELECT (mysql_res,"can not check the degrees a user belongs to", + "SELECT deg_degrees.DegCod," // row[0] + "MAX(crs_users.Role)" // row[1] + " FROM crs_users," + "crs_courses," + "deg_degrees" + " WHERE crs_users.UsrCod=%ld" + " AND crs_users.CrsCod=crs_courses.CrsCod" + " AND crs_courses.DegCod=deg_degrees.DegCod" + " AND deg_degrees.CtrCod=%ld" + " GROUP BY deg_degrees.DegCod" + " ORDER BY deg_degrees.ShortName", + UsrCod, + CtrCod); else - return DB_QuerySELECT (mysql_res,"can not check the degrees" - " a user belongs to", - "SELECT deg_degrees.DegCod," // row[0] - "MAX(crs_users.Role)" // row[1] - " FROM crs_users," - "crs_courses," - "deg_degrees" - " WHERE crs_users.UsrCod=%ld" - " AND crs_users.CrsCod=crs_courses.CrsCod" - " AND crs_courses.DegCod=deg_degrees.DegCod" - " GROUP BY deg_degrees.DegCod" - " ORDER BY deg_degrees.ShortName", - UsrCod); + return (unsigned) + DB_QuerySELECT (mysql_res,"can not check the degrees a user belongs to", + "SELECT deg_degrees.DegCod," // row[0] + "MAX(crs_users.Role)" // row[1] + " FROM crs_users," + "crs_courses," + "deg_degrees" + " WHERE crs_users.UsrCod=%ld" + " AND crs_users.CrsCod=crs_courses.CrsCod" + " AND crs_courses.DegCod=deg_degrees.DegCod" + " GROUP BY deg_degrees.DegCod" + " ORDER BY deg_degrees.ShortName", + UsrCod); } /*****************************************************************************/ @@ -2393,37 +2396,38 @@ unsigned long Usr_GetDegsFromUsr (long UsrCod,long CtrCod,MYSQL_RES **mysql_res) /*****************************************************************************/ // Returns the number of rows of the result -unsigned long Usr_GetCrssFromUsr (long UsrCod,long DegCod,MYSQL_RES **mysql_res) +unsigned Usr_GetCrssFromUsr (long UsrCod,long DegCod,MYSQL_RES **mysql_res) { /***** Get from database the courses a user belongs to *****/ if (DegCod > 0) // Courses in a degree - return DB_QuerySELECT (mysql_res,"can not get the courses" - " a user belongs to", - "SELECT crs_users.CrsCod," // row[0] - "crs_users.Role," // row[1] - "crs_courses.DegCod" // row[2] - " FROM crs_users," - "crs_courses" - " WHERE crs_users.UsrCod=%ld" - " AND crs_users.CrsCod=crs_courses.CrsCod" - " AND crs_courses.DegCod=%ld" - " ORDER BY crs_courses.ShortName", - UsrCod,DegCod); + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get the courses a user belongs to", + "SELECT crs_users.CrsCod," // row[0] + "crs_users.Role," // row[1] + "crs_courses.DegCod" // row[2] + " FROM crs_users," + "crs_courses" + " WHERE crs_users.UsrCod=%ld" + " AND crs_users.CrsCod=crs_courses.CrsCod" + " AND crs_courses.DegCod=%ld" + " ORDER BY crs_courses.ShortName", + UsrCod, + DegCod); else // All the courses - return DB_QuerySELECT (mysql_res,"can not get the courses" - " a user belongs to", - "SELECT crs_users.CrsCod," // row[0] - "crs_users.Role," // row[1] - "crs_courses.DegCod" // row[2] - " FROM crs_users," - "crs_courses," - "deg_degrees" - " WHERE crs_users.UsrCod=%ld" - " AND crs_users.CrsCod=crs_courses.CrsCod" - " AND crs_courses.DegCod=deg_degrees.DegCod" - " ORDER BY deg_degrees.ShortName," - "crs_courses.ShortName", - UsrCod); + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get the courses a user belongs to", + "SELECT crs_users.CrsCod," // row[0] + "crs_users.Role," // row[1] + "crs_courses.DegCod" // row[2] + " FROM crs_users," + "crs_courses," + "deg_degrees" + " WHERE crs_users.UsrCod=%ld" + " AND crs_users.CrsCod=crs_courses.CrsCod" + " AND crs_courses.DegCod=deg_degrees.DegCod" + " ORDER BY deg_degrees.ShortName," + "crs_courses.ShortName", + UsrCod); } /*****************************************************************************/ @@ -5499,10 +5503,10 @@ static void Usr_GetListUsrsFromQuery (char *Query,Rol_Role_t Role,Hie_Lvl_Level_ } /***** Query database *****/ - if ((Gbl.Usrs.LstUsrs[Role].NumUsrs = - (unsigned) DB_QuerySELECT (&mysql_res,"can not get list of users", - "%s", - Query))) + if ((Gbl.Usrs.LstUsrs[Role].NumUsrs = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get list of users", + "%s", + Query))) { if (Gbl.Usrs.LstUsrs[Role].NumUsrs > Cfg_MAX_USRS_IN_LIST) { @@ -5831,7 +5835,7 @@ void Usr_GetListsSelectedEncryptedUsrsCods (struct SelectedUsrs *SelectedUsrs) if (Gbl.Session.IsOpen) // If the session is open, get parameter from DB { Ses_GetParamFromDB (ParamName,SelectedUsrs->List[Rol_UNK], - Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS); + Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS); Str_ChangeFormat (Str_FROM_FORM,Str_TO_TEXT,SelectedUsrs->List[Rol_UNK], Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS,true); } @@ -7757,17 +7761,18 @@ static void Usr_GetMyUsrListTypeFromDB (void) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; + unsigned NumRows; Usr_ShowUsrsType_t ListType; /***** Get type of listing of users from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get type of listing of users", - "SELECT UsrListType" // row[0] - " FROM crs_user_settings" - " WHERE UsrCod=%ld" - " AND CrsCod=%ld", - Gbl.Usrs.Me.UsrDat.UsrCod, - Gbl.Hierarchy.Crs.CrsCod); + NumRows = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get type of listing of users", + "SELECT UsrListType" // row[0] + " FROM crs_user_settings" + " WHERE UsrCod=%ld" + " AND CrsCod=%ld", + Gbl.Usrs.Me.UsrDat.UsrCod, + Gbl.Hierarchy.Crs.CrsCod); if (NumRows == 1) // Should be one only row { /* Get type of users' listing used to select some of them */ @@ -7860,7 +7865,7 @@ static void Usr_GetMyColsClassPhotoFromDB (void) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; + unsigned NumRows; Gbl.Usrs.ClassPhoto.Cols = Usr_CLASS_PHOTO_COLS_DEF; @@ -7869,14 +7874,14 @@ static void Usr_GetMyColsClassPhotoFromDB (void) Gbl.Hierarchy.Level == Hie_Lvl_CRS) // Course selected { /***** Get number of columns in class photo from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not get number of columns" - " in class photo", - "SELECT ColsClassPhoto" // row[0] - " FROM crs_user_settings" - " WHERE UsrCod=%ld" - " AND CrsCod=%ld", - Gbl.Usrs.Me.UsrDat.UsrCod, - Gbl.Hierarchy.Crs.CrsCod); + NumRows = (unsigned) + DB_QuerySELECT (&mysql_res,"can not get number of columns in class photo", + "SELECT ColsClassPhoto" // row[0] + " FROM crs_user_settings" + " WHERE UsrCod=%ld" + " AND CrsCod=%ld", + Gbl.Usrs.Me.UsrDat.UsrCod, + Gbl.Hierarchy.Crs.CrsCod); if (NumRows == 1) // Should be one only row { /* Get number of columns in class photo */ @@ -7970,7 +7975,7 @@ void Usr_GetMyPrefAboutListWithPhotosFromDB (void) { MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned long NumRows; + unsigned NumRows; Gbl.Usrs.Listing.WithPhotos = Usr_LIST_WITH_PHOTOS_DEF; @@ -7978,14 +7983,15 @@ void Usr_GetMyPrefAboutListWithPhotosFromDB (void) if (Gbl.Usrs.Me.Logged && Gbl.Hierarchy.Crs.CrsCod) { /***** Get if listing of users must show photos from database *****/ - NumRows = DB_QuerySELECT (&mysql_res,"can not check if listing of users" - " must show photos", - "SELECT ListWithPhotos" // row[0] - " FROM crs_user_settings" - " WHERE UsrCod=%ld" - " AND CrsCod=%ld", - Gbl.Usrs.Me.UsrDat.UsrCod, - Gbl.Hierarchy.Crs.CrsCod); + NumRows = (unsigned) + DB_QuerySELECT (&mysql_res,"can not check if listing of users" + " must show photos", + "SELECT ListWithPhotos" // row[0] + " FROM crs_user_settings" + " WHERE UsrCod=%ld" + " AND CrsCod=%ld", + Gbl.Usrs.Me.UsrDat.UsrCod, + Gbl.Hierarchy.Crs.CrsCod); if (NumRows == 1) // Should be one only row { /* Get number of columns in class photo */ diff --git a/swad_user.h b/swad_user.h index cd40eeaa..a84f152b 100644 --- a/swad_user.h +++ b/swad_user.h @@ -358,10 +358,10 @@ bool Usr_CheckIfIBelongToDeg (long DegCod); bool Usr_CheckIfIBelongToCrs (long CrsCod); unsigned Usr_GetCtysFromUsr (long UsrCod,MYSQL_RES **mysql_res); -unsigned long Usr_GetInssFromUsr (long UsrCod,long CtyCod,MYSQL_RES **mysql_res); -unsigned long Usr_GetCtrsFromUsr (long UsrCod,long InsCod,MYSQL_RES **mysql_res); -unsigned long Usr_GetDegsFromUsr (long UsrCod,long CtrCod,MYSQL_RES **mysql_res); -unsigned long Usr_GetCrssFromUsr (long UsrCod,long DegCod,MYSQL_RES **mysql_res); +unsigned Usr_GetInssFromUsr (long UsrCod,long CtyCod,MYSQL_RES **mysql_res); +unsigned Usr_GetCtrsFromUsr (long UsrCod,long InsCod,MYSQL_RES **mysql_res); +unsigned Usr_GetDegsFromUsr (long UsrCod,long CtrCod,MYSQL_RES **mysql_res); +unsigned Usr_GetCrssFromUsr (long UsrCod,long DegCod,MYSQL_RES **mysql_res); void Usr_GetMainDeg (long UsrCod, char ShrtName[Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1], Rol_Role_t *MaxRole);