Version 20.57: Apr 05, 2021 Optimizations in database selects.

This commit is contained in:
acanas 2021-04-05 23:45:24 +02:00
parent 444bf9c76b
commit db17a4465c
39 changed files with 651 additions and 907 deletions

View File

@ -102,14 +102,15 @@ void ID_GetListIDsFromUsrCod (struct UsrData *UsrDat)
/***** Get user's IDs from database *****/
// First the confirmed (Confirmed == 'Y')
// Then the unconfirmed (Confirmed == 'N')
NumIDs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get user's IDs",
"SELECT UsrID," // row[0]
"Confirmed" // row[1]
" FROM usr_ids"
" WHERE UsrCod=%ld"
" ORDER BY Confirmed DESC,"
"UsrID",
UsrDat->UsrCod);
NumIDs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get user's IDs",
"SELECT UsrID," // row[0]
"Confirmed" // row[1]
" FROM usr_ids"
" WHERE UsrCod=%ld"
" ORDER BY Confirmed DESC,"
"UsrID",
UsrDat->UsrCod);
if (NumIDs)
{
/***** Allocate space for the list *****/
@ -182,7 +183,6 @@ unsigned ID_GetListUsrCodsFromUsrID (struct UsrData *UsrDat,
char *SubQueryAllUsrs = NULL;
char SubQueryOneUsr[1 + ID_MAX_BYTES_USR_ID + 1 + 1];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
size_t MaxLength;
unsigned NumID;
unsigned NumUsr;
@ -216,31 +216,31 @@ unsigned ID_GetListUsrCodsFromUsrID (struct UsrData *UsrDat,
{
// Get user's code if I have written the correct password
// or if password in database is empty (new user)
ListUsrCods->NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get user's codes",
"SELECT DISTINCT(usr_ids.UsrCod)"
" FROM usr_ids,"
"usr_data"
" WHERE usr_ids.UsrID IN (%s)"
"%s"
" AND usr_ids.UsrCod=usr_data.UsrCod"
" AND (usr_data.Password='%s'"
" OR usr_data.Password='')",
SubQueryAllUsrs,
OnlyConfirmedIDs ? " AND usr_ids.Confirmed='Y'" :
"",
EncryptedPassword);
ListUsrCods->NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get user's codes",
"SELECT DISTINCT(usr_ids.UsrCod)"
" FROM usr_ids,"
"usr_data"
" WHERE usr_ids.UsrID IN (%s)"
"%s"
" AND usr_ids.UsrCod=usr_data.UsrCod"
" AND (usr_data.Password='%s'"
" OR usr_data.Password='')",
SubQueryAllUsrs,
OnlyConfirmedIDs ? " AND usr_ids.Confirmed='Y'" :
"",
EncryptedPassword);
}
else
ListUsrCods->NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get user's codes",
"SELECT DISTINCT(UsrCod)"
" FROM usr_ids"
" WHERE UsrID IN (%s)"
"%s",
SubQueryAllUsrs,
OnlyConfirmedIDs ? " AND Confirmed='Y'" :
"");
ListUsrCods->NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get user's codes",
"SELECT DISTINCT(UsrCod)"
" FROM usr_ids"
" WHERE UsrID IN (%s)"
"%s",
SubQueryAllUsrs,
OnlyConfirmedIDs ? " AND Confirmed='Y'" :
"");
/***** Free memory for subquery string *****/
free (SubQueryAllUsrs);
@ -255,11 +255,8 @@ unsigned ID_GetListUsrCodsFromUsrID (struct UsrData *UsrDat,
for (NumUsr = 0;
NumUsr < ListUsrCods->NumUsrs;
NumUsr++)
{
/***** Get user's code *****/
row = mysql_fetch_row (mysql_res);
ListUsrCods->Lst[NumUsr] = Str_ConvertStrCodToLongCod (row[0]);
}
/* Get user's code */
ListUsrCods->Lst[NumUsr] = DB_GetNextCode (mysql_res);
UsrDat->UsrCod = ListUsrCods->Lst[0]; // The first user found
}
else // ListUsrCods->NumUsrs == 0

View File

@ -102,7 +102,6 @@ void MFU_GetMFUActions (struct MFU_ListMFUActions *ListMFUActions,unsigned MaxAc
{
extern Act_Action_t Act_FromActCodToAction[1 + Act_MAX_ACTION_COD];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
unsigned long NumRow;
long ActCod;
@ -110,7 +109,7 @@ void MFU_GetMFUActions (struct MFU_ListMFUActions *ListMFUActions,unsigned MaxAc
/***** Get most frequently used actions *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get most frequently used actions",
"SELECT ActCod" // row[0]
"SELECT ActCod"
" FROM act_frequent"
" WHERE UsrCod=%ld"
" ORDER BY Score DESC,"
@ -122,10 +121,8 @@ void MFU_GetMFUActions (struct MFU_ListMFUActions *ListMFUActions,unsigned MaxAc
NumRow < NumRows && ListMFUActions->NumActions < MaxActionsShown;
NumRow++)
{
row = mysql_fetch_row (mysql_res);
/* Get action code (row[0]) */
ActCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get action code */
ActCod = DB_GetNextCode (mysql_res);
if (ActCod >= 0 && ActCod <= Act_MAX_ACTION_COD)
if ((Action = Act_FromActCodToAction[ActCod]) >= 0)
if (Act_GetIndexInMenu (Action) >= 0) // MFU actions must be only actions shown on menu (database could contain wrong action numbers)
@ -145,7 +142,6 @@ Act_Action_t MFU_GetMyLastActionInCurrentTab (void)
{
extern Act_Action_t Act_FromActCodToAction[1 + Act_MAX_ACTION_COD];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumActions;
unsigned NumAct;
long ActCod;
@ -157,7 +153,7 @@ Act_Action_t MFU_GetMyLastActionInCurrentTab (void)
/***** Get my most frequently used actions *****/
NumActions = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get the most frequently used actions",
"SELECT ActCod" // row[0]
"SELECT ActCod"
" FROM act_frequent"
" WHERE UsrCod=%ld"
" ORDER BY LastClick DESC,"
@ -169,10 +165,8 @@ Act_Action_t MFU_GetMyLastActionInCurrentTab (void)
NumAct < NumActions;
NumAct++)
{
row = mysql_fetch_row (mysql_res);
/* Get action code (row[0]) */
ActCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get action code */
ActCod = DB_GetNextCode (mysql_res);
if (ActCod >= 0 && ActCod <= Act_MAX_ACTION_COD)
if ((Action = Act_FromActCodToAction[ActCod]) >= 0)
if (Act_GetTab (Act_GetSuperAction (Action)) == Gbl.Action.Tab)

View File

@ -2237,7 +2237,6 @@ void Ctr_ListCtrsFound (MYSQL_RES **mysql_res,unsigned NumCtrs)
{
extern const char *Txt_center;
extern const char *Txt_centers;
MYSQL_ROW row;
unsigned NumCtr;
struct Ctr_Center Ctr;
@ -2262,10 +2261,7 @@ void Ctr_ListCtrsFound (MYSQL_RES **mysql_res,unsigned NumCtrs)
NumCtr++)
{
/* Get next center */
row = mysql_fetch_row (*mysql_res);
/* Get center code (row[0]) */
Ctr.CtrCod = Str_ConvertStrCodToLongCod (row[0]);
Ctr.CtrCod = DB_GetNextCode (*mysql_res);
/* Get data of center */
Ctr_GetDataOfCenterByCod (&Ctr);

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.56.1 (2021-04-04)"
#define Log_PLATFORM_VERSION "SWAD 20.57 (2021-04-05)"
#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.57: Apr 05, 2021 Optimizations in database selects. (309041 lines)
Version 20.56.1: Apr 04, 2021 Optimizations in database selects. (309252 lines)
Version 20.56: Apr 04, 2021 Optimizations in database selects. (309296 lines)
Version 20.55: Apr 04, 2021 Optimizations in database selects. (309500 lines)

View File

@ -2090,7 +2090,6 @@ void Cty_ListCtysFound (MYSQL_RES **mysql_res,unsigned NumCtys)
{
extern const char *Txt_country;
extern const char *Txt_countries;
MYSQL_ROW row;
unsigned NumCty;
struct Cty_Countr Cty;
@ -2115,10 +2114,7 @@ void Cty_ListCtysFound (MYSQL_RES **mysql_res,unsigned NumCtys)
NumCty++)
{
/* Get next country */
row = mysql_fetch_row (*mysql_res);
/* Get country code (row[0]) */
Cty.CtyCod = Str_ConvertStrCodToLongCod (row[0]);
Cty.CtyCod = DB_GetNextCode (*mysql_res);
/* Get data of country */
Cty_GetDataOfCountryByCod (&Cty);

View File

@ -2136,7 +2136,6 @@ void Deg_ListDegsFound (MYSQL_RES **mysql_res,unsigned NumDegs)
{
extern const char *Txt_degree;
extern const char *Txt_degrees;
MYSQL_ROW row;
unsigned NumDeg;
struct Deg_Degree Deg;
@ -2161,10 +2160,7 @@ void Deg_ListDegsFound (MYSQL_RES **mysql_res,unsigned NumDegs)
NumDeg++)
{
/* Get next degree */
row = mysql_fetch_row (*mysql_res);
/* Get degree code (row[0]) */
Deg.DegCod = Str_ConvertStrCodToLongCod (row[0]);
Deg.DegCod = DB_GetNextCode (*mysql_res);
/* Get data of degree */
Deg_GetDataOfDegreeByCod (&Deg);

View File

@ -1375,7 +1375,7 @@ int Ind_GetNumIndicatorsCrsFromDB (long CrsCod)
/***** Get number of indicators of a course from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get number of indicators",
"SELECT NumIndicators"
"SELECT NumIndicators" // row[0]
" FROM crs_courses"
" WHERE CrsCod=%ld",
CrsCod))
@ -1492,10 +1492,10 @@ static unsigned long Ind_GetNumFilesInDocumZonesOfCrsFromDB (long CrsCod)
/***** Get number of files in document zones of a course from database *****/
DB_QuerySELECT (&mysql_res,"can not get the number of files",
"SELECT"
" (SELECT COALESCE(SUM(NumFiles),0)"
" (SELECT COALESCE(SUM(NumFiles),0)" // row[0]
" FROM brw_sizes"
" WHERE FileBrowser=%u AND Cod=%ld) +"
" (SELECT COALESCE(SUM(brw_sizes.NumFiles),0)"
" (SELECT COALESCE(SUM(brw_sizes.NumFiles),0)" // row[0]
" FROM grp_types,"
"grp_groups,"
"brw_sizes"
@ -1535,10 +1535,10 @@ static unsigned long Ind_GetNumFilesInShareZonesOfCrsFromDB (long CrsCod)
/***** Get number of files in document zones of a course from database *****/
DB_QuerySELECT (&mysql_res,"can not get the number of files",
"SELECT"
" (SELECT COALESCE(SUM(NumFiles),0)"
" (SELECT COALESCE(SUM(NumFiles),0)" // row[0]
" FROM brw_sizes"
" WHERE FileBrowser=%u AND Cod=%ld) +"
" (SELECT COALESCE(SUM(brw_sizes.NumFiles),0)"
" (SELECT COALESCE(SUM(brw_sizes.NumFiles),0)" // row[0]
" FROM grp_types,"
"grp_groups,"
"brw_sizes"
@ -1577,7 +1577,7 @@ static unsigned long Ind_GetNumFilesInAssigZonesOfCrsFromDB (long CrsCod)
/***** Get number of files in document zones of a course from database *****/
DB_QuerySELECT (&mysql_res,"can not get the number of files",
"SELECT COALESCE(SUM(NumFiles),0)"
"SELECT COALESCE(SUM(NumFiles),0)" // row[0]
" FROM brw_sizes"
" WHERE FileBrowser=%u"
" AND Cod=%ld",
@ -1610,7 +1610,7 @@ static unsigned long Ind_GetNumFilesInWorksZonesOfCrsFromDB (long CrsCod)
/***** Get number of files in document zones of a course from database *****/
DB_QuerySELECT (&mysql_res,"can not get the number of files",
"SELECT COALESCE(SUM(NumFiles),0)"
"SELECT COALESCE(SUM(NumFiles),0)" // row[0]
" FROM brw_sizes"
" WHERE FileBrowser=%u"
" AND Cod=%ld",

View File

@ -537,7 +537,7 @@ bool Inf_GetIfIMustReadAnyCrsInfoInThisCrs (void)
/***** Get info types where students must read info *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get if you must read"
" any course info",
"SELECT InfoType"
"SELECT InfoType" // row[0]
" FROM crs_info_src"
" WHERE CrsCod=%ld"
" AND MustBeRead='Y'"
@ -1467,7 +1467,7 @@ Inf_InfoSrc_t Inf_GetInfoSrcFromDB (long CrsCod,Inf_InfoType_t InfoType)
/***** Get info source for a specific type of info from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get info source",
"SELECT InfoSrc"
"SELECT InfoSrc" // row[0]
" FROM crs_info_src"
" WHERE CrsCod=%ld"
" AND InfoType='%s'",
@ -1508,8 +1508,8 @@ void Inf_GetAndCheckInfoSrcFromDB (struct Syl_Syllabus *Syllabus,
/***** Get info source for a specific type of info from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get info source",
"SELECT InfoSrc,"
"MustBeRead"
"SELECT InfoSrc," // row[0]
"MustBeRead" // row[1]
" FROM crs_info_src"
" WHERE CrsCod=%ld"
" AND InfoType='%s'",
@ -1668,8 +1668,8 @@ void Inf_GetInfoTxtFromDB (long CrsCod,Inf_InfoType_t InfoType,
/***** 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",
"SELECT InfoTxtHTML,"
"InfoTxtMD"
"SELECT InfoTxtHTML," // row[0]
"InfoTxtMD" // row[1]
" FROM crs_info_txt"
" WHERE CrsCod=%ld"
" AND InfoType='%s'",

View File

@ -133,8 +133,8 @@ void Ins_SeeInsWithPendingCtrs (void)
case Rol_INS_ADM:
NumInss = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get institutions with pending centers",
"SELECT ctr_centers.InsCod,"
"COUNT(*)"
"SELECT ctr_centers.InsCod," // row[0]
"COUNT(*)" // row[1]
" FROM ctr_centers,"
"ins_admin,"
"ins_instits"
@ -150,8 +150,8 @@ void Ins_SeeInsWithPendingCtrs (void)
case Rol_SYS_ADM:
NumInss = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get institutions with pending centers",
"SELECT ctr_centers.InsCod,"
"COUNT(*)"
"SELECT ctr_centers.InsCod," // row[0]
"COUNT(*)" // row[1]
" FROM ctr_centers,"
"ins_instits"
" WHERE (ctr_centers.Status & %u)<>0"
@ -899,9 +899,8 @@ void Ins_GetShortNameOfInstitution (struct Ins_Instit *Ins)
/***** 3. Slow: get short name of institution from database *****/
Gbl.Cache.InstitutionShrtName.InsCod = Ins->InsCod;
if (DB_QuerySELECT (&mysql_res,"can not get the short name"
" of an institution",
"SELECT ShortName"
if (DB_QuerySELECT (&mysql_res,"can not get the short name of an institution",
"SELECT ShortName" // row[0]
" FROM ins_instits"
" WHERE InsCod=%ld",
Ins->InsCod) == 1)
@ -1041,8 +1040,8 @@ void Ins_WriteSelectorOfInstitution (void)
/***** Get institutions of selected country from database *****/
NumInss =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get institutions",
"SELECT DISTINCT InsCod,"
"ShortName"
"SELECT DISTINCT InsCod," // row[0]
"ShortName" // row[1]
" FROM ins_instits"
" WHERE CtyCod=%ld"
" ORDER BY ShortName",
@ -2139,7 +2138,6 @@ void Ins_ListInssFound (MYSQL_RES **mysql_res,unsigned NumInss)
{
extern const char *Txt_institution;
extern const char *Txt_institutions;
MYSQL_ROW row;
unsigned NumIns;
struct Ins_Instit Ins;
@ -2164,10 +2162,7 @@ void Ins_ListInssFound (MYSQL_RES **mysql_res,unsigned NumInss)
NumIns++)
{
/* Get next institution */
row = mysql_fetch_row (*mysql_res);
/* Get institution code (row[0]) */
Ins.InsCod = Str_ConvertStrCodToLongCod (row[0]);
Ins.InsCod = DB_GetNextCode (*mysql_res);
/* Get data of institution */
Ins_GetDataOfInstitutionByCod (&Ins);
@ -2247,7 +2242,7 @@ bool Ins_GetIfMapIsAvailable (long InsCod)
/***** Get if any center in current institution has a coordinate set
(coordinates 0, 0 means not set ==> don't show map) *****/
if (DB_QuerySELECT (&mysql_res,"can not get if map is available",
"SELECT EXISTS"
"SELECT EXISTS" // row[0]
"(SELECT *"
" FROM ctr_centers"
" WHERE InsCod=%ld"

View File

@ -278,7 +278,6 @@ static void InsCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom)
static void InsCfg_Map (void)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
struct Coordinates InsAvgCoord;
unsigned Zoom;
unsigned NumCtrs;
@ -321,10 +320,7 @@ static void InsCfg_Map (void)
NumCtr++)
{
/* Get next center */
row = mysql_fetch_row (mysql_res);
/* Get center code (row[0]) */
Ctr.CtrCod = Str_ConvertStrCodToLongCod (row[0]);
Ctr.CtrCod = DB_GetNextCode (mysql_res);
/* Get data of center */
Ctr_GetDataOfCenterByCod (&Ctr);

View File

@ -1087,8 +1087,8 @@ bool Mai_GetEmailFromUsrCod (struct UsrData *UsrDat)
/***** Get current (last updated) user's nickname from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get email address",
"SELECT E_mail,"
"Confirmed"
"SELECT E_mail," // row[0]
"Confirmed" // row[1]
" FROM usr_emails"
" WHERE UsrCod=%ld"
" ORDER BY CreatTime DESC"
@ -1123,43 +1123,22 @@ bool Mai_GetEmailFromUsrCod (struct UsrData *UsrDat)
long Mai_GetUsrCodFromEmail (const char Email[Cns_MAX_BYTES_EMAIL_ADDRESS + 1])
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumUsrs;
long UsrCod = -1L;
/***** Trivial check 1: email should be not null ******/
if (!Email)
return -1L;
if (Email)
if (Email[0])
{
/***** Get user's code from database *****/
/* Check if user code from table usr_emails is also in table usr_data */
NumUsrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get user's code",
"SELECT usr_emails.UsrCod"
" FROM usr_emails,"
"usr_data"
" WHERE usr_emails.E_mail='%s'"
" AND usr_emails.UsrCod=usr_data.UsrCod",
Email);
if (NumUsrs == 0)
/* User not found for this email ==> set user's code to void */
UsrCod = -1L;
else if (NumUsrs == 1) // One user found
{
/* Get row */
row = mysql_fetch_row (mysql_res);
/***** Trivial check 2: email should be not empty ******/
if (!Email[0])
return -1L;
/* Get user's code */
UsrCod = Str_ConvertStrCodToLongCod (row[0]);
}
else // NumRows > 1 ==> impossible, an email can not be reapeated
Lay_ShowErrorAndExit ("Internal error: email is repeated in database.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
return UsrCod;
/***** Get user's code from database *****/
return DB_QuerySELECTCode ("can not get user's code",
"SELECT usr_emails.UsrCod"
" FROM usr_emails,"
"usr_data"
" WHERE usr_emails.E_mail='%s'"
" AND usr_emails.UsrCod=usr_data.UsrCod",
Email);
}
/*****************************************************************************/
@ -1829,7 +1808,7 @@ void Mai_ConfirmEmail (void)
/***** Check user's code and email
and get if email is already confirmed *****/
if (DB_QuerySELECT (&mysql_res,"can not check if email is confirmed",
"SELECT Confirmed"
"SELECT Confirmed" // row[0]
" FROM usr_emails"
" WHERE UsrCod=%ld"
" AND E_mail='%s'",

View File

@ -181,14 +181,10 @@ void Map_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom,
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get latitude (row[0]) */
Coord->Latitude = Map_GetLatitudeFromStr (row[0]);
/* Get longitude (row[1]) */
/* Get latitude (row[0]), longitude (row[1]) and maximum distance (row[2]) */
Coord->Latitude = Map_GetLatitudeFromStr (row[0]);
Coord->Longitude = Map_GetLongitudeFromStr (row[1]);
/* Get maximum distance (row[2]) */
MaxDistance = Str_GetDoubleFromStr (row[2]);
MaxDistance = Str_GetDoubleFromStr (row[2]);
}
else
Coord->Latitude =

View File

@ -770,8 +770,8 @@ static void Mch_GetAndWriteNamesOfGrpsAssociatedToMatch (const struct Mch_Match
/***** Get groups associated to a match from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get groups of a match",
"SELECT grp_types.GrpTypName,"
"grp_groups.GrpName"
"SELECT grp_types.GrpTypName," // row[0]
"grp_groups.GrpName" // row[1]
" FROM mch_groups,"
"grp_groups,"
"grp_types"
@ -2074,7 +2074,7 @@ static void Mch_GetElapsedTimeInQuestion (const struct Mch_Match *Match,
/***** Query database *****/
NumRows = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get elapsed time",
"SELECT ElapsedTime"
"SELECT ElapsedTime" // row[0]
" FROM mch_times"
" WHERE MchCod=%ld"
" AND QstInd=%u",
@ -2101,7 +2101,7 @@ static void Mch_GetElapsedTimeInMatch (const struct Mch_Match *Match,
/***** Query database *****/
NumRows = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get elapsed time",
"SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(ElapsedTime)))"
"SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(ElapsedTime)))" // row[0]
" FROM mch_times"
" WHERE MchCod=%ld",
Match->MchCod);
@ -3505,7 +3505,7 @@ static void Mch_ShowMatchScore (const struct Mch_Match *Match)
/***** Get maximum number of users *****/
if (DB_QuerySELECT (&mysql_res,"can not get max users",
"SELECT MAX(NumUsrs)" // row[1]
"SELECT MAX(NumUsrs)" // row[0]
" FROM (SELECT COUNT(*) AS NumUsrs"
" FROM mch_results"
" WHERE MchCod=%ld"
@ -4115,16 +4115,17 @@ void Mch_GetQstAnsFromDB (long MchCod,long UsrCod,unsigned QstInd,
UsrAnswer->AnsInd = -1; // < 0 ==> no answer selected
/***** Get student's answer *****/
NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get user's answer to a match question",
"SELECT NumOpt," // row[0]
"AnsInd" // row[1]
" FROM mch_answers"
" WHERE MchCod=%ld"
" AND UsrCod=%ld"
" AND QstInd=%u",
MchCod,
UsrCod,
QstInd);
NumRows = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get user's answer to a match question",
"SELECT NumOpt," // row[0]
"AnsInd" // row[1]
" FROM mch_answers"
" WHERE MchCod=%ld"
" AND UsrCod=%ld"
" AND QstInd=%u",
MchCod,
UsrCod,
QstInd);
if (NumRows) // Answer found...
{
row = mysql_fetch_row (mysql_res);

View File

@ -393,7 +393,6 @@ void MchRes_ShowAllMchResultsInGam (void)
static void MchRes_ListAllMchResultsInGam (struct Gam_Games *Games,long GamCod)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumUsrs;
unsigned long NumUsr;
@ -402,7 +401,7 @@ static void MchRes_ListAllMchResultsInGam (struct Gam_Games *Games,long GamCod)
/***** Get all users who have answered any match question in this game *****/
NumUsrs = DB_QuerySELECT (&mysql_res,"can not get users in game",
"SELECT users.UsrCod" // row[0]
"SELECT users.UsrCod"
" FROM (SELECT DISTINCT mch_results.UsrCod AS UsrCod"
" FROM mch_results,"
"mch_matches,"
@ -418,26 +417,20 @@ static void MchRes_ListAllMchResultsInGam (struct Gam_Games *Games,long GamCod)
"usr_data.FirstName",
GamCod,
Gbl.Hierarchy.Crs.CrsCod);
if (NumUsrs)
{
/***** List matches results for each user *****/
for (NumUsr = 0;
NumUsr < NumUsrs;
NumUsr++)
{
row = mysql_fetch_row (mysql_res);
/* Get match code (row[0]) */
if ((Gbl.Usrs.Other.UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0])) > 0)
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,Usr_DONT_GET_PREFS))
if (Usr_CheckIfICanViewTstExaMchResult (&Gbl.Usrs.Other.UsrDat))
{
/***** Show matches results *****/
Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat);
MchRes_ShowMchResults (Games,Usr_OTHER,-1L,GamCod,NULL);
}
}
}
/***** List matches results for each user *****/
for (NumUsr = 0;
NumUsr < NumUsrs;
NumUsr++)
/* Get match code */
if ((Gbl.Usrs.Other.UsrDat.UsrCod = DB_GetNextCode (mysql_res)) > 0)
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,Usr_DONT_GET_PREFS))
if (Usr_CheckIfICanViewTstExaMchResult (&Gbl.Usrs.Other.UsrDat))
{
/***** Show matches results *****/
Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat);
MchRes_ShowMchResults (Games,Usr_OTHER,-1L,GamCod,NULL);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
@ -489,7 +482,6 @@ void MchRes_ShowAllMchResultsInMch (void)
static void MchRes_ListAllMchResultsInMch (struct Gam_Games *Games,long MchCod)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumUsrs;
unsigned long NumUsr;
@ -499,7 +491,7 @@ static void MchRes_ListAllMchResultsInMch (struct Gam_Games *Games,long MchCod)
/***** Get all users who have answered any match question in this game *****/
NumUsrs = DB_QuerySELECT (&mysql_res,"can not get users in match",
"SELECT users.UsrCod"
" FROM (SELECT mch_results.UsrCod AS UsrCod" // row[0]
" FROM (SELECT mch_results.UsrCod AS UsrCod"
" FROM mch_results,"
"mch_matches,"
"gam_games"
@ -514,26 +506,20 @@ static void MchRes_ListAllMchResultsInMch (struct Gam_Games *Games,long MchCod)
"usr_data.FirstName",
MchCod,
Gbl.Hierarchy.Crs.CrsCod);
if (NumUsrs)
{
/***** List matches results for each user *****/
for (NumUsr = 0;
NumUsr < NumUsrs;
NumUsr++)
{
row = mysql_fetch_row (mysql_res);
/* Get match code (row[0]) */
if ((Gbl.Usrs.Other.UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0])) > 0)
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,Usr_DONT_GET_PREFS))
if (Usr_CheckIfICanViewTstExaMchResult (&Gbl.Usrs.Other.UsrDat))
{
/***** Show matches results *****/
Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat);
MchRes_ShowMchResults (Games,Usr_OTHER,MchCod,-1L,NULL);
}
}
}
/***** List matches results for each user *****/
for (NumUsr = 0;
NumUsr < NumUsrs;
NumUsr++)
/* Get match code (row[0]) */
if ((Gbl.Usrs.Other.UsrDat.UsrCod = DB_GetNextCode (mysql_res)) > 0)
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,Usr_DONT_GET_PREFS))
if (Usr_CheckIfICanViewTstExaMchResult (&Gbl.Usrs.Other.UsrDat))
{
/***** Show matches results *****/
Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat);
MchRes_ShowMchResults (Games,Usr_OTHER,MchCod,-1L,NULL);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
@ -770,7 +756,6 @@ static void MchRes_ShowMchResults (struct Gam_Games *Games,
char *GamSubQuery;
char *HidGamSubQuery;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
struct UsrData *UsrDat;
struct MchRes_ICanView ICanView;
unsigned NumResults;
@ -852,25 +837,25 @@ static void MchRes_ShowMchResults (struct Gam_Games *Games,
}
/***** Make database query *****/
NumResults =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get matches results",
"SELECT mch_results.MchCod" // row[0]
" FROM mch_results,"
"mch_matches,"
"gam_games"
" WHERE mch_results.UsrCod=%ld"
"%s" // Match subquery
" AND mch_results.MchCod=mch_matches.MchCod"
"%s" // Games subquery
" AND mch_matches.GamCod=gam_games.GamCod"
"%s" // Hidden games subquery
" AND gam_games.CrsCod=%ld" // Extra check
" ORDER BY mch_matches.Title",
UsrDat->UsrCod,
MchSubQuery,
GamSubQuery,
HidGamSubQuery,
Gbl.Hierarchy.Crs.CrsCod);
NumResults = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get matches results",
"SELECT mch_results.MchCod"
" FROM mch_results,"
"mch_matches,"
"gam_games"
" WHERE mch_results.UsrCod=%ld"
"%s" // Match subquery
" AND mch_results.MchCod=mch_matches.MchCod"
"%s" // Games subquery
" AND mch_matches.GamCod=gam_games.GamCod"
"%s" // Hidden games subquery
" AND gam_games.CrsCod=%ld" // Extra check
" ORDER BY mch_matches.Title",
UsrDat->UsrCod,
MchSubQuery,
GamSubQuery,
HidGamSubQuery,
Gbl.Hierarchy.Crs.CrsCod);
free (HidGamSubQuery);
free (GamSubQuery);
free (MchSubQuery);
@ -886,11 +871,9 @@ static void MchRes_ShowMchResults (struct Gam_Games *Games,
NumResult < NumResults;
NumResult++)
{
row = mysql_fetch_row (mysql_res);
/* Get match code (row[0]) */
/* Get match code */
MchPrn_ResetPrint (&Print);
if ((Print.MchCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
if ((Print.MchCod = DB_GetNextCode (mysql_res)) < 0)
Lay_ShowErrorAndExit ("Wrong code of match.");
/* Get match result data */

View File

@ -1439,7 +1439,6 @@ static unsigned long Msg_DelSomeRecOrSntMsgsUsr (const struct Msg_Messages *Mess
const char *FilterFromToSubquery)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long MsgNum;
unsigned long NumMsgs;
long MsgCod;
@ -1455,9 +1454,10 @@ static unsigned long Msg_DelSomeRecOrSntMsgsUsr (const struct Msg_Messages *Mess
MsgNum < NumMsgs;
MsgNum++)
{
row = mysql_fetch_row (mysql_res);
if (sscanf (row[0],"%ld",&MsgCod) != 1)
MsgCod = DB_GetNextCode (mysql_res);
if (MsgCod <= 0)
Lay_ShowErrorAndExit ("Wrong code of message.");
switch (Messages->TypeOfMessages)
{
case Msg_RECEIVED:
@ -2861,8 +2861,8 @@ static void Msg_GetDistinctCoursesInMyMessages (struct Msg_Messages *Messages)
case Msg_RECEIVED:
NumRows =
DB_QuerySELECT (&mysql_res,"can not get distinct courses in your messages",
"SELECT DISTINCT crs_courses.CrsCod,"
"crs_courses.ShortName"
"SELECT DISTINCT crs_courses.CrsCod," // row[0]
"crs_courses.ShortName" // row[1]
" FROM msg_rcv,"
"msg_snt,"
"crs_courses"
@ -2875,8 +2875,8 @@ static void Msg_GetDistinctCoursesInMyMessages (struct Msg_Messages *Messages)
case Msg_SENT:
NumRows =
DB_QuerySELECT (&mysql_res,"can not get distinct courses in your messages",
"SELECT DISTINCT crs_courses.CrsCod,"
"crs_courses.ShortName"
"SELECT DISTINCT crs_courses.CrsCod," // row[0]
"crs_courses.ShortName" // row[1]
" FROM msg_snt,"
"crs_courses"
" WHERE msg_snt.UsrCod=%ld"
@ -3097,7 +3097,7 @@ static void Msg_GetMsgSubject (long MsgCod,char Subject[Cns_MAX_BYTES_SUBJECT +
/***** Get subject of message from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get the subject of a message",
"SELECT Subject"
"SELECT Subject" // row[0]
" FROM msg_content"
" WHERE MsgCod=%ld",
MsgCod) == 1) // Result should have a unique row
@ -3163,7 +3163,7 @@ static void Msg_GetStatusOfSentMsg (long MsgCod,bool *Expanded)
/***** Get if sent message has been replied/expanded from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get if a sent message"
" has been replied/expanded",
"SELECT Expanded"
"SELECT Expanded" // row[0]
" FROM msg_snt"
" WHERE MsgCod=%ld"
" AND UsrCod=%ld",
@ -3197,9 +3197,9 @@ static void Msg_GetStatusOfReceivedMsg (long MsgCod,bool *Open,bool *Replied,boo
/***** Get if received message has been replied/expanded from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get if a received message"
" has been replied/expanded",
"SELECT Open,"
"Replied,"
"Expanded"
"SELECT Open," // row[0]
"Replied," // row[1]
"Expanded" // row[2]
" FROM msg_rcv"
" WHERE MsgCod=%ld"
" AND UsrCod=%ld",
@ -3427,8 +3427,8 @@ void Msg_GetNotifMessage (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
/***** Get subject of message from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get subject and content"
" of a message",
"SELECT Subject,"
"Content"
"SELECT Subject," // row[0]
"Content" // row[1]
" FROM msg_content"
" WHERE MsgCod=%ld",
MsgCod) == 1) // Result should have a unique row
@ -3780,23 +3780,23 @@ static void Msg_WriteMsgTo (struct Msg_Messages *Messages,long MsgCod)
/***** Get recipients of a message from database *****/
NumRecipientsKnown =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get recipients of a message",
"(SELECT msg_rcv.UsrCod,"
"'N',"
"msg_rcv.Open,"
"usr_data.Surname1 AS S1,"
"usr_data.Surname2 AS S2,"
"usr_data.FirstName AS FN"
"(SELECT msg_rcv.UsrCod," // row[0]
"'N'," // row[1]
"msg_rcv.Open," // row[2]
"usr_data.Surname1 AS S1," // row[3]
"usr_data.Surname2 AS S2," // row[4]
"usr_data.FirstName AS FN" // row[5]
" FROM msg_rcv,"
"usr_data"
" WHERE msg_rcv.MsgCod=%ld"
" AND msg_rcv.UsrCod=usr_data.UsrCod)"
" UNION "
"(SELECT msg_rcv_deleted.UsrCod,"
"'Y',"
"msg_rcv_deleted.Open,"
"usr_data.Surname1 AS S1,"
"usr_data.Surname2 AS S2,"
"usr_data.FirstName AS FN"
"(SELECT msg_rcv_deleted.UsrCod," // row[0]
"'Y'," // row[1]
"msg_rcv_deleted.Open," // row[2]
"usr_data.Surname1 AS S1," // row[3]
"usr_data.Surname2 AS S2," // row[4]
"usr_data.FirstName AS FN" // row[5]
" FROM msg_rcv_deleted,"
"usr_data"
" WHERE msg_rcv_deleted.MsgCod=%ld"
@ -4149,8 +4149,8 @@ void Msg_ListBannedUsrs (void)
extern const char *Txt_Banned_users;
extern const char *Txt_Sender_banned_click_to_unban_him;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumUsr,NumUsrs;
unsigned NumUsr;
unsigned NumUsrs;
struct UsrData UsrDat;
/***** Get my banned users *****/
@ -4182,10 +4182,8 @@ void Msg_ListBannedUsrs (void)
NumUsr <= NumUsrs;
NumUsr++)
{
row = mysql_fetch_row (mysql_res);
/* Get user's code (row[0]) */
UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get user's code */
UsrDat.UsrCod = DB_GetNextCode (mysql_res);
/* Get user's data from database */
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS))

View File

@ -225,7 +225,7 @@ void Net_ShowWebsAndSocialNets (const struct UsrData *UsrDat)
{
/***** Check if exists the web / social network for this user *****/
if (DB_QuerySELECT (&mysql_res,"can not get user's web / social network",
"SELECT URL"
"SELECT URL" // row[0]
" FROM usr_webs"
" WHERE UsrCod=%ld"
" AND Web='%s'",
@ -304,7 +304,7 @@ void Net_ShowFormMyWebsAndSocialNets (void)
{
/***** Get user's web / social network from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get user's web / social network",
"SELECT URL"
"SELECT URL" // row[0]
" FROM usr_webs"
" WHERE UsrCod=%ld"
" AND Web='%s'",

View File

@ -121,7 +121,7 @@ bool Nck_GetNicknameFromUsrCod (long UsrCod,
/***** Get current (last updated) user's nickname from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get nickname",
"SELECT Nickname"
"SELECT Nickname" // row[0]
" FROM usr_nicknames"
" WHERE UsrCod=%ld"
" ORDER BY CreatTime DESC"
@ -154,39 +154,27 @@ bool Nck_GetNicknameFromUsrCod (long UsrCod,
long Nck_GetUsrCodFromNickname (const char *Nickname)
{
char NickWithoutArr[Nck_MAX_BYTES_NICK_FROM_FORM + 1];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long UsrCod = -1L;
if (Nickname)
if (Nickname[0])
{
/***** Make a copy without possible starting arrobas *****/
Str_Copy (NickWithoutArr,Nickname,sizeof (NickWithoutArr) - 1);
Str_RemoveLeadingArrobas (NickWithoutArr);
/***** Trivial check 1: nickname should be not null *****/
if (!Nickname)
return -1L;
/***** Get user's code from database *****/
/* Check if user code from table usr_nicknames is also in table usr_data */
if (DB_QuerySELECT (&mysql_res,"can not get user's code",
"SELECT usr_nicknames.UsrCod"
" FROM usr_nicknames,"
"usr_data"
" WHERE usr_nicknames.Nickname='%s'"
" AND usr_nicknames.UsrCod=usr_data.UsrCod",
NickWithoutArr))
{
/* Get row */
row = mysql_fetch_row (mysql_res);
/***** Trivial check 2: nickname should be not empty *****/
if (!Nickname[0])
return -1L;
/* Get user's code */
UsrCod = Str_ConvertStrCodToLongCod (row[0]);
}
/***** Make a copy without possible starting arrobas *****/
Str_Copy (NickWithoutArr,Nickname,sizeof (NickWithoutArr) - 1);
Str_RemoveLeadingArrobas (NickWithoutArr);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
return UsrCod;
/***** Get user's code from database *****/
return DB_QuerySELECTCode ("can not get user's code",
"SELECT usr_nicknames.UsrCod"
" FROM usr_nicknames,"
"usr_data"
" WHERE usr_nicknames.Nickname='%s'"
" AND usr_nicknames.UsrCod=usr_data.UsrCod",
NickWithoutArr);
}
/*****************************************************************************/
@ -239,13 +227,13 @@ static void Nck_ShowFormChangeUsrNickname (bool ItsMe,
HTM_SECTION_Begin (Nck_NICKNAME_SECTION_ID);
/***** Get my nicknames *****/
NumNicks =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get nicknames of a user",
"SELECT Nickname"
" FROM usr_nicknames"
" WHERE UsrCod=%ld"
" ORDER BY CreatTime DESC",
UsrDat->UsrCod);
NumNicks = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get nicknames of a user",
"SELECT Nickname" // row[0]
" FROM usr_nicknames"
" WHERE UsrCod=%ld"
" ORDER BY CreatTime DESC",
UsrDat->UsrCod);
/***** Begin box *****/
snprintf (StrRecordWidth,sizeof (StrRecordWidth),"%upx",Rec_RECORD_WIDTH);

View File

@ -393,11 +393,11 @@ void Not_ShowNotices (Not_Listing_t TypeNoticesListing,long HighlightNotCod)
{
case Not_LIST_BRIEF_NOTICES:
NumNotices = DB_QuerySELECT (&mysql_res,"can not get notices from database",
"SELECT NotCod,"
"UNIX_TIMESTAMP(CreatTime) AS F,"
"UsrCod,"
"Content,"
"Status"
"SELECT NotCod," // row[0]
"UNIX_TIMESTAMP(CreatTime) AS F," // row[1]
"UsrCod," // row[2]
"Content," // row[3]
"Status" // row[4]
" FROM not_notices"
" WHERE CrsCod=%ld"
" AND Status=%u"
@ -407,11 +407,11 @@ void Not_ShowNotices (Not_Listing_t TypeNoticesListing,long HighlightNotCod)
break;
case Not_LIST_FULL_NOTICES:
NumNotices = DB_QuerySELECT (&mysql_res,"can not get notices from database",
"SELECT NotCod,"
"UNIX_TIMESTAMP(CreatTime) AS F,"
"UsrCod,"
"Content,"
"Status"
"SELECT NotCod," // row[0]
"UNIX_TIMESTAMP(CreatTime) AS F," // row[1]
"UsrCod," // row[2]
"Content," // row[3]
"Status" // row[4]
" FROM not_notices"
" WHERE CrsCod=%ld"
" ORDER BY CreatTime DESC",

View File

@ -1192,7 +1192,6 @@ void Ntf_MarkNotifFilesInGroupAsRemoved (long GrpCod)
unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRow;
unsigned long NumRows = 0; // Initialized to avoid warning
struct UsrData UsrDat;
@ -1229,7 +1228,7 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
break;
case Brw_ADMI_TCH_CRS: // Notify all teachers in course except me
NumRows = DB_QuerySELECT (&mysql_res,"can not get users"
" to be notified",
" to be notified",
"SELECT UsrCod" // row[0]
" FROM crs_users"
" WHERE CrsCod=%ld"
@ -1243,7 +1242,7 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
case Brw_ADMI_SHR_GRP:
case Brw_ADMI_MRK_GRP: // Notify all users in group except me
NumRows = DB_QuerySELECT (&mysql_res,"can not get users"
" to be notified",
" to be notified",
"SELECT UsrCod" // row[0]
" FROM grp_users"
" WHERE GrpCod=%ld"
@ -1253,7 +1252,7 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
break;
case Brw_ADMI_TCH_GRP: // Notify all teachers in group except me
NumRows = DB_QuerySELECT (&mysql_res,"can not get users"
" to be notified",
" to be notified",
"SELECT grp_users.UsrCod" // row[0]
" FROM grp_users,"
"grp_groups,"
@ -1500,10 +1499,7 @@ unsigned Ntf_StoreNotifyEventsToAllUsrs (Ntf_NotifyEvent_t NotifyEvent,long Cod)
NumRow++)
{
/* Get next user */
row = mysql_fetch_row (mysql_res);
/* Get user code */
UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]);
UsrDat.UsrCod = DB_GetNextCode (mysql_res);
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS)) // Get user's data from the database
if ((UsrDat.NtfEvents.CreateNotif & NotifyEventMask)) // Create notification
@ -1573,7 +1569,6 @@ static void Ntf_UpdateMyLastAccessToNotifications (void)
void Ntf_SendPendingNotifByEMailToAllUsrs (void)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
unsigned long NumRow;
struct UsrData UsrDat;
@ -1608,10 +1603,7 @@ void Ntf_SendPendingNotifByEMailToAllUsrs (void)
NumRow++)
{
/* Get next user */
row = mysql_fetch_row (mysql_res);
/* Get user code */
UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]);
UsrDat.UsrCod = DB_GetNextCode (mysql_res);
/* Get user's data */
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS)) // Get user's data from the database
@ -1680,13 +1672,13 @@ static void Ntf_SendPendingNotifByEMailToOneUsr (struct UsrData *ToUsrDat,unsign
/***** Get pending notifications of this user from database ******/
NumRows = DB_QuerySELECT (&mysql_res,"can not get pending notifications"
" of a user",
"SELECT NotifyEvent,"
"FromUsrCod,"
"InsCod,"
"CtrCod,"
"DegCod,"
"CrsCod,"
"Cod"
"SELECT NotifyEvent," // row[0]
"FromUsrCod," // row[1]
"InsCod," // row[2]
"CtrCod," // row[3]
"DegCod," // row[4]
"CrsCod," // row[5]
"Cod" // row[6]
" FROM ntf_notifications"
" WHERE ToUsrCod=%ld"
" AND (Status & %u)<>0"

View File

@ -129,8 +129,8 @@ static void Pho_ShowOrPrintClassPhotoDegrees (struct Pho_DegPhotos *DegPhotos,
Pho_AvgPhotoSeeOrPrint_t SeeOrPrint);
static void Pho_ShowOrPrintListDegrees (struct Pho_DegPhotos *DegPhotos,
Pho_AvgPhotoSeeOrPrint_t SeeOrPrint);
static unsigned long Pho_BuildQueryOfDegrees (Pho_HowOrderDegrees_t HowOrderDegrees,
MYSQL_RES **mysql_res);
static unsigned long Pho_QueryDegrees (Pho_HowOrderDegrees_t HowOrderDegrees,
MYSQL_RES **mysql_res);
static void Pho_GetNumStdsInDegree (long DegCod,Usr_Sex_t Sex,int *NumStds,int *NumStdsWithPhoto);
static void Pho_UpdateDegStats (long DegCod,Usr_Sex_t Sex,unsigned NumStds,unsigned NumStdsWithPhoto,long TimeToComputeAvgPhoto);
static void Pho_ShowDegreeStat (int NumStds,int NumStdsWithPhoto);
@ -932,7 +932,7 @@ unsigned Pho_UpdateMyClicksWithoutPhoto (void)
/***** Get number of clicks without photo from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get number of clicks"
" without photo",
"SELECT NumClicks"
"SELECT NumClicks" // row[0]
" FROM pho_clicks_without_photo"
" WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod);
@ -1417,79 +1417,43 @@ void Pho_CalcPhotoDegree (void)
static long Pho_GetDegWithAvgPhotoLeastRecentlyUpdated (void)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows = 0;
long DegCod = -1L;
long DegCod;
/***** Delete all the degrees in sta_degrees table not present in degrees table *****/
Pho_RemoveObsoleteStatDegrees ();
/***** 1. If a degree is not in table of computed degrees,
choose it as least recently updated *****/
/* Get one degree with students not yet computed */
NumRows =
DB_QuerySELECT (&mysql_res,"can not get degrees",
"SELECT DISTINCT deg_degrees.DegCod" // row[0]
" FROM deg_degrees,"
"crs_courses,"
"crs_users"
" WHERE deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=crs_users.CrsCod"
" AND crs_users.Role=%u"
" AND deg_degrees.DegCod NOT IN"
" (SELECT DISTINCT DegCod"
" FROM sta_degrees)"
" LIMIT 1",
(unsigned) Rol_STD);
/* If number of rows is 1, then get the degree code */
if (NumRows == 1)
{
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get degree code (row[0]) */
if ((DegCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of degree.");
}
else // NumRows == 0
{
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
DegCod = DB_QuerySELECTCode ("can not get degrees",
"SELECT DISTINCT deg_degrees.DegCod"
" FROM deg_degrees,"
"crs_courses,"
"crs_users"
" WHERE deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=crs_users.CrsCod"
" AND crs_users.Role=%u"
" AND deg_degrees.DegCod NOT IN"
" (SELECT DISTINCT DegCod"
" FROM sta_degrees)"
" LIMIT 1",
(unsigned) Rol_STD);
if (DegCod <= 0)
/***** 2. If all the degrees are in table,
choose the least recently updated that has students *****/
/* Get degrees from database */
NumRows =
DB_QuerySELECT (&mysql_res,"can not get degrees",
"SELECT sta_degrees.DegCod" // row[0]
" FROM sta_degrees,"
"crs_courses,"
"crs_users"
" WHERE sta_degrees.TimeAvgPhoto<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)"
" AND sta_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=crs_users.CrsCod"
" AND crs_users.Role=%u"
" ORDER BY sta_degrees.TimeAvgPhoto"
" LIMIT 1",
Cfg_MIN_TIME_TO_RECOMPUTE_AVG_PHOTO,
(unsigned) Rol_STD);
/* If number of rows is 1, then get the degree code */
if (NumRows == 1)
{
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get degree code (row[0]) */
if ((DegCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of degree.");
}
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
DegCod = DB_QuerySELECTCode ("can not get degrees",
"SELECT sta_degrees.DegCod"
" FROM sta_degrees,"
"crs_courses,"
"crs_users"
" WHERE sta_degrees.TimeAvgPhoto<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)"
" AND sta_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=crs_users.CrsCod"
" AND crs_users.Role=%u"
" ORDER BY sta_degrees.TimeAvgPhoto"
" LIMIT 1",
Cfg_MIN_TIME_TO_RECOMPUTE_AVG_PHOTO,
(unsigned) Rol_STD);
return DegCod;
}
@ -1521,7 +1485,7 @@ static long Pho_GetTimeAvgPhotoWasComputed (long DegCod)
/***** Get last time an average photo was computed from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get last time"
" an average photo was computed",
"SELECT MIN(UNIX_TIMESTAMP(TimeAvgPhoto))"
"SELECT MIN(UNIX_TIMESTAMP(TimeAvgPhoto))" // row[0]
" FROM sta_degrees"
" WHERE DegCod=%ld",
DegCod);
@ -2149,7 +2113,6 @@ static void Pho_ShowOrPrintClassPhotoDegrees (struct Pho_DegPhotos *DegPhotos,
Pho_AvgPhotoSeeOrPrint_t SeeOrPrint)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumDeg;
unsigned long NumDegs;
struct Deg_Degree Deg;
@ -2159,7 +2122,7 @@ static void Pho_ShowOrPrintClassPhotoDegrees (struct Pho_DegPhotos *DegPhotos,
bool TRIsOpen = false;
/***** Get degrees from database *****/
NumDegs = Pho_BuildQueryOfDegrees (DegPhotos->HowOrderDegrees,&mysql_res);
NumDegs = Pho_QueryDegrees (DegPhotos->HowOrderDegrees,&mysql_res);
if (NumDegs) // Degrees with students found
{
@ -2174,10 +2137,7 @@ static void Pho_ShowOrPrintClassPhotoDegrees (struct Pho_DegPhotos *DegPhotos,
NumDeg++)
{
/***** Get next degree *****/
row = mysql_fetch_row (mysql_res);
/* Get degree code (row[0]) */
if ((Deg.DegCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
if ((Deg.DegCod = DB_GetNextCode (mysql_res)) < 0)
Lay_ShowErrorAndExit ("Wrong code of degree.");
/* Get data of degree */
@ -2243,7 +2203,7 @@ static void Pho_ShowOrPrintListDegrees (struct Pho_DegPhotos *DegPhotos,
Usr_Sex_t Sex;
/***** Get degrees from database *****/
NumDegs = Pho_BuildQueryOfDegrees (DegPhotos->HowOrderDegrees,&mysql_res);
NumDegs = Pho_QueryDegrees (DegPhotos->HowOrderDegrees,&mysql_res);
if (NumDegs) // Degrees with students found
{
@ -2333,8 +2293,8 @@ static void Pho_ShowOrPrintListDegrees (struct Pho_DegPhotos *DegPhotos,
/****** Build a query to get the degrees ordered by different criteria *******/
/*****************************************************************************/
static unsigned long Pho_BuildQueryOfDegrees (Pho_HowOrderDegrees_t HowOrderDegrees,
MYSQL_RES **mysql_res)
static unsigned long Pho_QueryDegrees (Pho_HowOrderDegrees_t HowOrderDegrees,
MYSQL_RES **mysql_res)
{
unsigned long NumDegs = 0; // Initialized to avoid warning
@ -2401,8 +2361,8 @@ static void Pho_GetNumStdsInDegree (long DegCod,Usr_Sex_t Sex,int *NumStds,int *
/***** Get the number of students in a degree from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get the number of students"
" in a degree",
"SELECT NumStds,"
"NumStdsWithPhoto"
"SELECT NumStds," // row[0]
"NumStdsWithPhoto" // row[1]
" FROM sta_degrees"
" WHERE DegCod=%ld"
" AND Sex='%s'",

View File

@ -365,10 +365,10 @@ void Plc_GetListPlaces (struct Plc_Places *Places)
/***** Get places from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get places",
"(SELECT plc_places.PlcCod,"
"plc_places.ShortName,"
"plc_places.FullName,"
"COUNT(*) AS NumCtrs"
"(SELECT plc_places.PlcCod," // row[0]
"plc_places.ShortName," // row[1]
"plc_places.FullName," // row[2]
"COUNT(*) AS NumCtrs" // row[3]
" FROM plc_places,"
"ctr_centers"
" WHERE plc_places.InsCod=%ld"

View File

@ -822,17 +822,18 @@ void Prf_GetUsrFigures (long UsrCod,struct UsrFigures *UsrFigures)
unsigned NumRows;
/***** Get user's figures from database *****/
NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get user's figures",
"SELECT UNIX_TIMESTAMP(FirstClickTime)," // row[0]
"DATEDIFF(NOW(),FirstClickTime)+1," // row[1]
"NumClicks," // row[2]
"NumSocPub," // row[3]
"NumFileViews," // row[4]
"NumForPst," // row[5]
"NumMsgSnt" // row[6]
" FROM usr_figures"
" WHERE UsrCod=%ld",
UsrCod);
NumRows = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get user's figures",
"SELECT UNIX_TIMESTAMP(FirstClickTime)," // row[0]
"DATEDIFF(NOW(),FirstClickTime)+1," // row[1]
"NumClicks," // row[2]
"NumSocPub," // row[3]
"NumFileViews," // row[4]
"NumForPst," // row[5]
"NumMsgSnt" // row[6]
" FROM usr_figures"
" WHERE UsrCod=%ld",
UsrCod);
if (NumRows)
{
/***** Get user's figures *****/
@ -1057,11 +1058,9 @@ static void Prf_GetFirstClickFromLogAndStoreAsUsrFigure (long UsrCod)
/***** Get first click from log table *****/
if (DB_QuerySELECT (&mysql_res,"can not get user's first click",
"SELECT UNIX_TIMESTAMP("
"(SELECT MIN(ClickTime)"
" FROM log"
" WHERE UsrCod=%ld)"
")",
"SELECT UNIX_TIMESTAMP((SELECT MIN(ClickTime)"
" FROM log"
" WHERE UsrCod=%ld))",
UsrCod))
{
/* Get first click */

View File

@ -1165,7 +1165,7 @@ static void Prg_GetItemTxtFromDB (long ItmCod,char Txt[Cns_MAX_BYTES_TEXT + 1])
/***** Get text of program item from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get program item text",
"SELECT Txt"
"SELECT Txt" // row[0]
" FROM prg_items"
" WHERE ItmCod=%ld"
" AND CrsCod=%ld", // Extra check

View File

@ -2318,7 +2318,7 @@ unsigned Prj_GetMyRolesInProject (long PrjCod)
Gbl.Cache.MyRolesInProject.PrjCod = PrjCod;
Gbl.Cache.MyRolesInProject.RolesInProject = 0;
NumRows = (unsigned) DB_QuerySELECT (&mysql_res,"can not get my roles in project",
"SELECT RoleInProject"
"SELECT RoleInProject" // row[0]
" FROM prj_users"
" WHERE PrjCod=%ld"
" AND UsrCod=%ld",
@ -2847,7 +2847,6 @@ static void Prj_GetListProjects (struct Prj_Projects *Projects)
"prj_projects.Title",
};
MYSQL_RES *mysql_res = NULL; // Initialized to avoid freeing when not assigned
MYSQL_ROW row;
unsigned NumUsrsInList;
long *LstSelectedUsrCods;
char *SubQueryUsrs;
@ -3090,8 +3089,7 @@ static void Prj_GetListProjects (struct Prj_Projects *Projects)
NumPrj++)
{
/* Get next project code */
row = mysql_fetch_row (mysql_res);
if ((PrjCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
if ((PrjCod = DB_GetNextCode (mysql_res)) < 0)
Lay_WrongProjectExit ();
/* Filter projects depending on faultiness */
@ -3126,31 +3124,16 @@ static void Prj_GetListProjects (struct Prj_Projects *Projects)
long Prj_GetCourseOfProject (long PrjCod)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long CrsCod = -1L;
/***** Trivial check: project code should be > 0 *****/
if (PrjCod <= 0)
return -1L;
if (PrjCod > 0)
{
/***** Get course code from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get project course",
"SELECT CrsCod" // row[0]
" FROM prj_projects"
" WHERE PrjCod=%ld",
PrjCod)) // Project found...
{
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get code of the course (row[0]) */
CrsCod = Str_ConvertStrCodToLongCod (row[0]);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
return CrsCod;
/***** Get course code from database *****/
return DB_QuerySELECTCode ("can not get project course",
"SELECT CrsCod" // row[0]
" FROM prj_projects"
" WHERE PrjCod=%ld",
PrjCod); // Project found...
}
/*****************************************************************************/

View File

@ -202,10 +202,10 @@ void Rec_GetListRecordFieldsInCurrentCrs (void)
/***** Get fields of records in a course from database *****/
Gbl.Crs.Records.LstFields.Num = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get fields of records in a course",
"SELECT FieldCod,"
"FieldName,"
"NumLines,"
"Visibility"
"SELECT FieldCod," // row[0]
"FieldName," // row[1]
"NumLines," // row[2]
"Visibility" // row[3]
" FROM crs_record_fields"
" WHERE CrsCod=%ld"
" ORDER BY FieldName",
@ -1856,7 +1856,7 @@ unsigned long Rec_GetFieldFromCrsRecord (long UsrCod,long FieldCod,MYSQL_RES **m
/***** Get the text of a field of a record from database *****/
return DB_QuerySELECT (mysql_res,"can not get the text"
" of a field of a record",
"SELECT Txt"
"SELECT Txt" // row[0]
" FROM crs_records"
" WHERE FieldCod=%ld"
" AND UsrCod=%ld",

View File

@ -1101,8 +1101,8 @@ static void Rep_GetAndWriteMyHistoricCrss (Rol_Role_t Role,
/***** Get historic courses of a user from log *****/
NumCrss =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get courses of a user",
"SELECT CrsCod,"
"COUNT(*) AS N"
"SELECT CrsCod," // row[0]
"COUNT(*) AS N" // row[1]
" FROM log"
" WHERE UsrCod=%ld"
" AND Role=%u"
@ -1242,8 +1242,9 @@ static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role,
sprintf (SubQueryRol," AND Role=%u",(unsigned) Role);
NumRows = DB_QuerySELECT (&mysql_res,"can not get clicks",
"SELECT SQL_NO_CACHE YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year,"
"COUNT(*) FROM log"
"SELECT SQL_NO_CACHE YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year," // row[0]
"COUNT(*)" // row[1]
" FROM log"
" WHERE ClickTime>=FROM_UNIXTIME(%ld)"
" AND UsrCod=%ld"
"%s"

View File

@ -622,7 +622,7 @@ Rol_Role_t Rol_GetRequestedRole (long UsrCod)
/***** Get requested role from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get requested role",
"SELECT Role"
"SELECT Role" // row[0]
" FROM crs_requests"
" WHERE CrsCod=%ld"
" AND UsrCod=%ld",

View File

@ -466,7 +466,7 @@ static unsigned Sch_SearchCountriesInDB (const char *RangeQuery)
/***** Query database and list institutions found *****/
NumCtys = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get countries",
"SELECT CtyCod" // row[0]
"SELECT CtyCod"
" FROM cty_countrs"
" WHERE %s"
"%s"
@ -506,7 +506,7 @@ static unsigned Sch_SearchInstitutionsInDB (const char *RangeQuery)
/***** Query database and list institutions found *****/
NumInss = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get institutions",
"SELECT ins_instits.InsCod" // row[0]
"SELECT ins_instits.InsCod"
" FROM ins_instits,"
"cty_countrs"
" WHERE %s"
@ -546,7 +546,7 @@ static unsigned Sch_SearchCentersInDB (const char *RangeQuery)
/***** Query database and list centers found *****/
NumCtrs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get centers",
"SELECT ctr_centers.CtrCod" // row[0]
"SELECT ctr_centers.CtrCod"
" FROM ctr_centers,"
"ins_instits,"
"cty_countrs"
@ -585,7 +585,7 @@ static unsigned Sch_SearchDegreesInDB (const char *RangeQuery)
/***** Query database and list degrees found *****/
NumDegs = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get degrees",
"SELECT deg_degrees.DegCod" // row[0]
"SELECT deg_degrees.DegCod"
" FROM deg_degrees,"
"ctr_centers,"
"ins_instits,"

View File

@ -437,7 +437,7 @@ void Ses_GetParamFromDB (const char *ParamName,char *ParamValue,size_t MaxBytes)
{
/***** Get a session parameter from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get a session parameter",
"SELECT ParamValue"
"SELECT ParamValue" // row[0]
" FROM ses_params"
" WHERE SessionId='%s'"
" AND ParamName='%s'",
@ -488,7 +488,7 @@ bool Ses_GetPublicDirFromCache (const char *FullPathMediaPriv,
{
/***** Get temporary directory from cache *****/
if (DB_QuerySELECT (&mysql_res,"can not get check if file is cached",
"SELECT TmpPubDir"
"SELECT TmpPubDir" // row[0]
" FROM brw_caches"
" WHERE SessionId='%s'"
" AND PrivPath='%s'",

View File

@ -1789,7 +1789,7 @@ static void Sta_WriteLogComments (long LogCod)
/***** Get log comments from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get log comments",
"SELECT Comments"
"SELECT Comments" // row[0]
" FROM log_comments"
" WHERE LogCod=%ld",
LogCod))

View File

@ -937,7 +937,6 @@ static void Svy_GetListSurveys (struct Svy_Surveys *Surveys)
[Dat_END_TIME ] = "EndTime DESC,StartTime DESC,Title DESC",
};
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
unsigned NumSvy;
unsigned ScopesAllowed = 0;
@ -1067,12 +1066,9 @@ static void Svy_GetListSurveys (struct Svy_Surveys *Surveys)
for (NumSvy = 0;
NumSvy < Surveys->Num;
NumSvy++)
{
/* Get next survey code */
row = mysql_fetch_row (mysql_res);
if ((Surveys->LstSvyCods[NumSvy] = Str_ConvertStrCodToLongCod (row[0])) < 0)
if ((Surveys->LstSvyCods[NumSvy] = DB_GetNextCode (mysql_res)) < 0)
Lay_ShowErrorAndExit ("Error: wrong survey code.");
}
}
else
Surveys->Num = 0;
@ -1494,7 +1490,7 @@ static void Svy_GetSurveyTxtFromDB (long SvyCod,char Txt[Cns_MAX_BYTES_TEXT + 1]
/***** Get text of survey from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get survey text",
"SELECT Txt"
"SELECT Txt" // row[0]
" FROM svy_surveys"
" WHERE SvyCod=%ld",
SvyCod);
@ -2510,8 +2506,8 @@ static void Svy_GetAndWriteNamesOfGrpsAssociatedToSvy (struct Svy_Survey *Svy)
/***** Get groups associated to a survey from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get groups of a survey",
"SELECT grp_types.GrpTypName,"
"grp_groups.GrpName"
"SELECT grp_types.GrpTypName," // row[0]
"grp_groups.GrpName" // row[1]
" FROM svy_groups,"
"grp_groups,"
"grp_types"
@ -2984,9 +2980,9 @@ static unsigned Svy_GetAnswersQst (long QstCod,MYSQL_RES **mysql_res)
/***** Get answers of a question from database *****/
NumRows = DB_QuerySELECT (mysql_res,"can not get answers of a question",
"SELECT AnsInd,"
"NumUsrs,"
"Answer"
"SELECT AnsInd," // row[0]
"NumUsrs," // row[1]
"Answer" // row[2]
" FROM svy_answers"
" WHERE QstCod=%ld"
" ORDER BY AnsInd",
@ -3223,7 +3219,7 @@ static unsigned Svy_GetQstIndFromQstCod (long QstCod)
/***** Get number of surveys with a field value from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get question index",
"SELECT QstInd"
"SELECT QstInd" // row[0]
" FROM svy_questions"
" WHERE QstCod=%ld",
QstCod);
@ -3256,7 +3252,7 @@ static unsigned Svy_GetNextQuestionIndexInSvy (long SvyCod)
/***** Get number of surveys with a field value from database *****/
DB_QuerySELECT (&mysql_res,"can not get last question index",
"SELECT MAX(QstInd)"
"SELECT MAX(QstInd)" // row[0]
" FROM svy_questions"
" WHERE SvyCod=%ld",
SvyCod);
@ -3809,7 +3805,6 @@ void Svy_ReceiveSurveyAnswers (void)
static void Svy_ReceiveAndStoreUserAnswersToASurvey (long SvyCod)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumQst;
unsigned NumQsts;
long QstCod;
@ -3835,11 +3830,8 @@ static void Svy_ReceiveAndStoreUserAnswersToASurvey (long SvyCod)
NumQst < NumQsts;
NumQst++)
{
/* Get next answer */
row = mysql_fetch_row (mysql_res);
/* Get question code (row[0]) */
if ((QstCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
/* Get next question */
if ((QstCod = DB_GetNextCode (mysql_res)) <= 0)
Lay_ShowErrorAndExit ("Error: wrong question code.");
/* Get possible parameter with the user's answer */
@ -4032,16 +4024,16 @@ unsigned Svy_GetNumCrsSurveys (Hie_Lvl_Level_t Scope,unsigned *NumNotif)
{
case Hie_Lvl_SYS:
DB_QuerySELECT (&mysql_res,"can not get number of surveys",
"SELECT COUNT(*),"
"SUM(NumNotif)"
"SELECT COUNT(*)," // row[0]
"SUM(NumNotif)" // row[1]
" FROM svy_surveys"
" WHERE Scope='%s'",
Sco_GetDBStrFromScope (Hie_Lvl_CRS));
break;
case Hie_Lvl_CTY:
DB_QuerySELECT (&mysql_res,"can not get number of surveys",
"SELECT COUNT(*),"
"SUM(svy_surveys.NumNotif)"
"SELECT COUNT(*)," // row[0]
"SUM(svy_surveys.NumNotif)" // row[1]
" FROM ins_instits,"
"ctr_centers,"
"deg_degrees,"
@ -4058,8 +4050,8 @@ unsigned Svy_GetNumCrsSurveys (Hie_Lvl_Level_t Scope,unsigned *NumNotif)
break;
case Hie_Lvl_INS:
DB_QuerySELECT (&mysql_res,"can not get number of surveys",
"SELECT COUNT(*),"
"SUM(svy_surveys.NumNotif)"
"SELECT COUNT(*)," // row[0]
"SUM(svy_surveys.NumNotif)" // row[1]
" FROM ctr_centers,"
"deg_degrees,"
"crs_courses,"
@ -4074,8 +4066,8 @@ unsigned Svy_GetNumCrsSurveys (Hie_Lvl_Level_t Scope,unsigned *NumNotif)
break;
case Hie_Lvl_CTR:
DB_QuerySELECT (&mysql_res,"can not get number of surveys",
"SELECT COUNT(*),"
"SUM(svy_surveys.NumNotif)"
"SELECT COUNT(*)," // row[0]
"SUM(svy_surveys.NumNotif)" // row[1]
" FROM deg_degrees,"
"crs_courses,"
"svy_surveys"
@ -4088,8 +4080,8 @@ unsigned Svy_GetNumCrsSurveys (Hie_Lvl_Level_t Scope,unsigned *NumNotif)
break;
case Hie_Lvl_DEG:
DB_QuerySELECT (&mysql_res,"can not get number of surveys",
"SELECT COUNT(*),"
"SUM(svy_surveys.NumNotif)"
"SELECT COUNT(*)," // row[0]
"SUM(svy_surveys.NumNotif)" // row[1]
" FROM crs_courses,"
"svy_surveys"
" WHERE crs_courses.DegCod=%ld"
@ -4100,8 +4092,8 @@ unsigned Svy_GetNumCrsSurveys (Hie_Lvl_Level_t Scope,unsigned *NumNotif)
break;
case Hie_Lvl_CRS:
DB_QuerySELECT (&mysql_res,"can not get number of surveys",
"SELECT COUNT(*),"
"SUM(NumNotif)"
"SELECT COUNT(*)," // row[0]
"SUM(NumNotif)" // row[1]
" FROM svy_surveys"
" WHERE svy_surveys.Scope='%s'"
" AND CrsCod=%ld",
@ -4149,7 +4141,7 @@ double Svy_GetNumQstsPerCrsSurvey (Hie_Lvl_Level_t Scope)
case Hie_Lvl_SYS:
DB_QuerySELECT (&mysql_res,"can not get number of questions"
" per survey",
"SELECT AVG(NumQsts)"
"SELECT AVG(NumQsts)" // row[0]
" FROM (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM svy_surveys,"
"svy_questions"
@ -4161,7 +4153,7 @@ double Svy_GetNumQstsPerCrsSurvey (Hie_Lvl_Level_t Scope)
case Hie_Lvl_CTY:
DB_QuerySELECT (&mysql_res,"can not get number of questions"
" per survey",
"SELECT AVG(NumQsts)"
"SELECT AVG(NumQsts)" // row[0]
" FROM (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM ins_instits,"
"ctr_centers,"
@ -4183,7 +4175,7 @@ double Svy_GetNumQstsPerCrsSurvey (Hie_Lvl_Level_t Scope)
case Hie_Lvl_INS:
DB_QuerySELECT (&mysql_res,"can not get number of questions"
" per survey",
"SELECT AVG(NumQsts)"
"SELECT AVG(NumQsts)" // row[0]
" FROM (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM ctr_centers,"
"deg_degrees,"
@ -4203,7 +4195,7 @@ double Svy_GetNumQstsPerCrsSurvey (Hie_Lvl_Level_t Scope)
case Hie_Lvl_CTR:
DB_QuerySELECT (&mysql_res,"can not get number of questions"
" per survey",
"SELECT AVG(NumQsts)"
"SELECT AVG(NumQsts)" // row[0]
" FROM (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM deg_degrees,"
"crs_courses,"
@ -4221,7 +4213,7 @@ double Svy_GetNumQstsPerCrsSurvey (Hie_Lvl_Level_t Scope)
case Hie_Lvl_DEG:
DB_QuerySELECT (&mysql_res,"can not get number of questions"
" per survey",
"SELECT AVG(NumQsts)"
"SELECT AVG(NumQsts)" // row[0]
" FROM (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM crs_courses,"
"svy_surveys,"
@ -4237,7 +4229,7 @@ double Svy_GetNumQstsPerCrsSurvey (Hie_Lvl_Level_t Scope)
case Hie_Lvl_CRS:
DB_QuerySELECT (&mysql_res,"can not get number of questions"
" per survey",
"SELECT AVG(NumQsts)"
"SELECT AVG(NumQsts)" // row[0]
" FROM (SELECT COUNT(svy_questions.QstCod) AS NumQsts"
" FROM svy_surveys,"
"svy_questions"

View File

@ -224,7 +224,6 @@ static void SysCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom)
static void SysCfg_Map (void)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
struct Coordinates CtyAvgCoord;
unsigned Zoom;
unsigned NumCtrs;
@ -266,10 +265,7 @@ static void SysCfg_Map (void)
NumCtr++)
{
/* Get next center */
row = mysql_fetch_row (mysql_res);
/* Get center code (row[0]) */
Ctr.CtrCod = Str_ConvertStrCodToLongCod (row[0]);
Ctr.CtrCod = DB_GetNextCode (mysql_res);
/* Get data of center */
Ctr_GetDataOfCenterByCod (&Ctr);

View File

@ -362,32 +362,19 @@ void Tag_RenameTag (void)
static long Tag_GetTagCodFromTagTxt (const char *TagTxt)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
long TagCod = -1L; // -1 means that the tag does not exist in database
long TagCod;
/***** Get tag code from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get tag",
"SELECT TagCod"
" FROM tst_tags"
" WHERE CrsCod=%ld"
" AND TagTxt='%s'",
Gbl.Hierarchy.Crs.CrsCod,TagTxt);
if (NumRows == 1)
{
/***** Get tag code *****/
row = mysql_fetch_row (mysql_res);
if ((TagCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Ale_CreateAlert (Ale_ERROR,NULL,
"Wrong code of tag.");
}
else if (NumRows > 1)
TagCod = DB_QuerySELECTCode ("can not get tag",
"SELECT TagCod"
" FROM tst_tags"
" WHERE CrsCod=%ld"
" AND TagTxt='%s'",
Gbl.Hierarchy.Crs.CrsCod,
TagTxt);
if (TagCod <= 0)
Ale_CreateAlert (Ale_ERROR,NULL,
"Duplicated tag.");
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
"Wrong tag.");
/***** Abort on error *****/
if (Ale_GetTypeOfLastAlert () == Ale_ERROR)

View File

@ -4008,48 +4008,27 @@ bool Tst_GetQstDataFromDB (struct Tst_Question *Question)
static long Tst_GetMedCodFromDB (long CrsCod,long QstCod,int NumOpt)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned long NumRows;
long MedCod = -1L;
/***** Trivial check: question code should be > 0 *****/
if (QstCod <= 0)
return -1L;
if (QstCod > 0) // Existing question
{
/***** Query depending on NumOpt *****/
if (NumOpt < 0)
// Get media associated to stem
NumRows = DB_QuerySELECT (&mysql_res,"can not get media",
"SELECT MedCod" // row[0]
" FROM tst_questions"
" WHERE QstCod=%ld"
" AND CrsCod=%ld",
QstCod,CrsCod);
else
// Get media associated to answer
NumRows = DB_QuerySELECT (&mysql_res,"can not get media",
"SELECT MedCod" // row[0]
" FROM tst_answers"
" WHERE QstCod=%ld"
" AND AnsInd=%u",
QstCod,(unsigned) NumOpt);
if (NumRows)
{
if (NumRows == 1)
{
/***** Get media code (row[0]) *****/
row = mysql_fetch_row (mysql_res);
MedCod = Str_ConvertStrCodToLongCod (row[0]);
}
else // NumRows > 1
Lay_ShowErrorAndExit ("Duplicated media in database.");
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
return MedCod;
/***** Query depending on NumOpt *****/
if (NumOpt < 0)
// Get media associated to stem
return DB_QuerySELECTCode ("can not get media",
"SELECT MedCod"
" FROM tst_questions"
" WHERE QstCod=%ld"
" AND CrsCod=%ld",
QstCod,CrsCod);
else
// Get media associated to answer
return DB_QuerySELECTCode ("can not get media",
"SELECT MedCod"
" FROM tst_answers"
" WHERE QstCod=%ld"
" AND AnsInd=%u",
QstCod,(unsigned) NumOpt);
}
/*****************************************************************************/
@ -4555,15 +4534,14 @@ bool Tst_CheckIfQuestionExistsInDB (struct Tst_Question *Question)
NumQst++)
{
/* Get question code */
row = mysql_fetch_row (mysql_res_qst);
if ((Question->QstCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
if ((Question->QstCod = DB_GetNextCode (mysql_res_qst)) < 0)
Lay_ShowErrorAndExit ("Wrong code of question.");
/* Get answers from this question */
NumOptsExistingQstInDB =
(unsigned) DB_QuerySELECT (&mysql_res_ans,"can not get the answer"
" of a question",
"SELECT Answer"
"SELECT Answer" // row[0]
" FROM tst_answers"
" WHERE QstCod=%ld"
" ORDER BY AnsInd",
@ -5222,7 +5200,7 @@ static void Tst_RemoveMediaFromStemOfQst (long CrsCod,long QstCod)
/***** Get media code associated to stem of test question from database *****/
NumMedia =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get media",
"SELECT MedCod" // row[0]
"SELECT MedCod"
" FROM tst_questions"
" WHERE QstCod=%ld"
" AND CrsCod=%ld", // Extra check
@ -5361,15 +5339,15 @@ static unsigned Tst_GetNumTstQuestions (Hie_Lvl_Level_t Scope,Tst_AnswerType_t A
case Hie_Lvl_SYS:
if (AnsType == Tst_ANS_UNKNOWN) // Any type
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),"
"SUM(NumHits),"
"SUM(Score)"
"SELECT COUNT(*)," // row[0]
"SUM(NumHits)," // row[1]
"SUM(Score)" // row[2]
" FROM tst_questions");
else
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),"
"SUM(NumHits),"
"SUM(Score)"
"SELECT COUNT(*)," // row[0]
"SUM(NumHits)," // row[1]
"SUM(Score)" // row[2]
" FROM tst_questions"
" WHERE AnsType='%s'",
Tst_StrAnswerTypesDB[AnsType]);
@ -5377,9 +5355,9 @@ static unsigned Tst_GetNumTstQuestions (Hie_Lvl_Level_t Scope,Tst_AnswerType_t A
case Hie_Lvl_CTY:
if (AnsType == Tst_ANS_UNKNOWN) // Any type
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),"
"SUM(NumHits),"
"SUM(Score)"
"SELECT COUNT(*)," // row[0]
"SUM(NumHits)," // row[1]
"SUM(Score)" // row[2]
" FROM ins_instits,"
"ctr_centers,"
"deg_degrees,"
@ -5393,9 +5371,9 @@ static unsigned Tst_GetNumTstQuestions (Hie_Lvl_Level_t Scope,Tst_AnswerType_t A
Gbl.Hierarchy.Cty.CtyCod);
else
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),"
"SUM(NumHits),"
"SUM(Score)"
"SELECT COUNT(*)," // row[0]
"SUM(NumHits)," // row[1]
"SUM(Score)" // row[2]
" FROM ins_instits,"
"ctr_centers,"
"deg_degrees,"
@ -5413,9 +5391,9 @@ static unsigned Tst_GetNumTstQuestions (Hie_Lvl_Level_t Scope,Tst_AnswerType_t A
case Hie_Lvl_INS:
if (AnsType == Tst_ANS_UNKNOWN) // Any type
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),"
"SUM(NumHits),"
"SUM(Score)"
"SELECT COUNT(*)," // row[0]
"SUM(NumHits)," // row[1]
"SUM(Score)" // row[2]
" FROM ctr_centers,"
"deg_degrees,"
"crs_courses,"
@ -5427,9 +5405,9 @@ static unsigned Tst_GetNumTstQuestions (Hie_Lvl_Level_t Scope,Tst_AnswerType_t A
Gbl.Hierarchy.Ins.InsCod);
else
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),"
"SUM(NumHits),"
"SUM(Score)"
"SELECT COUNT(*)," // row[0]
"SUM(NumHits)," // row[1]
"SUM(Score)" // row[2]
" FROM ctr_centers,"
"deg_degrees,"
"crs_courses,"
@ -5445,9 +5423,9 @@ static unsigned Tst_GetNumTstQuestions (Hie_Lvl_Level_t Scope,Tst_AnswerType_t A
case Hie_Lvl_CTR:
if (AnsType == Tst_ANS_UNKNOWN) // Any type
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),"
"SUM(NumHits),"
"SUM(Score)"
"SELECT COUNT(*)," // row[0]
"SUM(NumHits)," // row[1]
"SUM(Score)" // row[2]
" FROM deg_degrees,"
"crs_courses,"
"tst_questions"
@ -5457,9 +5435,9 @@ static unsigned Tst_GetNumTstQuestions (Hie_Lvl_Level_t Scope,Tst_AnswerType_t A
Gbl.Hierarchy.Ctr.CtrCod);
else
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),"
"SUM(NumHits),"
"SUM(Score)"
"SELECT COUNT(*)," // row[0]
"SUM(NumHits)," // row[1]
"SUM(Score)" // row[2]
" FROM deg_degrees,"
"crs_courses,"
"tst_questions"
@ -5473,9 +5451,9 @@ static unsigned Tst_GetNumTstQuestions (Hie_Lvl_Level_t Scope,Tst_AnswerType_t A
case Hie_Lvl_DEG:
if (AnsType == Tst_ANS_UNKNOWN) // Any type
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),"
"SUM(NumHits),"
"SUM(Score)"
"SELECT COUNT(*)," // row[0]
"SUM(NumHits)," // row[1]
"SUM(Score)" // row[2]
" FROM crs_courses,"
"tst_questions"
" WHERE crs_courses.DegCod=%ld"
@ -5483,9 +5461,9 @@ static unsigned Tst_GetNumTstQuestions (Hie_Lvl_Level_t Scope,Tst_AnswerType_t A
Gbl.Hierarchy.Deg.DegCod);
else
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),"
"SUM(NumHits),"
"SUM(Score)"
"SELECT COUNT(*)," // row[0]
"SUM(NumHits)," // row[1]
"SUM(Score)" // row[2]
" FROM crs_courses,"
"tst_questions"
" WHERE crs_courses.DegCod=%ld"
@ -5497,17 +5475,17 @@ static unsigned Tst_GetNumTstQuestions (Hie_Lvl_Level_t Scope,Tst_AnswerType_t A
case Hie_Lvl_CRS:
if (AnsType == Tst_ANS_UNKNOWN) // Any type
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),"
"SUM(NumHits),"
"SUM(Score)"
"SELECT COUNT(*)," // row[0]
"SUM(NumHits)," // row[1]
"SUM(Score)" // row[2]
" FROM tst_questions"
" WHERE CrsCod=%ld",
Gbl.Hierarchy.Crs.CrsCod);
else
DB_QuerySELECT (&mysql_res,"can not get number of test questions",
"SELECT COUNT(*),"
"SUM(NumHits),"
"SUM(Score)"
"SELECT COUNT(*)," // row[0]
"SUM(NumHits)," // row[1]
"SUM(Score)" // row[2]
" FROM tst_questions"
" WHERE CrsCod=%ld"
" AND AnsType='%s'",

View File

@ -138,28 +138,14 @@ unsigned Tml_DB_GetDataOfNoteByCod (long NotCod,MYSQL_RES **mysql_res)
long Tml_DB_GetPubCodOfOriginalNote (long NotCod)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long OriginalPubCod = -1L; // Default value
/***** Get code of publication of the original note *****/
if (DB_QuerySELECT (&mysql_res,"can not get code of publication",
"SELECT PubCod"
" FROM tml_pubs"
" WHERE NotCod=%ld"
" AND PubType=%u",
NotCod,
(unsigned) Tml_Pub_ORIGINAL_NOTE) == 1)
{ // Result should have a unique row
/* Get code of publication (row[0]) */
row = mysql_fetch_row (mysql_res);
OriginalPubCod = Str_ConvertStrCodToLongCod (row[0]);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return OriginalPubCod;
return DB_QuerySELECTCode ("can not get code of publication",
"SELECT PubCod"
" FROM tml_pubs"
" WHERE NotCod=%ld"
" AND PubType=%u",
NotCod,
(unsigned) Tml_Pub_ORIGINAL_NOTE);
}
/*****************************************************************************/
@ -702,26 +688,13 @@ void Tml_DB_RemoveAllCommsMadeBy (long UsrCod)
static long Tml_DB_GetMedCod (const char *Table,const char *Field,long Cod)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long MedCod = -1L; // Default value
/***** Get code of media associated to comment *****/
if (DB_QuerySELECT (&mysql_res,"can not get media code",
"SELECT MedCod" // row[0]
" FROM %s"
" WHERE %s=%ld",
Table,Field,Cod) == 1) // Result should have a unique row
{
/* Get media code */
row = mysql_fetch_row (mysql_res);
MedCod = Str_ConvertStrCodToLongCod (row[0]);
}
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
return MedCod;
return DB_QuerySELECTCode ("can not get media code",
"SELECT MedCod" // row[0]
" FROM %s"
" WHERE %s=%ld",
Table,
Field,Cod);
}
/*****************************************************************************/
@ -862,26 +835,12 @@ unsigned Tml_DB_GetDataOfPubByCod (long PubCod,MYSQL_RES **mysql_res)
long Tml_DB_GetNotCodFromPubCod (long PubCod)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long NotCod = -1L; // Default value
/***** Get code of note from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get code of note",
"SELECT NotCod"
" FROM tml_pubs"
" WHERE PubCod=%ld",
PubCod) == 1) // Result should have a unique row
{
/* Get code of note */
row = mysql_fetch_row (mysql_res);
NotCod = Str_ConvertStrCodToLongCod (row[0]);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return NotCod;
return DB_QuerySELECTCode ("can not get code of note",
"SELECT NotCod"
" FROM tml_pubs"
" WHERE PubCod=%ld",
PubCod);
}
/*****************************************************************************/

View File

@ -1252,7 +1252,6 @@ static void Tml_Not_RemoveNote (void)
static void Tml_Not_RemoveNoteMediaAndDBEntries (struct Tml_Not_Note *Not)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long PubCod;
unsigned long NumComms;
unsigned long NumComm;
@ -1268,8 +1267,7 @@ static void Tml_Not_RemoveNoteMediaAndDBEntries (struct Tml_Not_Note *Not)
NumComm++)
{
/* Get code of comment **/
row = mysql_fetch_row (mysql_res);
PubCod = Str_ConvertStrCodToLongCod (row[0]);
PubCod = DB_GetNextCode (mysql_res);
/* Remove media associated to comment
and delete comment from database */

View File

@ -149,9 +149,9 @@ static void Tml_Usr_GetAndShowSharersOrFavers (Tml_Usr_FavSha_t FavSha,
if (NumUsrs)
NumFirstUsrs =
Tml_Usr_GetListFaversOrSharers (FavSha,Cod,UsrCod,
HowManyUsrs == Tml_Usr_SHOW_FEW_USRS ? Tml_Usr_DEF_USRS_SHOWN :
Tml_Usr_MAX_USRS_SHOWN,
&mysql_res);
HowManyUsrs == Tml_Usr_SHOW_FEW_USRS ? Tml_Usr_DEF_USRS_SHOWN :
Tml_Usr_MAX_USRS_SHOWN,
&mysql_res);
else
NumFirstUsrs = 0;
@ -167,8 +167,8 @@ static void Tml_Usr_GetAndShowSharersOrFavers (Tml_Usr_FavSha_t FavSha,
if (NumFirstUsrs < NumUsrs) // Not all are shown
/* Clickable ellipsis to show all users */
Tml_Frm_PutFormToSeeAllFaversSharers (Action[FavSha],
ParamFormat[FavSha],Cod,
HowManyUsrs);
ParamFormat[FavSha],Cod,
HowManyUsrs);
HTM_DIV_End ();
/***** Free structure that stores the query result *****/
@ -190,7 +190,6 @@ static void Tml_Usr_ShowNumSharersOrFavers (unsigned NumUsrs)
static void Tml_Usr_ListSharersOrFavers (MYSQL_RES **mysql_res,
unsigned NumUsrs,unsigned NumFirstUsrs)
{
MYSQL_ROW row;
unsigned NumUsr;
struct UsrData UsrDat;
@ -211,8 +210,7 @@ static void Tml_Usr_ListSharersOrFavers (MYSQL_RES **mysql_res,
NumUsr++)
{
/***** Get user's code *****/
row = mysql_fetch_row (*mysql_res);
UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]);
UsrDat.UsrCod = DB_GetNextCode (*mysql_res);
/***** Get user's data and show user's photo *****/
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS))

View File

@ -715,76 +715,86 @@ static void Tmt_FillTimeTableFromDB (struct Tmt_Timetable *Timetable,
switch (Gbl.Crs.Grps.WhichGrps)
{
case Grp_MY_GROUPS:
NumRows = DB_QuerySELECT (&mysql_res,"can not get timetable",
"SELECT tmt_courses.Weekday,"
"TIME_TO_SEC(tmt_courses.StartTime) AS S,"
"TIME_TO_SEC(tmt_courses.Duration) AS D,"
"tmt_courses.Info,"
"tmt_courses.ClassType,"
"tmt_courses.GrpCod,"
"tmt_courses.CrsCod"
" FROM tmt_courses,"
"crs_users"
" WHERE crs_users.UsrCod=%ld"
" AND tmt_courses.GrpCod=-1"
" AND tmt_courses.CrsCod=crs_users.CrsCod"
" UNION DISTINCT "
"SELECT tmt_courses.Weekday,"
"TIME_TO_SEC(tmt_courses.StartTime) AS S,"
"TIME_TO_SEC(tmt_courses.Duration) AS D,"
"tmt_courses.Info,"
"tmt_courses.ClassType,"
"tmt_courses.GrpCod,"
"tmt_courses.CrsCod"
" FROM grp_users,"
"tmt_courses"
" WHERE grp_users.UsrCod=%ld"
" AND grp_users.GrpCod=tmt_courses.GrpCod"
" UNION "
"SELECT Weekday,"
"TIME_TO_SEC(StartTime) AS S,"
"TIME_TO_SEC(Duration) AS D,"
"Info,"
"'tutoring' AS ClassType,"
"-1 AS GrpCod,"
"-1 AS CrsCod"
" FROM tmt_tutoring"
" WHERE UsrCod=%ld"
" ORDER BY Weekday,S,ClassType,"
"GrpCod,Info,D DESC,CrsCod",
UsrCod,UsrCod,UsrCod);
NumRows =
DB_QuerySELECT (&mysql_res,"can not get timetable",
"SELECT tmt_courses.Weekday," // row[0]
"TIME_TO_SEC(tmt_courses.StartTime) AS S," // row[1]
"TIME_TO_SEC(tmt_courses.Duration) AS D," // row[2]
"tmt_courses.Info," // row[3]
"tmt_courses.ClassType," // row[4]
"tmt_courses.GrpCod," // row[5]
"tmt_courses.CrsCod" // row[6]
" FROM tmt_courses,"
"crs_users"
" WHERE crs_users.UsrCod=%ld"
" AND tmt_courses.GrpCod=-1"
" AND tmt_courses.CrsCod=crs_users.CrsCod"
" UNION DISTINCT "
"SELECT tmt_courses.Weekday," // row[0]
"TIME_TO_SEC(tmt_courses.StartTime) AS S," // row[1]
"TIME_TO_SEC(tmt_courses.Duration) AS D," // row[2]
"tmt_courses.Info," // row[3]
"tmt_courses.ClassType," // row[4]
"tmt_courses.GrpCod," // row[5]
"tmt_courses.CrsCod" // row[6]
" FROM grp_users,"
"tmt_courses"
" WHERE grp_users.UsrCod=%ld"
" AND grp_users.GrpCod=tmt_courses.GrpCod"
" UNION "
"SELECT Weekday," // row[0]
"TIME_TO_SEC(StartTime) AS S," // row[1]
"TIME_TO_SEC(Duration) AS D," // row[2]
"Info," // row[3]
"'tutoring' AS ClassType," // row[4]
"-1 AS GrpCod," // row[5]
"-1 AS CrsCod" // row[6]
" FROM tmt_tutoring"
" WHERE UsrCod=%ld"
" ORDER BY Weekday,"
"S,"
"ClassType,"
"GrpCod,"
"Info,"
"D DESC,"
"CrsCod",
UsrCod,
UsrCod,
UsrCod);
break;
case Grp_ALL_GROUPS:
NumRows = DB_QuerySELECT (&mysql_res,"can not get timetable",
"SELECT tmt_courses.Weekday," // row[0]
"TIME_TO_SEC(tmt_courses.StartTime) AS S," // row[1]
"TIME_TO_SEC(tmt_courses.Duration) AS D," // row[2]
"tmt_courses.Info," // row[3]
"tmt_courses.ClassType," // row[4]
"tmt_courses.GrpCod," // row[5]
"tmt_courses.CrsCod" // row[6]
" FROM tmt_courses,"
"crs_users"
" WHERE crs_users.UsrCod=%ld"
" AND tmt_courses.CrsCod=crs_users.CrsCod"
" UNION "
"SELECT Weekday," // row[0]
"TIME_TO_SEC(StartTime) AS S,"
"TIME_TO_SEC(Duration) AS D,"
"Info,"
"'tutoring' AS ClassType,"
"-1 AS GrpCod,"
"-1 AS CrsCod"
" FROM tmt_tutoring"
" WHERE UsrCod=%ld"
" ORDER BY Weekday,"
"S,"
"ClassType,"
"GrpCod,"
"Info,"
"D DESC,"
"CrsCod",
UsrCod,UsrCod);
NumRows =
DB_QuerySELECT (&mysql_res,"can not get timetable",
"SELECT tmt_courses.Weekday," // row[0]
"TIME_TO_SEC(tmt_courses.StartTime) AS S," // row[1]
"TIME_TO_SEC(tmt_courses.Duration) AS D," // row[2]
"tmt_courses.Info," // row[3]
"tmt_courses.ClassType," // row[4]
"tmt_courses.GrpCod," // row[5]
"tmt_courses.CrsCod" // row[6]
" FROM tmt_courses,"
"crs_users"
" WHERE crs_users.UsrCod=%ld"
" AND tmt_courses.CrsCod=crs_users.CrsCod"
" UNION "
"SELECT Weekday," // row[0]
"TIME_TO_SEC(StartTime) AS S," // row[1]
"TIME_TO_SEC(Duration) AS D," // row[2]
"Info," // row[3]
"'tutoring' AS ClassType," // row[4]
"-1 AS GrpCod," // row[5]
"-1 AS CrsCod" // row[6]
" FROM tmt_tutoring"
" WHERE UsrCod=%ld"
" ORDER BY Weekday,"
"S,"
"ClassType,"
"GrpCod,"
"Info,"
"D DESC,"
"CrsCod",
UsrCod,
UsrCod);
break;
}
break;
@ -792,70 +802,73 @@ 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 = DB_QuerySELECT (&mysql_res,"can not get timetable",
"SELECT Weekday," // row[0]
"TIME_TO_SEC(StartTime) AS S," // row[1]
"TIME_TO_SEC(Duration) AS D," // row[2]
"Info," // row[3]
"ClassType," // row[4]
"GrpCod" // row[5]
" FROM tmt_courses"
" WHERE CrsCod=%ld"
" ORDER BY Weekday,"
"S,"
"ClassType,"
"GrpCod,"
"Info,"
"D DESC",
Gbl.Hierarchy.Crs.CrsCod);
NumRows =
DB_QuerySELECT (&mysql_res,"can not get timetable",
"SELECT Weekday," // row[0]
"TIME_TO_SEC(StartTime) AS S," // row[1]
"TIME_TO_SEC(Duration) AS D," // row[2]
"Info," // row[3]
"ClassType," // row[4]
"GrpCod" // row[5]
" FROM tmt_courses"
" WHERE CrsCod=%ld"
" ORDER BY Weekday,"
"S,"
"ClassType,"
"GrpCod,"
"Info,"
"D DESC",
Gbl.Hierarchy.Crs.CrsCod);
else
NumRows = DB_QuerySELECT (&mysql_res,"can not get timetable",
"SELECT tmt_courses.Weekday," // row[0]
"TIME_TO_SEC(tmt_courses.StartTime) AS S," // row[1]
"TIME_TO_SEC(tmt_courses.Duration) AS D," // row[2]
"tmt_courses.Info," // row[3]
"tmt_courses.ClassType," // row[4]
"tmt_courses.GrpCod" // row[5]
" FROM tmt_courses,"
"crs_users"
" WHERE tmt_courses.CrsCod=%ld"
" AND tmt_courses.GrpCod=-1"
" AND crs_users.UsrCod=%ld"
" AND tmt_courses.CrsCod=crs_users.CrsCod"
" UNION DISTINCT "
"SELECT tmt_courses.Weekday," // row[0]
"TIME_TO_SEC(tmt_courses.StartTime) AS S," // row[1]
"TIME_TO_SEC(tmt_courses.Duration) AS D," // row[2]
"tmt_courses.Info," // row[3]
"tmt_courses.ClassType," // row[4]
"tmt_courses.GrpCod" // row[5]
" FROM tmt_courses,"
"grp_users"
" WHERE tmt_courses.CrsCod=%ld"
" AND grp_users.UsrCod=%ld"
" AND tmt_courses.GrpCod=grp_users.GrpCod"
" ORDER BY Weekday,"
"S,"
"ClassType,"
"GrpCod,"
"Info,"
"D DESC",
Gbl.Hierarchy.Crs.CrsCod,UsrCod,
Gbl.Hierarchy.Crs.CrsCod,UsrCod);
NumRows =
DB_QuerySELECT (&mysql_res,"can not get timetable",
"SELECT tmt_courses.Weekday," // row[0]
"TIME_TO_SEC(tmt_courses.StartTime) AS S," // row[1]
"TIME_TO_SEC(tmt_courses.Duration) AS D," // row[2]
"tmt_courses.Info," // row[3]
"tmt_courses.ClassType," // row[4]
"tmt_courses.GrpCod" // row[5]
" FROM tmt_courses,"
"crs_users"
" WHERE tmt_courses.CrsCod=%ld"
" AND tmt_courses.GrpCod=-1"
" AND crs_users.UsrCod=%ld"
" AND tmt_courses.CrsCod=crs_users.CrsCod"
" UNION DISTINCT "
"SELECT tmt_courses.Weekday," // row[0]
"TIME_TO_SEC(tmt_courses.StartTime) AS S," // row[1]
"TIME_TO_SEC(tmt_courses.Duration) AS D," // row[2]
"tmt_courses.Info," // row[3]
"tmt_courses.ClassType," // row[4]
"tmt_courses.GrpCod" // row[5]
" FROM tmt_courses,"
"grp_users"
" WHERE tmt_courses.CrsCod=%ld"
" AND grp_users.UsrCod=%ld"
" AND tmt_courses.GrpCod=grp_users.GrpCod"
" ORDER BY Weekday,"
"S,"
"ClassType,"
"GrpCod,"
"Info,"
"D DESC",
Gbl.Hierarchy.Crs.CrsCod,UsrCod,
Gbl.Hierarchy.Crs.CrsCod,UsrCod);
break;
case Tmt_TUTORING_TIMETABLE:
NumRows = DB_QuerySELECT (&mysql_res,"can not get timetable",
"SELECT Weekday," // row[0]
"TIME_TO_SEC(StartTime) AS S," // row[1]
"TIME_TO_SEC(Duration) AS D," // row[2]
"Info" // row[3]
" FROM tmt_tutoring"
" WHERE UsrCod=%ld"
" ORDER BY Weekday,"
"S,"
"Info,"
"D DESC",
UsrCod);
NumRows =
DB_QuerySELECT (&mysql_res,"can not get timetable",
"SELECT Weekday," // row[0]
"TIME_TO_SEC(StartTime) AS S," // row[1]
"TIME_TO_SEC(Duration) AS D," // row[2]
"Info" // row[3]
" FROM tmt_tutoring"
" WHERE UsrCod=%ld"
" ORDER BY Weekday,"
"S,"
"Info,"
"D DESC",
UsrCod);
break;
}

View File

@ -1766,9 +1766,9 @@ void Usr_GetMyCourses (void)
NumCrss =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get which courses"
" you belong to",
"SELECT CrsCod,"
"Role,"
"DegCod"
"SELECT CrsCod," // row[0]
"Role," // row[1]
"DegCod" // row[2]
" FROM my_courses_tmp");
for (NumCrs = 0;
NumCrs < NumCrss;
@ -2269,8 +2269,8 @@ unsigned long Usr_GetInssFromUsr (long UsrCod,long CtyCod,MYSQL_RES **mysql_res)
if (CtyCod > 0)
return DB_QuerySELECT (mysql_res,"can not get the institutions"
" a user belongs to",
"SELECT ins_instits.InsCod,"
"MAX(crs_users.Role)"
"SELECT ins_instits.InsCod," // row[0]
"MAX(crs_users.Role)" // row[1]
" FROM crs_users,"
"crs_courses,"
"deg_degrees,"
@ -2288,8 +2288,8 @@ unsigned long Usr_GetInssFromUsr (long UsrCod,long CtyCod,MYSQL_RES **mysql_res)
else
return DB_QuerySELECT (mysql_res,"can not get the ins_instits"
" a user belongs to",
"SELECT ins_instits.InsCod,"
"MAX(crs_users.Role)"
"SELECT ins_instits.InsCod," // row[0]
"MAX(crs_users.Role)" // row[1]
" FROM crs_users,"
"crs_courses,"
"deg_degrees,"
@ -2316,8 +2316,8 @@ unsigned long Usr_GetCtrsFromUsr (long UsrCod,long InsCod,MYSQL_RES **mysql_res)
if (InsCod > 0)
return DB_QuerySELECT (mysql_res,"can not check the centers"
" a user belongs to",
"SELECT ctr_centers.CtrCod,"
"MAX(crs_users.Role)"
"SELECT ctr_centers.CtrCod," // row[0]
"MAX(crs_users.Role)" // row[1]
" FROM crs_users,"
"crs_courses,"
"deg_degrees,"
@ -2333,8 +2333,8 @@ unsigned long Usr_GetCtrsFromUsr (long UsrCod,long InsCod,MYSQL_RES **mysql_res)
else
return DB_QuerySELECT (mysql_res,"can not check the centers"
" a user belongs to",
"SELECT deg_degrees.CtrCod,"
"MAX(crs_users.Role)"
"SELECT deg_degrees.CtrCod," // row[0]
"MAX(crs_users.Role)" // row[1]
" FROM crs_users,"
"crs_courses,"
"deg_degrees,"
@ -2359,8 +2359,8 @@ unsigned long Usr_GetDegsFromUsr (long UsrCod,long CtrCod,MYSQL_RES **mysql_res)
if (CtrCod > 0)
return DB_QuerySELECT (mysql_res,"can not check the degrees"
" a user belongs to",
"SELECT deg_degrees.DegCod,"
"MAX(crs_users.Role)"
"SELECT deg_degrees.DegCod," // row[0]
"MAX(crs_users.Role)" // row[1]
" FROM crs_users,"
"crs_courses,"
"deg_degrees"
@ -2374,8 +2374,8 @@ unsigned long Usr_GetDegsFromUsr (long UsrCod,long CtrCod,MYSQL_RES **mysql_res)
else
return DB_QuerySELECT (mysql_res,"can not check the degrees"
" a user belongs to",
"SELECT deg_degrees.DegCod,"
"MAX(crs_users.Role)"
"SELECT deg_degrees.DegCod," // row[0]
"MAX(crs_users.Role)" // row[1]
" FROM crs_users,"
"crs_courses,"
"deg_degrees"
@ -2398,9 +2398,9 @@ unsigned long Usr_GetCrssFromUsr (long UsrCod,long DegCod,MYSQL_RES **mysql_res)
if (DegCod > 0) // Courses in a degree
return DB_QuerySELECT (mysql_res,"can not get the courses"
" a user belongs to",
"SELECT crs_users.CrsCod,"
"crs_users.Role,"
"crs_courses.DegCod"
"SELECT crs_users.CrsCod," // row[0]
"crs_users.Role," // row[1]
"crs_courses.DegCod" // row[2]
" FROM crs_users,"
"crs_courses"
" WHERE crs_users.UsrCod=%ld"
@ -2411,9 +2411,9 @@ unsigned long Usr_GetCrssFromUsr (long UsrCod,long DegCod,MYSQL_RES **mysql_res)
else // All the courses
return DB_QuerySELECT (mysql_res,"can not get the courses"
" a user belongs to",
"SELECT crs_users.CrsCod,"
"crs_users.Role,"
"crs_courses.DegCod"
"SELECT crs_users.CrsCod," // row[0]
"crs_users.Role," // row[1]
"crs_courses.DegCod" // row[2]
" FROM crs_users,"
"crs_courses,"
"deg_degrees"
@ -4080,31 +4080,16 @@ static void Usr_WriteUsrData (const char *BgColor,
long Usr_GetRamdomStdFromCrs (long CrsCod)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long UsrCod = -1L; // -1 means user not found
/***** Get a random student from current course from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get a random student"
" from the current course",
"SELECT UsrCod"
" FROM crs_users"
" WHERE CrsCod=%ld"
" AND Role=%u"
" ORDER BY RAND()"
" LIMIT 1",
CrsCod,
(unsigned) Rol_STD))
{
/***** Get user code *****/
row = mysql_fetch_row (mysql_res);
UsrCod = Str_ConvertStrCodToLongCod (row[0]);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return UsrCod;
return DB_QuerySELECTCode ("can not get a random student from a course",
"SELECT UsrCod"
" FROM crs_users"
" WHERE CrsCod=%ld"
" AND Role=%u"
" ORDER BY RAND()"
" LIMIT 1",
CrsCod,
(unsigned) Rol_STD);
}
/*****************************************************************************/
@ -4114,31 +4099,18 @@ long Usr_GetRamdomStdFromCrs (long CrsCod)
long Usr_GetRamdomStdFromGrp (long GrpCod)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long UsrCod = -1L; // -1 means user not found
/***** Get a random student from a group from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get a random student from a group",
"SELECT grp_users.UsrCod" // row[0]
" FROM grp_users,"
"crs_users"
" WHERE grp_users.GrpCod=%ld"
" AND grp_users.UsrCod=crs_users.UsrCod"
" AND crs_users.Role=%u"
" ORDER BY RAND()"
" LIMIT 1",
GrpCod,(unsigned) Rol_STD))
{
/***** Get user code *****/
row = mysql_fetch_row (mysql_res);
UsrCod = Str_ConvertStrCodToLongCod (row[0]);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
return UsrCod;
return DB_QuerySELECTCode ("can not get a random student from a group",
"SELECT grp_users.UsrCod"
" FROM grp_users,"
"crs_users"
" WHERE grp_users.GrpCod=%ld"
" AND grp_users.UsrCod=crs_users.UsrCod"
" AND crs_users.Role=%u"
" ORDER BY RAND()"
" LIMIT 1",
GrpCod,
(unsigned) Rol_STD);
}
/*****************************************************************************/
@ -7790,7 +7762,7 @@ static void Usr_GetMyUsrListTypeFromDB (void)
/***** Get type of listing of users from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get type of listing of users",
"SELECT UsrListType"
"SELECT UsrListType" // row[0]
" FROM crs_user_settings"
" WHERE UsrCod=%ld"
" AND CrsCod=%ld",
@ -7899,7 +7871,7 @@ static void Usr_GetMyColsClassPhotoFromDB (void)
/***** Get number of columns in class photo from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get number of columns"
" in class photo",
"SELECT ColsClassPhoto"
"SELECT ColsClassPhoto" // row[0]
" FROM crs_user_settings"
" WHERE UsrCod=%ld"
" AND CrsCod=%ld",
@ -8008,7 +7980,7 @@ void Usr_GetMyPrefAboutListWithPhotosFromDB (void)
/***** Get if listing of users must show photos from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not check if listing of users"
" must show photos",
"SELECT ListWithPhotos"
"SELECT ListWithPhotos" // row[0]
" FROM crs_user_settings"
" WHERE UsrCod=%ld"
" AND CrsCod=%ld",
@ -9746,13 +9718,13 @@ static double Usr_GetNumCrssPerUsr (Hie_Lvl_Level_t Scope,long Cod,Rol_Role_t Ro
case Hie_Lvl_SYS:
if (Role == Rol_UNK) // Any user
DB_QuerySELECT (&mysql_res,"can not get number of courses per user",
"SELECT AVG(NumCrss)"
"SELECT AVG(NumCrss)" // row[0]
" FROM (SELECT COUNT(CrsCod) AS NumCrss"
" FROM crs_users"
" GROUP BY UsrCod) AS NumCrssTable");
else
DB_QuerySELECT (&mysql_res,"can not get number of courses per user",
"SELECT AVG(NumCrss)"
"SELECT AVG(NumCrss)" // row[0]
" FROM (SELECT COUNT(CrsCod) AS NumCrss"
" FROM crs_users"
" WHERE Role=%u"
@ -9762,7 +9734,7 @@ static double Usr_GetNumCrssPerUsr (Hie_Lvl_Level_t Scope,long Cod,Rol_Role_t Ro
case Hie_Lvl_CTY:
if (Role == Rol_UNK) // Any user
DB_QuerySELECT (&mysql_res,"can not get number of courses per user",
"SELECT AVG(NumCrss)"
"SELECT AVG(NumCrss)" // row[0]
" FROM (SELECT COUNT(crs_users.CrsCod) AS NumCrss"
" FROM ins_instits,"
"ctr_centers,"
@ -9778,7 +9750,7 @@ static double Usr_GetNumCrssPerUsr (Hie_Lvl_Level_t Scope,long Cod,Rol_Role_t Ro
Cod);
else
DB_QuerySELECT (&mysql_res,"can not get number of courses per user",
"SELECT AVG(NumCrss)"
"SELECT AVG(NumCrss)" // row[0]
" FROM (SELECT COUNT(crs_users.CrsCod) AS NumCrss"
" FROM ins_instits,"
"ctr_centers,"
@ -9798,7 +9770,7 @@ static double Usr_GetNumCrssPerUsr (Hie_Lvl_Level_t Scope,long Cod,Rol_Role_t Ro
case Hie_Lvl_INS:
if (Role == Rol_UNK) // Any user
DB_QuerySELECT (&mysql_res,"can not get number of courses per user",
"SELECT AVG(NumCrss)"
"SELECT AVG(NumCrss)" // row[0]
" FROM (SELECT COUNT(crs_users.CrsCod) AS NumCrss"
" FROM ctr_centers,"
"deg_degrees,"
@ -9812,7 +9784,7 @@ static double Usr_GetNumCrssPerUsr (Hie_Lvl_Level_t Scope,long Cod,Rol_Role_t Ro
Cod);
else
DB_QuerySELECT (&mysql_res,"can not get number of courses per user",
"SELECT AVG(NumCrss)"
"SELECT AVG(NumCrss)" // row[0]
" FROM (SELECT COUNT(crs_users.CrsCod) AS NumCrss"
" FROM ctr_centers,"
"deg_degrees,"
@ -9830,7 +9802,7 @@ static double Usr_GetNumCrssPerUsr (Hie_Lvl_Level_t Scope,long Cod,Rol_Role_t Ro
case Hie_Lvl_CTR:
if (Role == Rol_UNK) // Any user
DB_QuerySELECT (&mysql_res,"can not get number of courses per user",
"SELECT AVG(NumCrss)"
"SELECT AVG(NumCrss)" // row[0]
" FROM (SELECT COUNT(crs_users.CrsCod) AS NumCrss"
" FROM deg_degrees,"
"crs_courses,"
@ -9842,7 +9814,7 @@ static double Usr_GetNumCrssPerUsr (Hie_Lvl_Level_t Scope,long Cod,Rol_Role_t Ro
Cod);
else
DB_QuerySELECT (&mysql_res,"can not get number of courses per user",
"SELECT AVG(NumCrss)"
"SELECT AVG(NumCrss)" // row[0]
" FROM (SELECT COUNT(crs_users.CrsCod) AS NumCrss"
" FROM deg_degrees,"
"crs_courses,"
@ -9858,7 +9830,7 @@ static double Usr_GetNumCrssPerUsr (Hie_Lvl_Level_t Scope,long Cod,Rol_Role_t Ro
case Hie_Lvl_DEG:
if (Role == Rol_UNK) // Any user
DB_QuerySELECT (&mysql_res,"can not get number of courses per user",
"SELECT AVG(NumCrss)"
"SELECT AVG(NumCrss)" // row[0]
" FROM (SELECT COUNT(crs_users.CrsCod) AS NumCrss"
" FROM crs_courses,"
"crs_users"
@ -9868,7 +9840,7 @@ static double Usr_GetNumCrssPerUsr (Hie_Lvl_Level_t Scope,long Cod,Rol_Role_t Ro
Cod);
else
DB_QuerySELECT (&mysql_res,"can not get number of courses per user",
"SELECT AVG(NumCrss)"
"SELECT AVG(NumCrss)" // row[0]
" FROM (SELECT COUNT(crs_users.CrsCod) AS NumCrss"
" FROM crs_courses,"
"crs_users"
@ -9936,13 +9908,13 @@ static double Usr_GetNumUsrsPerCrs (Hie_Lvl_Level_t Scope,long Cod,Rol_Role_t Ro
case Hie_Lvl_SYS:
if (Role == Rol_UNK) // Any user
DB_QuerySELECT (&mysql_res,"can not get number of users per course",
"SELECT AVG(NumUsrs)"
"SELECT AVG(NumUsrs)" // row[0]
" FROM (SELECT COUNT(UsrCod) AS NumUsrs"
" FROM crs_users"
" GROUP BY CrsCod) AS NumUsrsTable");
else
DB_QuerySELECT (&mysql_res,"can not get number of users per course",
"SELECT AVG(NumUsrs)"
"SELECT AVG(NumUsrs)" // row[0]
" FROM (SELECT COUNT(UsrCod) AS NumUsrs"
" FROM crs_users"
" WHERE Role=%u GROUP BY CrsCod) AS NumUsrsTable",
@ -9951,7 +9923,7 @@ static double Usr_GetNumUsrsPerCrs (Hie_Lvl_Level_t Scope,long Cod,Rol_Role_t Ro
case Hie_Lvl_CTY:
if (Role == Rol_UNK) // Any user
DB_QuerySELECT (&mysql_res,"can not get number of users per course",
"SELECT AVG(NumUsrs)"
"SELECT AVG(NumUsrs)" // row[0]
" FROM (SELECT COUNT(crs_users.UsrCod) AS NumUsrs"
" FROM ins_instits,"
"ctr_centers,"
@ -9967,7 +9939,7 @@ static double Usr_GetNumUsrsPerCrs (Hie_Lvl_Level_t Scope,long Cod,Rol_Role_t Ro
Cod);
else
DB_QuerySELECT (&mysql_res,"can not get number of users per course",
"SELECT AVG(NumUsrs)"
"SELECT AVG(NumUsrs)" // row[0]
" FROM (SELECT COUNT(crs_users.UsrCod) AS NumUsrs"
" FROM ins_instits,"
"ctr_centers,"
@ -9987,7 +9959,7 @@ static double Usr_GetNumUsrsPerCrs (Hie_Lvl_Level_t Scope,long Cod,Rol_Role_t Ro
case Hie_Lvl_INS:
if (Role == Rol_UNK) // Any user
DB_QuerySELECT (&mysql_res,"can not get number of users per course",
"SELECT AVG(NumUsrs)"
"SELECT AVG(NumUsrs)" // row[0]
" FROM (SELECT COUNT(crs_users.UsrCod) AS NumUsrs"
" FROM ctr_centers,"
"deg_degrees,"
@ -10001,7 +9973,7 @@ static double Usr_GetNumUsrsPerCrs (Hie_Lvl_Level_t Scope,long Cod,Rol_Role_t Ro
Cod);
else
DB_QuerySELECT (&mysql_res,"can not get number of users per course",
"SELECT AVG(NumUsrs)"
"SELECT AVG(NumUsrs)" // row[0]
" FROM (SELECT COUNT(crs_users.UsrCod) AS NumUsrs"
" FROM ctr_centers,"
"deg_degrees,"
@ -10019,7 +9991,7 @@ static double Usr_GetNumUsrsPerCrs (Hie_Lvl_Level_t Scope,long Cod,Rol_Role_t Ro
case Hie_Lvl_CTR:
if (Role == Rol_UNK) // Any user
DB_QuerySELECT (&mysql_res,"can not get number of users per course",
"SELECT AVG(NumUsrs)"
"SELECT AVG(NumUsrs)" // row[0]
" FROM (SELECT COUNT(crs_users.UsrCod) AS NumUsrs"
" FROM deg_degrees,"
"crs_courses,"
@ -10031,7 +10003,7 @@ static double Usr_GetNumUsrsPerCrs (Hie_Lvl_Level_t Scope,long Cod,Rol_Role_t Ro
Cod);
else
DB_QuerySELECT (&mysql_res,"can not get number of users per course",
"SELECT AVG(NumUsrs)"
"SELECT AVG(NumUsrs)" // row[0]
" FROM (SELECT COUNT(crs_users.UsrCod) AS NumUsrs"
" FROM deg_degrees,"
"crs_courses,"
@ -10047,7 +10019,7 @@ static double Usr_GetNumUsrsPerCrs (Hie_Lvl_Level_t Scope,long Cod,Rol_Role_t Ro
case Hie_Lvl_DEG:
if (Role == Rol_UNK) // Any user
DB_QuerySELECT (&mysql_res,"can not get number of users per course",
"SELECT AVG(NumUsrs)"
"SELECT AVG(NumUsrs)" // row[0]
" FROM (SELECT COUNT(crs_users.UsrCod) AS NumUsrs"
" FROM crs_courses,"
"crs_users"
@ -10057,7 +10029,7 @@ static double Usr_GetNumUsrsPerCrs (Hie_Lvl_Level_t Scope,long Cod,Rol_Role_t Ro
Cod);
else
DB_QuerySELECT (&mysql_res,"can not get number of users per course",
"SELECT AVG(NumUsrs)"
"SELECT AVG(NumUsrs)" // row[0]
" FROM (SELECT COUNT(crs_users.UsrCod) AS NumUsrs"
" FROM crs_courses,"
"crs_users"