Version 20.63: Apr 16, 2021 Optimizations in database selects.

This commit is contained in:
acanas 2021-04-16 13:51:12 +02:00
parent 367b80943e
commit d3bc257ce5
55 changed files with 2679 additions and 2814 deletions

View File

@ -1013,8 +1013,8 @@ 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",
NumRows = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get session data",
"SELECT UsrCod," // row[0]
"DegCod," // row[1]
"CrsCod" // row[2]
@ -2625,9 +2625,8 @@ 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",
NumGrps = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get groups of an attendance event",
"SELECT GrpCod"
" FROM att_groups"
" WHERE AttCod=%ld",
@ -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",
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,11 +4180,12 @@ 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",
NumTags = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get test tags",
"SELECT TagCod," // row[0]
"TagTxt" // row[1]
" FROM tst_tags"
@ -4193,9 +4194,9 @@ static int API_GetTstTags (struct soap *soap,
" 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,7 +4809,8 @@ 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",
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]
@ -4828,7 +4830,7 @@ int swad__getGames (struct soap *soap,
"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,7 +4993,8 @@ 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",
NumMatches = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get matches",
"SELECT MchCod," // row[ 0]
"UsrCod," // row[ 1]
"UNIX_TIMESTAMP(StartTime)," // row[ 2]
@ -5013,7 +5016,7 @@ int swad__getMatches (struct soap *soap,
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;

View File

@ -102,13 +102,14 @@ 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",
NumActions = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get most frequently used actions",
"SELECT ActCod"
" FROM act_frequent"
" WHERE UsrCod=%ld"
@ -117,9 +118,9 @@ void MFU_GetMFUActions (struct MFU_ListMFUActions *ListMFUActions,unsigned MaxAc
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);

View File

@ -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,7 +692,8 @@ 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",
NumAsgs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get assignments",
"SELECT AsgCod"
" FROM asg_assignments"
" WHERE CrsCod=%ld%s"
@ -716,7 +717,8 @@ static void Asg_GetListAssignments (struct Asg_Assignments *Assignments)
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",
NumAsgs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get assignments",
"SELECT AsgCod"
" FROM asg_assignments"
" WHERE CrsCod=%ld%s"
@ -725,12 +727,12 @@ static void Asg_GetListAssignments (struct Asg_Assignments *Assignments)
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,12 +762,13 @@ 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",
NumAsgs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get assignment data",
"SELECT AsgCod," // row[0]
"Hidden," // row[1]
"UsrCod," // row[2]
@ -781,7 +784,7 @@ void Asg_GetDataOfAssignmentByCod (struct Asg_Assignment *Asg)
Gbl.Hierarchy.Crs.CrsCod);
/***** Get data of assignment *****/
Asg_GetDataOfAssignment (Asg,&mysql_res,NumRows);
Asg_GetDataOfAssignment (Asg,&mysql_res,NumAsgs);
}
else
{
@ -798,12 +801,13 @@ 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",
NumAsgs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get assignment data",
"SELECT AsgCod," // row[0]
"Hidden," // row[1]
"UsrCod," // row[2]
@ -819,7 +823,7 @@ void Asg_GetDataOfAssignmentByFolder (struct Asg_Assignment *Asg)
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,13 +957,14 @@ 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",
NumAsgs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get assignment title and text",
"SELECT Title," // row[0]
"Txt" // row[1]
" FROM asg_assignments"
@ -967,7 +972,7 @@ void Asg_GetNotifAssignment (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
AsgCod);
/***** Result should have a unique row *****/
if (NumRows == 1)
if (NumAsgs == 1)
{
/***** Get row *****/
row = mysql_fetch_row (mysql_res);
@ -1727,11 +1732,12 @@ 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",
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,"
@ -1747,16 +1753,16 @@ static void Asg_GetAndWriteNamesOfGrpsAssociatedToAsg (struct Asg_Assignment *As
/***** 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&nbsp;%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 (", ");
}
}

View File

@ -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,7 +675,8 @@ 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",
Events->Num = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get attendance events",
"SELECT AttCod"
" FROM att_events"
" WHERE CrsCod=%ld"
@ -697,7 +697,8 @@ static void Att_GetListAttEvents (struct Att_Events *Events,
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",
Events->Num = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get attendance events",
"SELECT AttCod"
" FROM att_events"
" WHERE CrsCod=%ld%s"
@ -706,12 +707,10 @@ static void Att_GetListAttEvents (struct Att_Events *Events,
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,7 +764,8 @@ bool Att_GetDataOfAttEventByCod (struct Att_Event *Event)
if (Event->AttCod > 0)
{
/***** Build query *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get attendance event data",
NumAttEvents = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get attendance event data",
"SELECT AttCod," // row[0]
"CrsCod," // row[1]
"Hidden," // row[2]
@ -782,7 +780,7 @@ bool Att_GetDataOfAttEventByCod (struct Att_Event *Event)
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,7 +2234,8 @@ 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",
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",
@ -2572,11 +2571,10 @@ 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"
if (DB_QuerySELECT (&mysql_res,"can not get if a student"
" is already registered in an event",
"SELECT Present," // row[0]
"CommentStd," // row[1]
@ -2585,8 +2583,7 @@ static bool Att_CheckIfUsrIsPresentInAttEventAndGetComments (long AttCod,long Us
" WHERE AttCod=%ld"
" AND UsrCod=%ld",
AttCod,
UsrCod);
if (NumRows)
UsrCod))
{
/* Get row */
row = mysql_fetch_row (mysql_res);

View File

@ -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,13 +134,14 @@ 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",
NumBanners = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get banners",
"SELECT BanCod," // row[0]
"Hidden," // row[1]
"ShortName," // row[2]
@ -150,7 +151,7 @@ void Ban_SeeBanners (void)
" FROM ban_banners"
" WHERE Hidden='N'"
" ORDER BY ShortName");
Ban_GetListBanners (&Banners,&mysql_res,NumRows);
Ban_GetListBanners (&Banners,&mysql_res,NumBanners);
/***** Begin box *****/
Box_BoxBegin (NULL,Txt_Banners,
@ -258,10 +259,11 @@ 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",
NumBanners = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get banners",
"SELECT BanCod," // row[0]
"Hidden," // row[1]
"ShortName," // row[2]
@ -270,7 +272,7 @@ static void Ban_EditBannersInternal (struct Ban_Banners *Banners,
"WWW" // row[5]
" FROM ban_banners"
" ORDER BY ShortName");
Ban_GetListBanners (Banners,&mysql_res,NumRows);
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,7 +360,7 @@ 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",
if (DB_QuerySELECT (&mysql_res,"can not get data of a banner",
"SELECT Hidden," // row[0]
"ShortName," // row[1]
"FullName," // row[2]
@ -369,8 +368,7 @@ void Ban_GetDataOfBannerByCod (struct Ban_Banner *Ban)
"WWW" // row[4]
" FROM ban_banners"
" WHERE BanCod=%ld",
Ban->BanCod);
if (NumRows) // Banner found...
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,7 +1109,8 @@ 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",
NumBanners = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get banners",
"SELECT BanCod," // row[0]
"Hidden," // row[1]
"ShortName," // row[2]
@ -1125,7 +1124,7 @@ void Ban_WriteMenuWithBanners (void)
(unsigned long) (Gbl.StartExecutionTimeUTC /
Cfg_TIME_TO_CHANGE_BANNER),
Cfg_NUMBER_OF_BANNERS);
Ban_GetListBanners (&Banners,&mysql_res,NumRows);
Ban_GetListBanners (&Banners,&mysql_res,NumBanners);
/***** Write all the banners *****/
for (NumBan = 0;

View File

@ -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,7 +325,8 @@ void Bld_GetListBuildings (struct Bld_Buildings *Buildings,
switch (WhichData)
{
case Bld_ALL_DATA:
NumRows = DB_QuerySELECT (&mysql_res,"can not get buildings",
Buildings->Num = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get buildings",
"SELECT BldCod," // row[0]
"ShortName," // row[1]
"FullName," // row[2]
@ -339,7 +339,8 @@ void Bld_GetListBuildings (struct Bld_Buildings *Buildings,
break;
case Bld_ONLY_SHRT_NAME:
default:
NumRows = DB_QuerySELECT (&mysql_res,"can not get buildings",
Buildings->Num = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get buildings",
"SELECT BldCod," // row[0]
"ShortName" // row[1]
" FROM bld_buildings"
@ -350,12 +351,10 @@ void Bld_GetListBuildings (struct Bld_Buildings *Buildings,
}
/***** 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",
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);
/***** Count number of rows in result *****/
if (NumRows) // Building found...
Building->BldCod)) // Building found...
{
/* Get row */
row = mysql_fetch_row (mysql_res);

View File

@ -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"
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);
Gbl.Hierarchy.Crs.CrsCod,
SubQueryStatus);
/***** Begin box *****/
if (ICanEdit)
@ -887,16 +889,16 @@ 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",
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"
@ -966,15 +968,13 @@ 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",
if (DB_QuerySELECT (&mysql_res,"can not get data of a call for exam",
"SELECT CrsCod," // row[ 0]
"Status," // row[ 1]
"CrsFullName," // row[ 2]
@ -992,10 +992,7 @@ static void Cfe_GetDataCallForExamFromDB (struct Cfe_CallsForExams *CallsForExam
"OtherInfo" // row[14]
" FROM cfe_exams"
" WHERE ExaCod=%ld",
ExaCod);
/***** The result of the query must have one row *****/
if (NumExaAnns != 1)
ExaCod) != 1)
Lay_WrongCallForExamExit ();
/***** Get the data of the call for exam *****/

View File

@ -550,12 +550,12 @@ 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",
Gbl.Hierarchy.Ctrs.Num = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get centers",
"SELECT CtrCod," // row[ 0]
"InsCod," // row[ 1]
"PlcCod," // row[ 2]
@ -572,13 +572,10 @@ void Ctr_GetBasicListOfCenters (long InsCod)
" 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,12 +613,12 @@ 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",
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]
@ -663,13 +658,10 @@ void Ctr_GetFullListOfCenters (long 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,7 +711,7 @@ 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",
if (DB_QuerySELECT (&mysql_res,"can not get data of a center",
"SELECT CtrCod," // row[ 0]
"InsCod," // row[ 1]
"PlcCod," // row[ 2]
@ -736,8 +725,7 @@ bool Ctr_GetDataOfCenterByCod (struct Ctr_Center *Ctr)
"WWW" // row[10]
" FROM ctr_centers"
" WHERE CtrCod=%ld",
Ctr->CtrCod);
if (NumRows) // Center found...
Ctr->CtrCod)) // Center found...
{
/* Get row */
row = mysql_fetch_row (mysql_res);

View File

@ -600,13 +600,14 @@ TODO: Salvador Romero Cort
TODO: FIX BUG, URGENT! En las fechas como parámetro Dat_WriteParamsIniEndDates(), por ejemplo al cambiar el color de la gráfica de accesos por día y hora, no se respeta la zona horaria.
*/
#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)

View File

@ -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,10 +190,10 @@ 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);
@ -205,7 +205,7 @@ void Cht_ShowListOfAvailableChatRooms (void)
Crs_GetDataOfCourseByCod (&Crs);
/* Link to the room of this course */
IsLastItemInLevel[2] = (NumRow == NumRows - 1);
IsLastItemInLevel[2] = (NumCrs == NumCrss - 1);
snprintf (ThisRoomCode,sizeof (ThisRoomCode),"CRS_%ld",
Crs.CrsCod);
snprintf (ThisRoomShrtName,sizeof (ThisRoomShrtName),"%s",
@ -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",
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 (NumRows > 0) // If not empty chat rooms found
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);

View File

@ -784,11 +784,12 @@ 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"
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]
@ -801,8 +802,8 @@ static void Con_ComputeConnectedUsrsWithARoleCurrentCrsOneByOne (Rol_Role_t Role
" ORDER BY Dif",
Gbl.Hierarchy.Crs.CrsCod,
(unsigned) Role);
Gbl.Usrs.Connected.NumUsrs += (unsigned) NumRows;
Gbl.Usrs.Connected.NumUsrsToList += (unsigned) NumRows;
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;

View File

@ -753,13 +753,13 @@ 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",
Gbl.Hierarchy.Ctys.Num = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get countries",
"SELECT CtyCod," // row[0]
"Alpha2," // row[1]
"Name_%s" // row[2]
@ -767,12 +767,10 @@ void Cty_GetBasicListOfCountries (void)
" ORDER BY Name_%s",
Lan_STR_LANG_ID[Gbl.Prefs.Language],
Lan_STR_LANG_ID[Gbl.Prefs.Language]);
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 ();
@ -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,7 +865,8 @@ void Cty_GetFullListOfCountries (void)
Lay_NotEnoughMemoryExit ();
/* Query database */
NumRows = DB_QuerySELECT (&mysql_res,"can not get countries",
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[...]
@ -897,12 +893,10 @@ void Cty_GetFullListOfCountries (void)
/* 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;

View File

@ -237,7 +237,7 @@ static void Crs_WriteListMyCoursesToSelectOne (void)
HTM_LI_End ();
/***** Get my institutions in this country *****/
NumInss = (unsigned) Usr_GetInssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,
NumInss = Usr_GetInssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,
Hie.Cty.CtyCod,&mysql_resIns);
for (NumIns = 0;
NumIns < NumInss;
@ -271,7 +271,7 @@ static void Crs_WriteListMyCoursesToSelectOne (void)
HTM_LI_End ();
/***** Get my centers in this institution *****/
NumCtrs = (unsigned) Usr_GetCtrsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,
NumCtrs = Usr_GetCtrsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,
Hie.Ins.InsCod,&mysql_resCtr);
for (NumCtr = 0;
NumCtr < NumCtrs;
@ -305,7 +305,7 @@ static void Crs_WriteListMyCoursesToSelectOne (void)
HTM_LI_End ();
/***** Get my degrees in this center *****/
NumDegs = (unsigned) Usr_GetDegsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,
NumDegs = Usr_GetDegsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,
Hie.Ctr.CtrCod,&mysql_resDeg);
for (NumDeg = 0;
NumDeg < NumDegs;
@ -339,7 +339,7 @@ static void Crs_WriteListMyCoursesToSelectOne (void)
HTM_LI_End ();
/***** Get my courses in this degree *****/
NumCrss = (unsigned) Usr_GetCrssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,
NumCrss = Usr_GetCrssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,
Hie.Deg.DegCod,&mysql_resCrs);
for (NumCrs = 0;
NumCrs < NumCrss;
@ -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,7 +3008,8 @@ 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",
NumCrss = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get old courses",
"SELECT CrsCod"
" FROM crs_last"
" WHERE LastTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)"

View File

@ -32,6 +32,7 @@
#include <stddef.h> // For NULL
#include <stdio.h> // For FILE, vasprintf
#include <stdlib.h> // For free
#include <string.h> // 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);
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);
}
}
/*****************************************************************************/

View File

@ -1125,12 +1125,12 @@ 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",
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]
@ -1145,12 +1145,10 @@ void Deg_GetListDegsInCurrentCtr (void)
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]
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)

View File

@ -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",
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)

View File

@ -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,8 +438,7 @@ 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",
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]
@ -469,8 +467,7 @@ void Dpt_GetDataOfDepartmentByCod (struct Dpt_Department *Dpt)
" 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...
Dpt->DptCod,(unsigned) Rol_TCH)) // Department found...
{
/* Get row */
row = mysql_fetch_row (mysql_res);

View File

@ -274,7 +274,8 @@ 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",
NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get similar users",
"SELECT DISTINCT UsrCod"
" FROM (SELECT DISTINCT UsrCod"
" FROM usr_ids"
@ -294,7 +295,8 @@ static void Dup_ListSimilarUsrs (void)
Gbl.Usrs.Other.UsrDat.Surname2,
Gbl.Usrs.Other.UsrDat.FrstName);
else
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get similar users",
NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get similar users",
"SELECT DISTINCT UsrCod"
" FROM usr_ids"
" WHERE UsrID IN"

View File

@ -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,7 +881,8 @@ 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",
NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get old users",
"SELECT UsrCod"
" FROM (SELECT UsrCod"
" FROM usr_last"
@ -2260,8 +2261,8 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
extern const char *Txt_No_enrolment_requests;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumReqs = 0; // Initialized to avoid warning
unsigned long NumReq;
unsigned NumReqs = 0; // Initialized to avoid warning
unsigned NumReq;
long ReqCod;
struct Deg_Degree Deg;
struct Crs_Course Crs;
@ -2334,7 +2335,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
{
case Rol_TCH:
// Requests in all courses in which I am teacher
NumReqs =
NumReqs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get requests for enrolment",
"SELECT crs_requests.ReqCod," // row[0]
"crs_requests.CrsCod," // row[1]
@ -2354,7 +2355,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
break;
case Rol_DEG_ADM:
// Requests in all degrees administrated by me
NumReqs =
NumReqs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get requests for enrolment",
"SELECT crs_requests.ReqCod," // row[0]
"crs_requests.CrsCod," // row[1]
@ -2375,7 +2376,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
break;
case Rol_CTR_ADM:
// Requests in all centers administrated by me
NumReqs =
NumReqs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get requests for enrolment",
"SELECT crs_requests.ReqCod," // row[0]
"crs_requests.CrsCod," // row[1]
@ -2398,7 +2399,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
break;
case Rol_INS_ADM:
// Requests in all institutions administrated by me
NumReqs =
NumReqs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get requests for enrolment",
"SELECT crs_requests.ReqCod," // row[0]
"crs_requests.CrsCod," // row[1]
@ -2423,7 +2424,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
break;
case Rol_SYS_ADM:
// All requests
NumReqs =
NumReqs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get requests for enrolment",
"SELECT ReqCod," // row[0]
"CrsCod," // row[1]
@ -2445,7 +2446,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
{
case Rol_TCH:
// Requests in courses of this country in which I am teacher
NumReqs =
NumReqs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get requests for enrolment",
"SELECT crs_requests.ReqCod," // row[0]
"crs_requests.CrsCod," // row[1]
@ -2475,7 +2476,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
break;
case Rol_DEG_ADM:
// Requests in degrees of this country administrated by me
NumReqs =
NumReqs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get requests for enrolment",
"SELECT crs_requests.ReqCod," // row[0]
"crs_requests.CrsCod," // row[1]
@ -2505,7 +2506,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
break;
case Rol_CTR_ADM:
// Requests in centers of this country administrated by me
NumReqs =
NumReqs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get requests for enrolment",
"SELECT crs_requests.ReqCod," // row[0]
"crs_requests.CrsCod," // row[1]
@ -2535,7 +2536,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
break;
case Rol_INS_ADM:
// Requests in institutions of this country administrated by me
NumReqs =
NumReqs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get requests for enrolment",
"SELECT crs_requests.ReqCod," // row[0]
"crs_requests.CrsCod," // row[1]
@ -2565,7 +2566,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
break;
case Rol_SYS_ADM:
// Requests in any course of this country
NumReqs =
NumReqs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get requests for enrolment",
"SELECT crs_requests.ReqCod," // row[0]
"crs_requests.CrsCod," // row[1]
@ -2597,7 +2598,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
{
case Rol_TCH:
// Requests in courses of this institution in which I am teacher
NumReqs =
NumReqs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get requests for enrolment",
"SELECT crs_requests.ReqCod," // row[0]
"crs_requests.CrsCod," // row[1]
@ -2625,7 +2626,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
break;
case Rol_DEG_ADM:
// Requests in degrees of this institution administrated by me
NumReqs =
NumReqs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get requests for enrolment",
"SELECT crs_requests.ReqCod," // row[0]
"crs_requests.CrsCod," // row[1]
@ -2653,7 +2654,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
break;
case Rol_CTR_ADM:
// Requests in centers of this institution administrated by me
NumReqs =
NumReqs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get requests for enrolment",
"SELECT crs_requests.ReqCod," // row[0]
"crs_requests.CrsCod," // row[1]
@ -2681,7 +2682,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
case Rol_INS_ADM: // If I am logged as admin of this institution, I can view all the requesters from this institution
case Rol_SYS_ADM:
// Requests in any course of this institution
NumReqs =
NumReqs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get requests for enrolment",
"SELECT crs_requests.ReqCod," // row[0]
"crs_requests.CrsCod," // row[1]
@ -2711,7 +2712,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
{
case Rol_TCH:
// Requests in courses of this center in which I am teacher
NumReqs =
NumReqs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get requests for enrolment",
"SELECT crs_requests.ReqCod," // row[0]
"crs_requests.CrsCod," // row[1]
@ -2737,7 +2738,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
break;
case Rol_DEG_ADM:
// Requests in degrees of this center administrated by me
NumReqs =
NumReqs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get requests for enrolment",
"SELECT crs_requests.ReqCod," // row[0]
"crs_requests.CrsCod," // row[1]
@ -2765,7 +2766,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
case Rol_INS_ADM: // If I am logged as admin of this institution, I can view all the requesters from this center
case Rol_SYS_ADM:
// Request in any course of this center
NumReqs =
NumReqs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get requests for enrolment",
"SELECT crs_requests.ReqCod," // row[0]
"crs_requests.CrsCod," // row[1]
@ -2793,7 +2794,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
{
case Rol_TCH:
// Requests in courses of this degree in which I am teacher
NumReqs =
NumReqs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get requests for enrolment",
"SELECT crs_requests.ReqCod," // row[0]
"crs_requests.CrsCod," // row[1]
@ -2820,7 +2821,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
case Rol_INS_ADM: // If I am logged as admin of this institution, I can view all the requesters from this degree
case Rol_SYS_ADM:
// Requests in any course of this degree
NumReqs =
NumReqs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get requests for enrolment",
"SELECT crs_requests.ReqCod," // row[0]
"crs_requests.CrsCod," // row[1]
@ -2850,7 +2851,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
case Rol_INS_ADM: // If I am logged as admin of this institution, I can view all the requesters from this course
case Rol_SYS_ADM:
// Requests in this course
NumReqs =
NumReqs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get requests for enrolment",
"SELECT ReqCod," // row[0]
"CrsCod," // row[1]
@ -2932,7 +2933,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
/***** Number *****/
HTM_TR_Begin (NULL);
HTM_TD_Begin ("class=\"DAT RT\"");
HTM_UnsignedLong (NumReqs - NumReq);
HTM_Unsigned (NumReqs - NumReq);
HTM_TD_End ();
/***** Link to course *****/

View File

@ -800,7 +800,6 @@ void Exa_GetListExams (struct Exa_Exams *Exams,Exa_Order_t SelectedOrder)
MYSQL_RES *mysql_res;
MYSQL_ROW row;
char *HiddenSubQuery;
unsigned long NumRows = 0; // Initialized to avoid warning
unsigned NumExam;
/***** Free list of exams *****/
@ -829,7 +828,8 @@ void Exa_GetListExams (struct Exa_Exams *Exams,Exa_Order_t SelectedOrder)
}
/***** Get list of exams from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get exams",
Exams->Num = (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]
@ -847,12 +847,11 @@ void Exa_GetListExams (struct Exa_Exams *Exams,Exa_Order_t 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,7 +952,7 @@ void Exa_GetDataOfExamByCod (struct Exa_Exam *Exam)
}
/***** Get exam data from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get exam data",
if (DB_QuerySELECT (&mysql_res,"can not get exam data",
"SELECT ExaCod," // row[0]
"CrsCod," // row[1]
"Hidden," // row[2]
@ -966,8 +962,7 @@ void Exa_GetDataOfExamByCod (struct Exa_Exam *Exam)
"Title" // row[6]
" FROM exa_exams"
" WHERE ExaCod=%ld",
Exam->ExaCod);
if (NumRows) // Exam found...
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",
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);
if (NumRows)
Exam->ExaCod))
{
/* Get row */
row = mysql_fetch_row (mysql_res);
@ -1242,8 +1236,8 @@ 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",
NumMedia = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get media",
"SELECT exa_set_questions.MedCod"
" FROM exa_exams,"
"exa_sets,"

View File

@ -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,10 +252,11 @@ 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",
NumPrints = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get data of an exam print",
"SELECT PrnCod," // row[0]
"SesCod," // row[1]
"UsrCod," // row[2]
@ -270,7 +271,7 @@ void ExaPrn_GetDataOfPrintByPrnCod (struct ExaPrn_Print *Print)
Print->PrnCod);
/***** Get data of print *****/
ExaPrn_GetDataOfPrint (Print,&mysql_res,NumRows);
ExaPrn_GetDataOfPrint (Print,&mysql_res,NumPrints);
}
/*****************************************************************************/
@ -280,10 +281,11 @@ 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",
NumPrints = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get data of an exam print",
"SELECT PrnCod," // row[0]
"SesCod," // row[1]
"UsrCod," // row[2]
@ -300,7 +302,7 @@ void ExaPrn_GetDataOfPrintBySesCodAndUsrCod (struct ExaPrn_Print *Print)
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);

View File

@ -427,14 +427,15 @@ 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",
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"
@ -516,14 +517,15 @@ 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",
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"
@ -905,8 +907,8 @@ 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",
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"

View File

@ -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,8 +301,7 @@ void ExaSes_GetDataOfSessionByCod (struct ExaSes_Session *Session)
}
/***** Get exam data session from database *****/
NumRows = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get sessions",
if (DB_QuerySELECT (&mysql_res,"can not get sessions",
"SELECT SesCod," // row[0]
"ExaCod," // row[1]
"Hidden," // row[2]
@ -320,8 +318,7 @@ void ExaSes_GetDataOfSessionByCod (struct ExaSes_Session *Session)
" FROM exa_exams"
" WHERE CrsCod='%ld')",
Session->SesCod,
Gbl.Hierarchy.Crs.CrsCod);
if (NumRows) // Session found...
Gbl.Hierarchy.Crs.CrsCod)) // Session found...
/* Get exam session data from row */
ExaSes_GetSessionDataFromRow (mysql_res,Session);
else
@ -662,11 +659,12 @@ 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",
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,"
@ -682,16 +680,16 @@ static void ExaSes_GetAndWriteNamesOfGrpsAssociatedToSession (const struct ExaSe
/***** 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&nbsp;%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 (", ");
}
}

View File

@ -1394,8 +1394,8 @@ static void Fig_GetAndShowInssOrderedByNumUsrsWhoClaimToBelongToThem (void)
switch (Gbl.Scope.Current)
{
case Hie_Lvl_SYS:
NumInss =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions",
NumInss = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get institutions",
"SELECT InsCod," // row[0]
"COUNT(*) AS N" // row[1]
" FROM usr_data"
@ -1404,8 +1404,8 @@ static void Fig_GetAndShowInssOrderedByNumUsrsWhoClaimToBelongToThem (void)
" ORDER BY N DESC");
break;
case Hie_Lvl_CTY:
NumInss =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions",
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"
@ -1419,8 +1419,8 @@ static void Fig_GetAndShowInssOrderedByNumUsrsWhoClaimToBelongToThem (void)
case Hie_Lvl_CTR:
case Hie_Lvl_DEG:
case Hie_Lvl_CRS:
NumInss =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions",
NumInss = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get institutions",
"SELECT InsCod," // row[0]
"COUNT(*) AS N" // row[1]
" FROM usr_data"
@ -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\"");

View File

@ -2678,9 +2678,9 @@ 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]
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);
@ -2722,12 +2722,13 @@ 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",
NumFolders = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get folders of assignments",
"SELECT Folder" // row[0]
" FROM asg_assignments"
" WHERE CrsCod=%ld"
@ -2745,12 +2746,13 @@ static void Brw_CreateFoldersAssignmentsIfNotExist (long ZoneUsrCod)
" WHERE grp_users.UsrCod=%ld"
" AND asg_groups.GrpCod=grp_users.GrpCod)"
")",
Gbl.Hierarchy.Crs.CrsCod,ZoneUsrCod);
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,7 +5211,8 @@ static void Brw_GetAndUpdateDateLastAccFileBrowser (void)
default:
return;
}
NumRows = DB_QuerySELECT (&mysql_res,"can not get date-time"
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"
@ -5256,12 +5259,12 @@ 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"
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"
@ -5271,9 +5274,9 @@ static long Brw_GetGrpLastAccZone (const char *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,23 +11713,18 @@ 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++)
NumGrps = Grp_GetGrpsOfType (GrpTypCod,&mysql_res);
for (NumGrp = 0;
NumGrp < NumGrps;
NumGrp++)
{
/* Get next group */
row = mysql_fetch_row (mysql_res);
/* Group code is in row[0] */
if (sscanf (row[0],"%ld",&GrpCod) != 1)
Lay_ShowErrorAndExit ("Wrong group code.");
GrpCod = DB_GetNextCode (mysql_res);
/* Remove file zones of this group */
Brw_RemoveGrpZones (Gbl.Hierarchy.Crs.CrsCod,GrpCod);
@ -11783,28 +11781,28 @@ 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 (NumRow = 0;
NumRow < NumRows;
NumRow++)
for (NumCrs = 0;
NumCrs < NumCrss;
NumCrs++)
{
/* 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 *****/
DB_FreeMySQLResult (&mysql_res);

View File

@ -77,7 +77,7 @@ extern struct Globals Gbl;
/***************************** Private prototypes ****************************/
/*****************************************************************************/
static unsigned long Fol_GetUsrsToFollow (unsigned long MaxUsrsToShow,
static unsigned Fol_GetUsrsToFollow (unsigned MaxUsrsToShow,
Fol_WhichUsersSuggestToFollowThem_t WhichUsersSuggestToFollowThem,
MYSQL_RES **mysql_res);
@ -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,7 +262,7 @@ void Fol_SuggestUsrsToFollowMainZoneOnRightColumn (void)
/*************************** Get users to follow *****************************/
/*****************************************************************************/
static unsigned long Fol_GetUsrsToFollow (unsigned long MaxUsrsToShow,
static unsigned Fol_GetUsrsToFollow (unsigned MaxUsrsToShow,
Fol_WhichUsersSuggestToFollowThem_t WhichUsersSuggestToFollowThem,
MYSQL_RES **mysql_res)
{
@ -311,7 +311,8 @@ 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",
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get users to follow",
"SELECT DISTINCT UsrCod FROM"
" ("
/***** Likely known users *****/
@ -370,7 +371,7 @@ static unsigned long Fol_GetUsrsToFollow (unsigned long MaxUsrsToShow,
" (SELECT FollowedCod FROM usr_follow"
" WHERE FollowerCod=%ld)"
// Get only MaxUsrsToShow * 3 users
" ORDER BY RAND() LIMIT %lu"
" ORDER BY RAND() LIMIT %u"
")"
" UNION "
"("
@ -396,12 +397,12 @@ static unsigned long Fol_GetUsrsToFollow (unsigned long MaxUsrsToShow,
" 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"
" LIMIT %u"
")"
") AS UsrsToFollow"
// Get only MaxUsrsToShow users
" ORDER BY RAND()"
" LIMIT %lu",
" LIMIT %u",
Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
@ -675,15 +676,16 @@ 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",
NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get followed users",
"SELECT FollowedCod" // row[0]
" FROM usr_follow"
" WHERE FollowerCod=%ld"
@ -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,7 +766,8 @@ 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",
NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get followers",
"SELECT FollowerCod"
" FROM usr_follow"
" WHERE FollowedCod=%ld"

View File

@ -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,7 +1055,8 @@ 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",
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"
@ -1064,7 +1064,6 @@ static void For_ShowPostsOfAThread (struct For_Forums *Forums,
" 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,9 +1685,8 @@ 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
NumCtrs = Usr_GetCtrsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,
InsCod,&mysql_resCtr);
for (NumCtr = 0;
NumCtr < NumCtrs;
NumCtr++)
@ -1726,9 +1720,9 @@ static void For_ShowForumList (struct For_Forums *Forums)
IsLastItemInLevel) > 0)
{
/* Get my courses in this degree from database */
if ((NumCrss = Usr_GetCrssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,
NumCrss = Usr_GetCrssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,
DegCod,
&mysql_resCrs)) > 0) // Courses found in this degree
&mysql_resCrs);
for (NumCrs = 0;
NumCrs < NumCrss;
NumCrs++)
@ -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",
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",
" AND for_threads.ForumType=%u"
"%s",
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Forum->Type,SubQuery);
if (NumRows)
(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",
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 if last time I read this thread exists in database *****/
if (NumRows)
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",
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"
" WHERE for_threads.ForumType=%u"
"%s"
" AND for_threads.FirstPstCod=for_posts.PstCod"
" ORDER BY for_posts.CreatTime DESC",
(unsigned) Forums->Forum.Type,SubQuery);
(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",
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"
" WHERE for_threads.ForumType=%u"
"%s"
" AND for_threads.LastPstCod=for_posts.PstCod"
" ORDER BY for_posts.CreatTime DESC",
(unsigned) Forums->Forum.Type,SubQuery);
(unsigned) Forums->Forum.Type,
SubQuery);
break;
default: // Impossible
return;
@ -3654,12 +3650,10 @@ 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",
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]
@ -3673,10 +3667,7 @@ static void For_GetThreadData (struct For_Thread *Thr)
" 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)
Thr->ThrCod) != 1)
Lay_ShowErrorAndExit ("Error when getting data of a thread of a forum.");
row = mysql_fetch_row (mysql_res);

View File

@ -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,7 +894,8 @@ 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",
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]
@ -913,12 +913,11 @@ void Gam_GetListGames (struct Gam_Games *Games,Gam_Order_t 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,10 +1014,9 @@ 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",
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]
@ -1034,8 +1030,7 @@ void Gam_GetDataOfGameByCod (struct Gam_Game *Game)
" WHERE gam_games.GamCod=%ld"
" AND gam_games.CrsCod='%ld'", // Extra check
Game->GamCod,
Gbl.Hierarchy.Crs.CrsCod);
if (NumRows) // Game found...
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",
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);
if (NumRows)
Game->GamCod))
{
/* Get row */
row = mysql_fetch_row (mysql_res);

View File

@ -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,11 +3079,12 @@ 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",
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]
@ -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,7 +3189,7 @@ 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",
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]
@ -3212,9 +3206,7 @@ void Grp_GetDataOfGroupByCod (struct GroupData *GrpDat)
" ON grp_groups.RooCod=roo_rooms.RooCod"
" WHERE grp_groups.GrpCod=%ld"
" AND grp_groups.GrpTypCod=grp_types.GrpTypCod",
GrpDat->GrpCod);
if (NumRows == 1)
GrpDat->GrpCod) == 1)
{
/***** Get data of group *****/
row = mysql_fetch_row (mysql_res);
@ -3735,14 +3727,14 @@ 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",
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"
@ -3750,19 +3742,20 @@ void Grp_GetNamesGrpsStdBelongsTo (long GrpTypCod,long UsrCod,char *GroupNames)
" AND grp_groups.GrpCod=grp_users.GrpCod"
" AND grp_users.UsrCod=%ld"
" ORDER BY grp_groups.GrpName",
GrpTypCod,UsrCod);
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);
}

View File

@ -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);

View File

@ -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,8 +535,8 @@ 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",
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"
@ -551,9 +551,9 @@ bool Inf_GetIfIMustReadAnyCrsInfoInThisCrs (void)
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",
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]);
/***** The result of the query must have one row or none *****/
if (NumRows == 1)
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);
@ -1700,9 +1691,6 @@ void Inf_GetInfoTxtFromDB (long CrsCod,Inf_InfoType_t InfoType,
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
if (NumRows > 1)
Lay_ShowErrorAndExit ("Error when getting info text.");
}
/*****************************************************************************/

View File

@ -628,12 +628,12 @@ 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",
Gbl.Hierarchy.Inss.Num = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get institutions",
"SELECT InsCod," // row[0]
"CtyCod," // row[1]
"Status," // row[2]
@ -646,13 +646,10 @@ void Ins_GetBasicListOfInstitutions (long CtyCod)
" 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,13 +689,13 @@ 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",
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]
@ -734,13 +728,10 @@ void Ins_GetFullListOfInstitutions (long 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);

View File

@ -287,14 +287,14 @@ 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",
Gbl.Links.Num = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get institutional links",
"SELECT LnkCod," // row[0]
"ShortName," // row[1]
"FullName," // row[2]
@ -302,12 +302,11 @@ void Lnk_GetListLinks (void)
" 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",
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);
if (NumRows) // Link found...
Lnk->LnkCod)) // Link found...
{
/* Get row */
row = mysql_fetch_row (mysql_res);

View File

@ -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,7 +265,8 @@ void Log_GetAndShowLastClicks (void)
struct Hie_Hierarchy Hie;
/***** Get last clicks from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get last clicks",
NumClicks = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get last clicks",
"SELECT LogCod," // row[0]
"ActCod," // row[1]
"UNIX_TIMESTAMP()-"
@ -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);

View File

@ -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,7 +287,8 @@ static void Mai_GetListMailDomainsAllowedForNotif (void)
" FROM T1");
/***** Get mail domains from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get mail domains",
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]
@ -301,12 +307,11 @@ static void Mai_GetListMailDomainsAllowedForNotif (void)
" 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",
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);
if (NumRows) // Mail found...
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",
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);
if (NumRows == 0)
UsrDat->UsrCod) == 0)
{
UsrDat->Email[0] = '\0';
UsrDat->EmailConfirmed = false;

View File

@ -169,13 +169,12 @@ 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"
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]
@ -191,10 +190,7 @@ static void Mrk_GetNumRowsHeaderAndFooter (struct MarksProperties *Marks)
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)
Gbl.FileBrowser.FilFolLnk.Full) == 1)
{
/***** Get number of header and footer rows *****/
row = mysql_fetch_row (mysql_res);

View File

@ -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,11 +765,12 @@ 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",
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,"
@ -784,16 +785,16 @@ static void Mch_GetAndWriteNamesOfGrpsAssociatedToMatch (const struct Mch_Match
/***** 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&nbsp;%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 (", ");
}
}

View File

@ -393,14 +393,15 @@ 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",
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,"
@ -482,14 +483,15 @@ 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",
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,"

View File

@ -267,7 +267,8 @@ 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",
NumRows = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get media",
"SELECT Type," // row[0]
"Name," // row[1]
"URL," // row[2]

View File

@ -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",
if (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)
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,7 +2240,8 @@ 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",
NumMsgs = (unsigned)
DB_QuerySELECT (mysql_res,"can not get messages",
"SELECT MsgCod"
" FROM msg_content"
" WHERE MsgCod IN"
@ -2255,7 +2252,8 @@ static unsigned long Msg_GetSentOrReceivedMsgs (const struct Msg_Messages *Messa
SubQuery,
Messages->FilterContent);
else
NumMsgs = DB_QuerySELECT (mysql_res,"can not get messages",
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);
@ -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,11 +3038,12 @@ 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",
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]
@ -3055,7 +3054,8 @@ static void Msg_GetMsgSntData (long MsgCod,long *CrsCod,long *UsrCod,
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",
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]
@ -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",
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) == 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);
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,15 +3141,13 @@ 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",
/***** 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"
@ -3173,32 +3155,21 @@ static void Msg_GetStatusOfSentMsg (long MsgCod,bool *Expanded)
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 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"
/***** 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]
@ -3207,10 +3178,7 @@ static void Msg_GetStatusOfReceivedMsg (long MsgCod,bool *Open,bool *Replied,boo
" WHERE MsgCod=%ld"
" AND UsrCod=%ld",
MsgCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
/***** Result should have a unique row *****/
if (NumRows != 1)
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,8 +3749,8 @@ 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",
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]

View File

@ -435,13 +435,13 @@ 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
{
/***** Trivial check: if already filled, nothing to do *****/
if (UsrDat->Roles.InCrss >= 0)
return;
/***** 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",
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",
@ -457,7 +457,6 @@ void Rol_GetRolesInAllCrssIfNotYetGot (struct UsrData *UsrDat)
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
}
/*****************************************************************************/
/********************** Get role from unsigned string ************************/
@ -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]
return DB_QuerySELECTRole ("can not get requested role",
"SELECT Role"
" 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;
Gbl.Hierarchy.Crs.CrsCod,
UsrCod);
}
/*****************************************************************************/

View File

@ -704,19 +704,21 @@ 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"
"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,"
@ -730,17 +732,19 @@ static unsigned Sch_SearchOpenDocumentsInDB (const char *RangeQuery)
" 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"
// 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,"
@ -754,16 +758,19 @@ static unsigned Sch_SearchOpenDocumentsInDB (const char *RangeQuery)
" 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"
// 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,"
@ -778,17 +785,19 @@ static unsigned Sch_SearchOpenDocumentsInDB (const char *RangeQuery)
" 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"
// 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,"
@ -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,19 +908,22 @@ 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"
"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,"
@ -927,17 +942,20 @@ static unsigned Sch_SearchDocumentsInMyCoursesInDB (const char *RangeQuery)
" 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"
// 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,"
@ -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,19 +1034,22 @@ 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"
"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,"
@ -1041,17 +1063,20 @@ static unsigned Sch_SearchMyDocumentsInDB (const char *RangeQuery)
" 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"
// 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,"
@ -1065,17 +1090,20 @@ static unsigned Sch_SearchMyDocumentsInDB (const char *RangeQuery)
" 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"
// 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,"
@ -1091,17 +1119,20 @@ static unsigned Sch_SearchMyDocumentsInDB (const char *RangeQuery)
" 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"
// 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,"
@ -1118,17 +1149,20 @@ static unsigned Sch_SearchMyDocumentsInDB (const char *RangeQuery)
" 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"
// 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,"
@ -1149,17 +1183,20 @@ static unsigned Sch_SearchMyDocumentsInDB (const char *RangeQuery)
" 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"
// 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"

View File

@ -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",
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);
/***** 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 <strong>%s</strong> too large,"
" it exceed the maximum allowed size (%lu bytes).",
ParamName,(unsigned long) MaxBytes);
Lay_ShowErrorAndExit (ErrorTxt);
}
}
/*****************************************************************************/

View File

@ -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]);

View File

@ -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]
DB_QuerySELECTString (Comments,sizeof (Comments) - 1,
"can not get log comments",
"SELECT Comments"
" FROM log_comments"
" WHERE LogCod=%ld",
LogCod))
{
/***** Get and write comments *****/
row = mysql_fetch_row (mysql_res);
HTM_Txt (row[0]);
}
LogCod);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** Write comments *****/
if (Comments[0])
HTM_Txt (Comments);
}
/*****************************************************************************/

View File

@ -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]
/***** Get question index from database *****/
return DB_QuerySELECTUnsigned ("can not get question index",
"SELECT QstInd"
" 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;
}
/*****************************************************************************/

View File

@ -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");

View File

@ -1355,11 +1355,12 @@ 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",
NumRows = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get configuration of test",
"SELECT Pluggable" // row[0]
" FROM tst_config"
" WHERE CrsCod=%ld",
@ -2908,10 +2909,11 @@ 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",
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"
@ -2919,7 +2921,8 @@ unsigned long Tst_GetTagsQst (long QstCod,MYSQL_RES **mysql_res)
" AND tst_question_tags.TagCod=tst_tags.TagCod"
" AND tst_tags.CrsCod=%ld"
" ORDER BY tst_question_tags.TagInd",
QstCod,Gbl.Hierarchy.Crs.CrsCod);
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]
DB_QuerySELECTString (StrAnsTypeDB,sizeof (StrAnsTypeDB) - 1,
"can not get the type of a question",
"SELECT AnsType"
" 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;
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,15 +4042,16 @@ 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)
if (StrAnsTypeDB != NULL)
if (StrAnsTypeDB[0])
for (AnsType = (Tst_AnswerType_t) 0;
AnsType <= (Tst_AnswerType_t) (Tst_NUM_ANS_TYPES - 1);
AnsType++)
if (!strcmp (StrAnsTypeBD,Tst_StrAnswerTypesDB[AnsType]))
if (!strcmp (StrAnsTypeDB,Tst_StrAnswerTypesDB[AnsType]))
return AnsType;
return Tst_ANS_UNKNOWN;
@ -5223,9 +5217,9 @@ 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]
NumMedia = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get media",
"SELECT tst_answers.MedCod"
" FROM tst_answers,"
"tst_questions"
" WHERE tst_answers.QstCod=%ld"
@ -5277,9 +5271,9 @@ 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]
NumMedia = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get media",
"SELECT tst_answers.MedCod"
" FROM tst_questions,"
"tst_answers"
" WHERE tst_questions.CrsCod=%ld"

View File

@ -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);

View File

@ -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,"<tag>%s</tag>%s",

View File

@ -872,8 +872,8 @@ 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",
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",
@ -899,8 +899,8 @@ 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",
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",
@ -937,8 +937,8 @@ 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",
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",
@ -962,8 +962,8 @@ 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",
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"
@ -991,8 +991,8 @@ 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",
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",
@ -2067,8 +2067,8 @@ 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",
NumPrints = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get test exams of a user",
"SELECT ExaCod" // row[0]
" FROM tst_exams"
" WHERE CrsCod=%ld"
@ -2752,9 +2752,8 @@ 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",
NumQsts = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get questions of a test exam",
"SELECT QstCod," // row[0]
"Score," // row[1]
"Indexes," // row[2]

View File

@ -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]

View File

@ -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",
if (DB_QuerySELECT (&mysql_res,"can not get user's code",
"SELECT UsrCod"
" FROM usr_data"
" WHERE EncryptedUsrCod='%s'",
UsrDat->EnUsrCod);
if (NumRows != 1)
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,7 +501,8 @@ 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",
NumRows = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get user's data",
"SELECT EncryptedUsrCod," // row[ 0]
"Password," // row[ 1]
"Surname1," // row[ 2]
@ -534,7 +533,8 @@ void Usr_GetUsrDataFromUsrCod (struct UsrData *UsrDat,Usr_GetPrefs_t GetPrefs)
break;
case Usr_GET_PREFS:
default:
NumRows = DB_QuerySELECT (&mysql_res,"can not get user's data",
NumRows = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get user's data",
"SELECT EncryptedUsrCod," // row[ 0]
"Password," // row[ 1]
"Surname1," // row[ 2]
@ -743,12 +743,13 @@ 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",
NumRows = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get user's last data",
"SELECT WhatToSearch," // row[0]
"LastSco," // row[1]
"LastCod," // row[2]
@ -1551,7 +1552,7 @@ 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
NumCtys = Usr_GetCtysFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,&mysql_res);
for (NumCty = 0;
NumCty < NumCtys;
NumCty++)
@ -1598,7 +1599,7 @@ 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
NumInss = Usr_GetInssFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,-1L,&mysql_res);
for (NumIns = 0;
NumIns < NumInss;
NumIns++)
@ -1645,7 +1646,7 @@ 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
NumCtrs = Usr_GetCtrsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,-1L,&mysql_res);
for (NumCtr = 0;
NumCtr < NumCtrs;
NumCtr++)
@ -1692,7 +1693,7 @@ 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
NumDegs = Usr_GetDegsFromUsr (Gbl.Usrs.Me.UsrDat.UsrCod,-1L,&mysql_res);
for (NumDeg = 0;
NumDeg < NumDegs;
NumDeg++)
@ -1764,9 +1765,8 @@ 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",
NumCrss = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get which courses you belong to",
"SELECT CrsCod," // row[0]
"Role," // row[1]
"DegCod" // row[2]
@ -2264,12 +2264,12 @@ 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",
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,"
@ -2285,10 +2285,11 @@ unsigned long Usr_GetInssFromUsr (long UsrCod,long CtyCod,MYSQL_RES **mysql_res)
" AND ins_instits.CtyCod=%ld"
" GROUP BY ins_instits.InsCod"
" ORDER BY ins_instits.ShortName",
UsrCod,CtyCod);
UsrCod,
CtyCod);
else
return DB_QuerySELECT (mysql_res,"can not get the ins_instits"
" a user belongs to",
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,"
@ -2311,12 +2312,12 @@ 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",
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,"
@ -2330,10 +2331,11 @@ unsigned long Usr_GetCtrsFromUsr (long UsrCod,long InsCod,MYSQL_RES **mysql_res)
" AND ctr_centers.InsCod=%ld"
" GROUP BY ctr_centers.CtrCod"
" ORDER BY ctr_centers.ShortName",
UsrCod,InsCod);
UsrCod,
InsCod);
else
return DB_QuerySELECT (mysql_res,"can not check the centers"
" a user belongs to",
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,"
@ -2354,12 +2356,12 @@ 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",
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,"
@ -2371,10 +2373,11 @@ unsigned long Usr_GetDegsFromUsr (long UsrCod,long CtrCod,MYSQL_RES **mysql_res)
" AND deg_degrees.CtrCod=%ld"
" GROUP BY deg_degrees.DegCod"
" ORDER BY deg_degrees.ShortName",
UsrCod,CtrCod);
UsrCod,
CtrCod);
else
return DB_QuerySELECT (mysql_res,"can not check the degrees"
" a user belongs to",
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,"
@ -2393,12 +2396,12 @@ 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",
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]
@ -2408,10 +2411,11 @@ unsigned long Usr_GetCrssFromUsr (long UsrCod,long DegCod,MYSQL_RES **mysql_res)
" AND crs_users.CrsCod=crs_courses.CrsCod"
" AND crs_courses.DegCod=%ld"
" ORDER BY crs_courses.ShortName",
UsrCod,DegCod);
UsrCod,
DegCod);
else // All the courses
return DB_QuerySELECT (mysql_res,"can not get the courses"
" a user belongs to",
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]
@ -5499,8 +5503,8 @@ 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",
if ((Gbl.Usrs.LstUsrs[Role].NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get list of users",
"%s",
Query)))
{
@ -7757,11 +7761,12 @@ 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",
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"
@ -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,8 +7874,8 @@ 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",
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"
@ -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,7 +7983,8 @@ 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"
NumRows = (unsigned)
DB_QuerySELECT (&mysql_res,"can not check if listing of users"
" must show photos",
"SELECT ListWithPhotos" // row[0]
" FROM crs_user_settings"

View File

@ -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);