Version 21.52: Nov 05, 2021 Changed SELECT COUNT to SELECT EXISTS in some queries.

This commit is contained in:
acanas 2021-11-05 23:41:26 +01:00
parent df0dc40476
commit 25091b6664
53 changed files with 932 additions and 838 deletions

View File

@ -535,11 +535,12 @@ static int API_GenerateNewWSKey (struct soap *soap,
Str_Copy (WSKey,Gbl.UniqueNameEncrypted,API_BYTES_WS_KEY); Str_Copy (WSKey,Gbl.UniqueNameEncrypted,API_BYTES_WS_KEY);
/***** Check that key does not exist in database *****/ /***** Check that key does not exist in database *****/
if (DB_QueryCOUNT ("can not get existence of key", if (DB_QueryEXISTS ("can not get existence of key",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM api_keys" "(SELECT *"
" WHERE WSKey='%s'", " FROM api_keys"
WSKey)) " WHERE WSKey='%s')",
WSKey))
return soap_receiver_fault (soap, return soap_receiver_fault (soap,
"Error when generating key", "Error when generating key",
"Generated key already existed in database"); "Generated key already existed in database");
@ -769,11 +770,12 @@ static int API_CheckParamsNewAccount (char *NewNickWithArr, // Input
Str_RemoveLeadingArrobas (CopyOfNewNick); Str_RemoveLeadingArrobas (CopyOfNewNick);
/***** Check if the new nickname matches any of the nicknames of other users *****/ /***** Check if the new nickname matches any of the nicknames of other users *****/
if (DB_QueryCOUNT ("can not check if nickname already existed", if (DB_QueryEXISTS ("can not check if nickname already existed",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM usr_nicknames" "(SELECT *"
" WHERE Nickname='%s'", // A nickname of another user is the same that this nickname " FROM usr_nicknames"
CopyOfNewNick)) // Already without leading arrobas " WHERE Nickname='%s')", // A nickname of another user is the same that this nickname
CopyOfNewNick)) // Already without leading arrobas
return API_CHECK_NEW_ACCOUNT_NICKNAME_REGISTERED_BY_ANOTHER_USER; return API_CHECK_NEW_ACCOUNT_NICKNAME_REGISTERED_BY_ANOTHER_USER;
/***** Output value of nickname without leading arrobas *****/ /***** Output value of nickname without leading arrobas *****/
@ -786,12 +788,13 @@ static int API_CheckParamsNewAccount (char *NewNickWithArr, // Input
if (Mai_CheckIfEmailIsValid (NewEmail)) // New email is valid if (Mai_CheckIfEmailIsValid (NewEmail)) // New email is valid
{ {
/***** Check if the new email matches any of the confirmed emails of other users *****/ /***** Check if the new email matches any of the confirmed emails of other users *****/
if (DB_QueryCOUNT ("can not check if email already existed", if (DB_QueryEXISTS ("can not check if email already existed",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM usr_emails" "(SELECT *"
" WHERE E_mail='%s'" " FROM usr_emails"
" AND Confirmed='Y'", " WHERE E_mail='%s'"
NewEmail)) // An email of another user is the same that my email " AND Confirmed='Y')",
NewEmail)) // An email of another user is the same that my email
return API_CHECK_NEW_ACCOUNT_EMAIL_REGISTERED_BY_ANOTHER_USER; return API_CHECK_NEW_ACCOUNT_EMAIL_REGISTERED_BY_ANOTHER_USER;
} }
else // New email is not valid else // New email is not valid
@ -6052,23 +6055,24 @@ int swad__getLastLocation (struct soap *soap,
The other user does not have to share any course with me, The other user does not have to share any course with me,
but at least some course of each one has to share center. but at least some course of each one has to share center.
*/ */
if (DB_QueryCOUNT ("can not get session data", if (DB_QueryEXISTS ("can not check if you can see user location",
"SELECT COUNT(*) FROM " "SELECT EXISTS"
"(SELECT DISTINCT deg_degrees.CtrCod" "(SELECT *"
" FROM crs_users," " FROM (SELECT DISTINCT deg_degrees.CtrCod"
"crs_courses," " FROM crs_users,"
"deg_degrees" "crs_courses,"
" WHERE crs_users.UsrCod=%ld" "deg_degrees"
" AND crs_users.CrsCod=crs_courses.CrsCod" " WHERE crs_users.UsrCod=%ld"
" AND crs_courses.DegCod=deg_degrees.DegCod) AS C1," // centers of my courses " AND crs_users.CrsCod=crs_courses.CrsCod"
"(SELECT DISTINCT deg_degrees.CtrCod" " AND crs_courses.DegCod=deg_degrees.DegCod) AS C1," // centers of my courses
" FROM crs_users," "(SELECT DISTINCT deg_degrees.CtrCod"
"crs_courses," " FROM crs_users,"
"deg_degrees" "crs_courses,"
" WHERE crs_users.UsrCod=%d" "deg_degrees"
" AND crs_users.CrsCod=crs_courses.CrsCod" " WHERE crs_users.UsrCod=%d"
" AND crs_courses.DegCod=deg_degrees.DegCod) AS C2" // centers of user's courses " AND crs_users.CrsCod=crs_courses.CrsCod"
" WHERE C1.CtrCod=C2.CtrCod", " AND crs_courses.DegCod=deg_degrees.DegCod) AS C2" // centers of user's courses
" WHERE C1.CtrCod=C2.CtrCod)",
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
userCode)) userCode))
{ {

View File

@ -110,15 +110,16 @@ unsigned ID_DB_GetIDsFromUsrCod (MYSQL_RES **mysql_res,long UsrCod)
bool ID_DB_CheckIfConfirmed (long UsrCod,const char ID[ID_MAX_BYTES_USR_ID + 1]) bool ID_DB_CheckIfConfirmed (long UsrCod,const char ID[ID_MAX_BYTES_USR_ID + 1])
{ {
/***** Get if ID is confirmed from database *****/ return
return (DB_QueryCOUNT ("can not check if ID is confirmed", DB_QueryEXISTS ("can not check if ID is confirmed",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM usr_ids" "(SELECT *"
" WHERE UsrCod=%ld" " FROM usr_ids"
" AND UsrID='%s'" " WHERE UsrCod=%ld"
" AND Confirmed='Y'", " AND UsrID='%s'"
UsrCod, " AND Confirmed='Y')",
ID) != 0); UsrCod,
ID);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -127,11 +128,13 @@ bool ID_DB_CheckIfConfirmed (long UsrCod,const char ID[ID_MAX_BYTES_USR_ID + 1])
bool ID_DB_FindStrInUsrsIDs (const char *Str) bool ID_DB_FindStrInUsrsIDs (const char *Str)
{ {
return (DB_QueryCOUNT ("can not check if a string matches any user's ID", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if a string matches any user's ID",
" FROM usr_ids" "SELECT EXISTS"
" WHERE UsrID='%s'", "(SELECT *"
Str) != 0); " FROM usr_ids"
" WHERE UsrID='%s')",
Str);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -787,8 +787,8 @@ static void Acc_CreateNewEncryptedUsrCod (struct UsrData *UsrDat)
{ {
Str_CreateRandomAlphanumStr (RandomStr,LENGTH_RANDOM_STR); Str_CreateRandomAlphanumStr (RandomStr,LENGTH_RANDOM_STR);
Cry_EncryptSHA256Base64 (RandomStr,UsrDat->EnUsrCod); Cry_EncryptSHA256Base64 (RandomStr,UsrDat->EnUsrCod);
if (!Usr_DB_ChkIfEncryptedUsrCodExists (UsrDat->EnUsrCod)) if (Usr_DB_GetUsrCodFromEncryptedUsrCod (UsrDat->EnUsrCod) <= 0)
break; break;
} }
if (NumTry == MAX_TRY) if (NumTry == MAX_TRY)
Err_ShowErrorAndExit ("Can not create a new encrypted user's code."); Err_ShowErrorAndExit ("Can not create a new encrypted user's code.");

View File

@ -82,13 +82,15 @@ unsigned Acc_DB_GetUsrsWithID (MYSQL_RES **mysql_res,
bool Acc_DB_CheckIfNicknameAlreadyExists (const char NewNickWithoutArr[Nck_MAX_BYTES_NICK_WITHOUT_ARROBA + 1]) bool Acc_DB_CheckIfNicknameAlreadyExists (const char NewNickWithoutArr[Nck_MAX_BYTES_NICK_WITHOUT_ARROBA + 1])
{ {
return (DB_QueryCOUNT ("can not check if nickname already existed", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if nickname already existed",
" FROM usr_nicknames" "SELECT EXISTS"
" WHERE Nickname='%s'" "(SELECT *"
" AND UsrCod<>%ld", " FROM usr_nicknames"
NewNickWithoutArr, " WHERE Nickname='%s'"
Gbl.Usrs.Me.UsrDat.UsrCod) != 0); // A nickname of another user is the same that this nickname " AND UsrCod<>%ld)",
NewNickWithoutArr,
Gbl.Usrs.Me.UsrDat.UsrCod); // A nickname of another user is the same that this nickname
} }
/*****************************************************************************/ /*****************************************************************************/
@ -97,12 +99,14 @@ bool Acc_DB_CheckIfNicknameAlreadyExists (const char NewNickWithoutArr[Nck_MAX_B
bool Acc_DB_CheckIfEmailAlreadyExists (const char NewEmail[Cns_MAX_BYTES_EMAIL_ADDRESS + 1]) bool Acc_DB_CheckIfEmailAlreadyExists (const char NewEmail[Cns_MAX_BYTES_EMAIL_ADDRESS + 1])
{ {
return (DB_QueryCOUNT ("can not check if email already existed", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if email already existed",
" FROM usr_emails" "SELECT EXISTS"
" WHERE E_mail='%s'" "(SELECT *"
" AND Confirmed='Y'", " FROM usr_emails"
NewEmail) != 0); // An email of another user is the same that my email " WHERE E_mail='%s'"
" AND Confirmed='Y')",
NewEmail); // An email of another user is the same that my email
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -100,16 +100,17 @@ unsigned Adm_DB_GetAdmsCurrentScopeExceptMe (MYSQL_RES **mysql_res)
bool Adm_DB_CheckIfUsrIsAdm (long UsrCod,HieLvl_Level_t Scope,long Cod) bool Adm_DB_CheckIfUsrIsAdm (long UsrCod,HieLvl_Level_t Scope,long Cod)
{ {
/***** Get if a user is administrator of a degree from database *****/ return
return (DB_QueryCOUNT ("can not check if a user is administrator", DB_QueryEXISTS ("can not check if a user is administrator",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM usr_admins" "(SELECT *"
" WHERE UsrCod=%ld" " FROM usr_admins"
" AND Scope='%s'" " WHERE UsrCod=%ld"
" AND Cod=%ld", " AND Scope='%s'"
UsrCod, " AND Cod=%ld)",
Sco_GetDBStrFromScope (Scope), UsrCod,
Cod) != 0); Sco_GetDBStrFromScope (Scope),
Cod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -349,7 +349,6 @@ void Agd_DB_RemoveUsrEvents (long UsrCod)
unsigned Agd_DB_GetNumEventsFromUsr (long UsrCod) unsigned Agd_DB_GetNumEventsFromUsr (long UsrCod)
{ {
/***** Get number of events in a course from database *****/
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of events from user", DB_QueryCOUNT ("can not get number of events from user",
"SELECT COUNT(*)" "SELECT COUNT(*)"

View File

@ -216,15 +216,17 @@ void Asg_DB_GetAssignmentTxtByCod (long AsgCod,char Txt[Cns_MAX_BYTES_TEXT + 1])
bool Asg_DB_CheckIfSimilarAssignmentExists (const char *Field,const char *Value, bool Asg_DB_CheckIfSimilarAssignmentExists (const char *Field,const char *Value,
long AsgCod) long AsgCod)
{ {
/***** Get number of assignments with a field value from database *****/ return
return (DB_QueryCOUNT ("can not get similar assignments", DB_QueryEXISTS ("can not check if similar assignments exist",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM asg_assignments" "(SELECT *"
" WHERE CrsCod=%ld" " FROM asg_assignments"
" AND %s='%s'" " WHERE CrsCod=%ld"
" AND AsgCod<>%ld", " AND %s='%s'"
Gbl.Hierarchy.Crs.CrsCod, " AND AsgCod<>%ld)",
Field,Value,AsgCod) != 0); Gbl.Hierarchy.Crs.CrsCod,
Field,Value,
AsgCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -309,33 +311,34 @@ void Asg_DB_RemoveAssignment (long AsgCod)
} }
/*****************************************************************************/ /*****************************************************************************/
/******************* Get groups associated to an assignment ******************/ /********************* Check if I can do an assignment ***********************/
/*****************************************************************************/ /*****************************************************************************/
bool Asg_DB_CheckIfICanDoAssignment (long AsgCod) bool Asg_DB_CheckIfICanDoAssignment (long AsgCod)
{ {
// Students and teachers can do assignments depending on groups // Students and teachers can do assignments depending on groups
/***** Get if I can do an assignment from database *****/ return
return (DB_QueryCOUNT ("can not check if I can do an assignment", DB_QueryEXISTS ("can not check if I can do an assignment",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM asg_assignments" "(SELECT *"
" WHERE AsgCod=%ld" " FROM asg_assignments"
" AND (" " WHERE AsgCod=%ld"
// Assignment is for the whole course " AND ("
"AsgCod NOT IN" // Assignment is for the whole course
" (SELECT AsgCod" "AsgCod NOT IN"
" FROM asg_groups)" " (SELECT AsgCod"
" OR " " FROM asg_groups)"
// Assignment is for some of my groups " OR "
"AsgCod IN" // Assignment is for some of my groups
" (SELECT asg_groups.AsgCod" "AsgCod IN"
" FROM grp_users," " (SELECT asg_groups.AsgCod"
"asg_groups" " FROM grp_users,"
" WHERE grp_users.UsrCod=%ld" "asg_groups"
" AND asg_groups.GrpCod=grp_users.GrpCod)" " WHERE grp_users.UsrCod=%ld"
")", " AND asg_groups.GrpCod=grp_users.GrpCod)"
AsgCod, "))",
Gbl.Usrs.Me.UsrDat.UsrCod) != 0); AsgCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -568,7 +571,7 @@ unsigned Asg_DB_GetNumCoursesWithAssignments (HieLvl_Level_t Scope)
Gbl.Hierarchy.Crs.CrsCod); Gbl.Hierarchy.Crs.CrsCod);
default: default:
Err_WrongScopeExit (); Err_WrongScopeExit ();
return 0; return 0; // Not reached
} }
} }

View File

@ -188,17 +188,17 @@ void Att_DB_GetAttEventDescription (long AttCod,char Description[Cns_MAX_BYTES_T
bool Att_DB_CheckIfSimilarAttEventExists (const char *Field,const char *Value,long AttCod) bool Att_DB_CheckIfSimilarAttEventExists (const char *Field,const char *Value,long AttCod)
{ {
/***** Get number of attendance events return
with a field value from database *****/ DB_QueryEXISTS ("can not check similar attendance events",
return (DB_QueryCOUNT ("can not get similar attendance events", "SELECT EXISTS"
"SELECT COUNT(*)" "(SELECT *"
" FROM att_events" " FROM att_events"
" WHERE CrsCod=%ld" " WHERE CrsCod=%ld"
" AND %s='%s'" " AND %s='%s'"
" AND AttCod<>%ld", " AND AttCod<>%ld)",
Gbl.Hierarchy.Crs.CrsCod, Gbl.Hierarchy.Crs.CrsCod,
Field,Value, Field,Value,
AttCod) != 0); AttCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -138,14 +138,15 @@ unsigned Ban_DB_GetDataOfBannerByCod (MYSQL_RES **mysql_res,long BanCod)
bool Ban_DB_CheckIfBannerNameExists (const char *FieldName,const char *Name,long BanCod) bool Ban_DB_CheckIfBannerNameExists (const char *FieldName,const char *Name,long BanCod)
{ {
/***** Get number of banners with a name from database *****/ return
return (DB_QueryCOUNT ("can not check if the name of a banner already existed", DB_QueryEXISTS ("can not check if the name of a banner already existed",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM ban_banners" "(SELECT *"
" WHERE %s='%s'" " FROM ban_banners"
" AND BanCod<>%ld", " WHERE %s='%s'"
FieldName,Name, " AND BanCod<>%ld)",
BanCod) != 0); FieldName,Name,
BanCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -1426,19 +1426,20 @@ bool Brw_DB_GetIfFolderHasPublicFiles (const char Path[PATH_MAX + 1])
long Cod = Brw_GetCodForFileBrowser (); long Cod = Brw_GetCodForFileBrowser ();
long ZoneUsrCod = Brw_GetZoneUsrCodForFileBrowser (); long ZoneUsrCod = Brw_GetZoneUsrCodForFileBrowser ();
/***** Get if a file or folder is public from database *****/ return
return (DB_QueryCOUNT ("can not check if a folder contains public files", DB_QueryEXISTS ("can not check if a folder contains public files",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM brw_files" "(SELECT *"
" WHERE FileBrowser=%u" " FROM brw_files"
" AND Cod=%ld" " WHERE FileBrowser=%u"
" AND ZoneUsrCod=%ld" " AND Cod=%ld"
" AND Path LIKE '%s/%%'" " AND ZoneUsrCod=%ld"
" AND Public='Y'", " AND Path LIKE '%s/%%'"
(unsigned) Brw_DB_FileBrowserForDB_files[Gbl.FileBrowser.Type], " AND Public='Y')",
Cod, (unsigned) Brw_DB_FileBrowserForDB_files[Gbl.FileBrowser.Type],
ZoneUsrCod, Cod,
Path) != 0); ZoneUsrCod,
Path);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2325,21 +2326,23 @@ bool Brw_DB_CheckIfFileOrFolderIsSetAsHiddenUsingMetadata (const struct FileMeta
or or
2) the argument Path begins by 'x/', where x is a path stored in database 2) the argument Path begins by 'x/', where x is a path stored in database
*/ */
return (DB_QueryCOUNT ("can not check if a file or folder is hidden", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if a file or folder is hidden",
" FROM brw_files" "SELECT EXISTS"
" WHERE FileBrowser=%u" "(SELECT *"
" AND Cod=%ld" " FROM brw_files"
" AND ZoneUsrCod=%ld" " WHERE FileBrowser=%u"
" AND Hidden='Y'" " AND Cod=%ld"
" AND (Path='%s'" " AND ZoneUsrCod=%ld"
" OR" " AND Hidden='Y'"
" LOCATE(CONCAT(Path,'/'),'%s')=1)", " AND (Path='%s'"
FileMetadata->FileBrowser, " OR"
FileMetadata->Cod, " LOCATE(CONCAT(Path,'/'),'%s')=1))",
FileMetadata->ZoneUsrCod, FileMetadata->FileBrowser,
FileMetadata->FilFolLnk.Full, FileMetadata->Cod,
FileMetadata->FilFolLnk.Full) != 0); FileMetadata->ZoneUsrCod,
FileMetadata->FilFolLnk.Full,
FileMetadata->FilFolLnk.Full);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2422,42 +2425,48 @@ bool Brw_DB_GetIfExpandedFolder (const char Path[PATH_MAX + 1])
if (Cod > 0) if (Cod > 0)
{ {
if (WorksUsrCod > 0) if (WorksUsrCod > 0)
return (DB_QueryCOUNT ("can not get check if a folder is expanded", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check check if a folder is expanded",
" FROM brw_expanded" "SELECT EXISTS"
" WHERE UsrCod=%ld" "(SELECT *"
" AND FileBrowser=%u" " FROM brw_expanded"
" AND Cod=%ld" " WHERE UsrCod=%ld"
" AND WorksUsrCod=%ld" " AND FileBrowser=%u"
" AND Path='%s/'", " AND Cod=%ld"
Gbl.Usrs.Me.UsrDat.UsrCod, " AND WorksUsrCod=%ld"
(unsigned) FileBrowserForExpandedFolders, " AND Path='%s/')",
Cod, Gbl.Usrs.Me.UsrDat.UsrCod,
WorksUsrCod, (unsigned) FileBrowserForExpandedFolders,
Path) != 0); Cod,
WorksUsrCod,
Path);
else else
return (DB_QueryCOUNT ("can not get check if a folder is expanded", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not get check if a folder is expanded",
" FROM brw_expanded" "SELECT EXISTS"
" WHERE UsrCod=%ld" "(SELECT *"
" AND FileBrowser=%u" " FROM brw_expanded"
" AND Cod=%ld" " WHERE UsrCod=%ld"
" AND Path='%s/'", " AND FileBrowser=%u"
Gbl.Usrs.Me.UsrDat.UsrCod, " AND Cod=%ld"
(unsigned) FileBrowserForExpandedFolders, " AND Path='%s/')",
Cod, Gbl.Usrs.Me.UsrDat.UsrCod,
Path) != 0); (unsigned) FileBrowserForExpandedFolders,
Cod,
Path);
} }
else // Briefcase else // Briefcase
return (DB_QueryCOUNT ("can not get check if a folder is expanded", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not get check if a folder is expanded",
" FROM brw_expanded" "SELECT EXISTS"
" WHERE UsrCod=%ld" "(SELECT *"
" AND FileBrowser=%u" " FROM brw_expanded"
" AND Path='%s/'", " WHERE UsrCod=%ld"
Gbl.Usrs.Me.UsrDat.UsrCod, " AND FileBrowser=%u"
(unsigned) FileBrowserForExpandedFolders, " AND Path='%s/')",
Path) != 0); Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) FileBrowserForExpandedFolders,
Path);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -134,16 +134,17 @@ unsigned Bld_DB_GetDataOfBuildingByCod (MYSQL_RES **mysql_res,long BldCod)
bool Bld_DB_CheckIfBuildingNameExists (const char *FieldName,const char *Name,long BldCod) bool Bld_DB_CheckIfBuildingNameExists (const char *FieldName,const char *Name,long BldCod)
{ {
/***** Get number of buildings with a name from database *****/ return
return (DB_QueryCOUNT ("can not check if the name of a building" DB_QueryEXISTS ("can not check if the name of a building already existed",
" already existed", "SELECT EXISTS"
"SELECT COUNT(*)" "(SELECT *"
" FROM bld_buildings" " FROM bld_buildings"
" WHERE CtrCod=%ld" " WHERE CtrCod=%ld"
" AND %s='%s'" " AND %s='%s'"
" AND BldCod<>%ld", " AND BldCod<>%ld)",
Gbl.Hierarchy.Ctr.CtrCod, Gbl.Hierarchy.Ctr.CtrCod,
FieldName,Name,BldCod) != 0); FieldName,Name,
BldCod);
} }

View File

@ -306,18 +306,18 @@ unsigned Ctr_DB_GetPhotoAttribution (MYSQL_RES **mysql_res,long CtrCod)
bool Ctr_DB_CheckIfCtrNameExistsInIns (const char *FieldName,const char *Name, bool Ctr_DB_CheckIfCtrNameExistsInIns (const char *FieldName,const char *Name,
long CtrCod,long InsCod) long CtrCod,long InsCod)
{ {
/***** Get number of centers with a name from database *****/ return
return (DB_QueryCOUNT ("can not check if the name of a center" DB_QueryEXISTS ("can not check if the name of a center already existed",
" already existed", "SELECT EXISTS"
"SELECT COUNT(*)" "(SELECT *"
" FROM ctr_centers" " FROM ctr_centers"
" WHERE InsCod=%ld" " WHERE InsCod=%ld"
" AND %s='%s'" " AND %s='%s'"
" AND CtrCod<>%ld", " AND CtrCod<>%ld)",
InsCod, InsCod,
FieldName, FieldName,
Name, Name,
CtrCod) != 0); CtrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -622,33 +622,20 @@ void Ctr_DB_UpdateCtrStatus (long CtrCod,Ctr_Status_t NewStatus)
/********** Check if any of the centers in an institution has map ************/ /********** Check if any of the centers in an institution has map ************/
/*****************************************************************************/ /*****************************************************************************/
bool Ctr_DB_GetIfMapIsAvailableInIns (long InsCod) bool Ctr_DB_CheckIfMapIsAvailableInIns (long InsCod)
{ {
MYSQL_RES *mysql_res;
MYSQL_ROW row;
bool MapIsAvailable = false;
/***** Get if any center in current institution has a coordinate set /***** Get if any center in current institution has a coordinate set
(coordinates 0, 0 means not set ==> don't show map) *****/ (coordinates 0, 0 means not set ==> don't show map) *****/
if (DB_QuerySELECT (&mysql_res,"can not get if map is available", return
"SELECT EXISTS" // row[0] DB_QueryEXISTS ("can not check if map is available",
"(SELECT *" "SELECT EXISTS"
" FROM ctr_centers" "(SELECT *"
" WHERE InsCod=%ld" " FROM ctr_centers"
" AND (Latitude<>0" " WHERE InsCod=%ld"
" OR" " AND (Latitude<>0"
" Longitude<>0))", " OR"
InsCod)) " Longitude<>0))",
{ InsCod);
/* Get if map is available */
row = mysql_fetch_row (mysql_res);
MapIsAvailable = (row[0][0] == '1');
}
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
return MapIsAvailable;
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -81,7 +81,7 @@ void Ctr_DB_UpdateCtrCoordinate (long CtrCod,
void Ctr_DB_UpdateCtrStatus (long CtrCod,Ctr_Status_t NewStatus); void Ctr_DB_UpdateCtrStatus (long CtrCod,Ctr_Status_t NewStatus);
bool Ctr_DB_GetIfMapIsAvailableInIns (long InsCod); bool Ctr_DB_CheckIfMapIsAvailableInIns (long InsCod);
void Ctr_DB_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom); void Ctr_DB_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom);
void Ctr_DB_GetCoordAndZoomInCurrentIns (struct Map_Coordinates *Coord,unsigned *Zoom); void Ctr_DB_GetCoordAndZoomInCurrentIns (struct Map_Coordinates *Coord,unsigned *Zoom);
unsigned Ctr_DB_GetCtrsWithCoords (MYSQL_RES **mysql_res); unsigned Ctr_DB_GetCtrsWithCoords (MYSQL_RES **mysql_res);

View File

@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par
TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo. TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo.
*/ */
#define Log_PLATFORM_VERSION "SWAD 21.51 (2021-11-04)" #define Log_PLATFORM_VERSION "SWAD 21.52 (2021-11-05)"
#define CSS_FILE "swad20.45.css" #define CSS_FILE "swad20.45.css"
#define JS_FILE "swad20.69.1.js" #define JS_FILE "swad20.69.1.js"
/* /*
TODO: Rename CENTRE to CENTER in help wiki. TODO: Rename CENTRE to CENTER in help wiki.
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
Version 21.52: Nov 05, 2021 Changed SELECT COUNT to SELECT EXISTS in some queries. (321833 lines)
Version 21.51: Nov 04, 2021 Eliminated the limit of origin courses in messages. (321735 lines) Version 21.51: Nov 04, 2021 Eliminated the limit of origin courses in messages. (321735 lines)
Version 21.50.1: Nov 03, 2021 Queries moved to module swad_user_database and other modules. (321759 lines) Version 21.50.1: Nov 03, 2021 Queries moved to module swad_user_database and other modules. (321759 lines)
Version 21.50: Nov 03, 2021 Queries moved to module swad_user_database and other modules. (321696 lines) Version 21.50: Nov 03, 2021 Queries moved to module swad_user_database and other modules. (321696 lines)

View File

@ -47,12 +47,11 @@ extern struct Globals Gbl;
/*****************************************************************************/ /*****************************************************************************/
/*****************************************************************************/ /*****************************************************************************/
/********************* Get connected users with a role ***********************/ /**************** Get number of connected users with a role ******************/
/*****************************************************************************/ /*****************************************************************************/
unsigned Con_DB_GetConnectedUsrsTotal (Rol_Role_t Role) unsigned Con_DB_GetConnectedUsrsTotal (Rol_Role_t Role)
{ {
/***** Get number of connected users with a role from database *****/
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get number of connected users", DB_QueryCOUNT ("can not get number of connected users",
"SELECT COUNT(*)" "SELECT COUNT(*)"

View File

@ -1879,7 +1879,7 @@ static void Cty_FormToGoToMap (struct Cty_Countr *Cty)
{ {
extern const char *Txt_Map; extern const char *Txt_Map;
if (Cty_DB_GetIfMapIsAvailable (Cty->CtyCod)) if (Cty_DB_CheckIfMapIsAvailable (Cty->CtyCod))
{ {
Cty_EditingCty = Cty; // Used to pass parameter with the code of the country Cty_EditingCty = Cty; // Used to pass parameter with the code of the country
Lay_PutContextualLinkOnlyIcon (ActSeeCtyInf,NULL, Lay_PutContextualLinkOnlyIcon (ActSeeCtyInf,NULL,

View File

@ -374,13 +374,13 @@ unsigned Cty_DB_GetNumCtysWithUsrs (Rol_Role_t Role,
bool Cty_DB_CheckIfNumericCountryCodeExists (long CtyCod) bool Cty_DB_CheckIfNumericCountryCodeExists (long CtyCod)
{ {
/***** Get number of countries with a name from database *****/ return
return (DB_QueryCOUNT ("can not check if the numeric code" DB_QueryEXISTS ("can not check if the numeric code of a country already existed",
" of a country already existed", "SELECT EXISTS"
"SELECT COUNT(*)" "(SELECT *"
" FROM cty_countrs" " FROM cty_countrs"
" WHERE CtyCod='%03ld'", " WHERE CtyCod='%03ld')",
CtyCod) != 0); CtyCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -389,13 +389,13 @@ bool Cty_DB_CheckIfNumericCountryCodeExists (long CtyCod)
bool Cty_DB_CheckIfAlpha2CountryCodeExists (const char Alpha2[2 + 1]) bool Cty_DB_CheckIfAlpha2CountryCodeExists (const char Alpha2[2 + 1])
{ {
/***** Get number of countries with a name from database *****/ return
return (DB_QueryCOUNT ("can not check if the alphabetic code" DB_QueryEXISTS ("can not check if the alphabetic code of a country already existed",
" of a country already existed", "SELECT EXISTS"
"SELECT COUNT(*)" "(SELECT *"
" FROM cty_countrs" " FROM cty_countrs"
" WHERE Alpha2='%s'", " WHERE Alpha2='%s')",
Alpha2) != 0); Alpha2);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -406,15 +406,15 @@ bool Cty_DB_CheckIfCountryNameExists (Lan_Language_t Language,const char *Name,l
{ {
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES]; extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
/***** Get number of countries with a name from database *****/ return
return (DB_QueryCOUNT ("can not check if the name" DB_QueryEXISTS ("can not check if the name of a country already existed",
" of a country already existed", "SELECT EXISTS"
"SELECT COUNT(*)" "(SELECT *"
" FROM cty_countrs" " FROM cty_countrs"
" WHERE Name_%s='%s'" " WHERE Name_%s='%s'"
" AND CtyCod<>'%03ld'", " AND CtyCod<>'%03ld')",
Lan_STR_LANG_ID[Language],Name, Lan_STR_LANG_ID[Language],Name,
CtyCod) != 0); CtyCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -504,34 +504,21 @@ unsigned Cty_DB_GetMapAttr (MYSQL_RES **mysql_res,long CtyCod)
/************ Check if any of the centers in a country has map ***************/ /************ Check if any of the centers in a country has map ***************/
/*****************************************************************************/ /*****************************************************************************/
bool Cty_DB_GetIfMapIsAvailable (long CtyCod) bool Cty_DB_CheckIfMapIsAvailable (long CtyCod)
{ {
MYSQL_RES *mysql_res; /***** Check if any center in current country has a coordinate set
MYSQL_ROW row;
bool MapIsAvailable = false;
/***** Get if any center in current country has a coordinate set
(coordinates 0, 0 means not set ==> don't show map) *****/ (coordinates 0, 0 means not set ==> don't show map) *****/
if (DB_QuerySELECT (&mysql_res,"can not get if map is available", return
"SELECT EXISTS" DB_QueryEXISTS ("can not check if map is available",
"(SELECT *" "SELECT EXISTS"
" FROM ins_instits," "(SELECT *"
"ctr_centers" " FROM ins_instits,"
" WHERE ins_instits.CtyCod=%ld" "ctr_centers"
" AND ins_instits.InsCod=ctr_centers.InsCod" " WHERE ins_instits.CtyCod=%ld"
" AND (ctr_centers.Latitude<>0" " AND ins_instits.InsCod=ctr_centers.InsCod"
" OR ctr_centers.Longitude<>0))", " AND (ctr_centers.Latitude<>0"
CtyCod)) " OR ctr_centers.Longitude<>0))",
{ CtyCod);
/* Get if map is available */
row = mysql_fetch_row (mysql_res);
MapIsAvailable = (row[0][0] == '1');
}
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
return MapIsAvailable;
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -69,7 +69,7 @@ unsigned Cty_DB_SearchCtys (MYSQL_RES **mysql_res,
void Cty_DB_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom); void Cty_DB_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom);
unsigned Cty_DB_GetCtrsWithCoordsInCurrentCty (MYSQL_RES **mysql_res); unsigned Cty_DB_GetCtrsWithCoordsInCurrentCty (MYSQL_RES **mysql_res);
unsigned Cty_DB_GetMapAttr (MYSQL_RES **mysql_res,long CtyCod); unsigned Cty_DB_GetMapAttr (MYSQL_RES **mysql_res,long CtyCod);
bool Cty_DB_GetIfMapIsAvailable (long CtyCod); bool Cty_DB_CheckIfMapIsAvailable (long CtyCod);
void Cty_DB_UpdateCtyField (long CtyCod,const char *FieldName,const char *FieldValue); void Cty_DB_UpdateCtyField (long CtyCod,const char *FieldName,const char *FieldValue);
void Cty_DB_UpdateCtyMapAttr (const char NewMapAttribution[Med_MAX_BYTES_ATTRIBUTION + 1]); void Cty_DB_UpdateCtyMapAttr (const char NewMapAttribution[Med_MAX_BYTES_ATTRIBUTION + 1]);

View File

@ -202,20 +202,20 @@ void Crs_DB_GetShortNamesByCod (long CrsCod,
bool Crs_DB_CheckIfCrsNameExistsInYearOfDeg (const char *FieldName,const char *Name,long CrsCod, bool Crs_DB_CheckIfCrsNameExistsInYearOfDeg (const char *FieldName,const char *Name,long CrsCod,
long DegCod,unsigned Year) long DegCod,unsigned Year)
{ {
/***** Get number of courses in a year of a degree and with a name from database *****/ return
return (DB_QueryCOUNT ("can not check if the name" DB_QueryEXISTS ("can not check if the name of a course already existed",
" of a course already existed", "SELECT EXISTS"
"SELECT COUNT(*)" "(SELECT *"
" FROM crs_courses" " FROM crs_courses"
" WHERE DegCod=%ld" " WHERE DegCod=%ld"
" AND Year=%u" " AND Year=%u"
" AND %s='%s'" " AND %s='%s'"
" AND CrsCod<>%ld", " AND CrsCod<>%ld)",
DegCod, DegCod,
Year, Year,
FieldName, FieldName,
Name, Name,
CrsCod) != 0); CrsCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -4077,6 +4077,34 @@ unsigned long DB_QueryCOUNT (const char *MsgError,const char *fmt,...)
return NumRows; return NumRows;
} }
bool DB_QueryEXISTS (const char *MsgError,const char *fmt,...)
{
va_list ap;
int NumBytesPrinted;
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
bool Exists = false;
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Query,fmt,ap);
va_end (ap);
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
/***** Make query "SELECT EXISTS (...)" *****/
if (DB_QuerySELECTusingQueryStr (Query,&mysql_res,MsgError))
{
row = mysql_fetch_row (mysql_res);
Exists = (row[0][0] == '1');
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
return Exists;
}
/*****************************************************************************/ /*****************************************************************************/
/******************** Make an INSERT query in database ***********************/ /******************** Make an INSERT query in database ***********************/
/*****************************************************************************/ /*****************************************************************************/

View File

@ -57,6 +57,7 @@ void DB_QuerySELECTString (char *Str,size_t StrSize,const char *MsgError,
long DB_GetNextCode (MYSQL_RES *mysql_res); long DB_GetNextCode (MYSQL_RES *mysql_res);
unsigned long DB_GetNumRowsTable (const char *Table); unsigned long DB_GetNumRowsTable (const char *Table);
unsigned long DB_QueryCOUNT (const char *MsgError,const char *fmt,...); unsigned long DB_QueryCOUNT (const char *MsgError,const char *fmt,...);
bool DB_QueryEXISTS (const char *MsgError,const char *fmt,...);
void DB_QueryINSERT (const char *MsgError,const char *fmt,...); void DB_QueryINSERT (const char *MsgError,const char *fmt,...);

View File

@ -305,14 +305,15 @@ void Deg_DB_GetShortNameOfDegreeByCod (long DegCod,char ShrtName[Cns_HIERARCHY_M
bool Deg_DB_CheckIfDegreeTypeNameExists (const char *DegTypName,long DegTypCod) bool Deg_DB_CheckIfDegreeTypeNameExists (const char *DegTypName,long DegTypCod)
{ {
/***** Get number of degree types with a name from database *****/ return
return (DB_QueryCOUNT ("can not check if the name of a type of degree" DB_QueryEXISTS ("can not check if the name of a type of degree already existed",
" already existed", "SELECT EXISTS"
"SELECT COUNT(*)" "(SELECT *"
" FROM deg_types" " FROM deg_types"
" WHERE DegTypName='%s'" " WHERE DegTypName='%s'"
" AND DegTypCod<>%ld", " AND DegTypCod<>%ld)",
DegTypName,DegTypCod) != 0); DegTypName,
DegTypCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -460,17 +461,17 @@ unsigned Deg_DB_GetDegsWithStds (MYSQL_RES **mysql_res)
bool Deg_DB_CheckIfDegNameExistsInCtr (const char *FieldName,const char *Name, bool Deg_DB_CheckIfDegNameExistsInCtr (const char *FieldName,const char *Name,
long DegCod,long CtrCod) long DegCod,long CtrCod)
{ {
/***** Get number of degrees with a type and a name from database *****/ return
return (DB_QueryCOUNT ("can not check if the name of a degree" DB_QueryEXISTS ("can not check if the name of a degree already existed",
" already existed", "SELECT EXISTS"
"SELECT COUNT(*)" "(SELECT *"
" FROM deg_degrees" " FROM deg_degrees"
" WHERE CtrCod=%ld" " WHERE CtrCod=%ld"
" AND %s='%s'" " AND %s='%s'"
" AND DegCod<>%ld", " AND DegCod<>%ld)",
CtrCod, CtrCod,
FieldName,Name, FieldName,Name,
DegCod) != 0); DegCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -549,7 +550,8 @@ unsigned Deg_DB_GetNumDegsWithUsrs (Rol_Role_t Role,
" AND deg_degrees.DegCod=crs_courses.DegCod" " AND deg_degrees.DegCod=crs_courses.DegCod"
" AND crs_courses.CrsCod=crs_users.CrsCod" " AND crs_courses.CrsCod=crs_users.CrsCod"
" AND crs_users.Role=%u", " AND crs_users.Role=%u",
SubQuery,(unsigned) Role); SubQuery,
(unsigned) Role);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -761,16 +763,18 @@ unsigned Deg_DB_GetUsrMainDeg (MYSQL_RES **mysql_res,long UsrCod)
bool Deg_DB_CheckIfUsrBelongsToDeg (long UsrCod,long DegCod) bool Deg_DB_CheckIfUsrBelongsToDeg (long UsrCod,long DegCod)
{ {
return (DB_QueryCOUNT ("can not check if a user belongs to a degree", return
"SELECT COUNT(DISTINCT crs_courses.DegCod)" DB_QueryEXISTS ("can not check if a user belongs to a degree",
" FROM crs_users," "SELECT EXISTS"
"crs_courses" "(SELECT *"
" WHERE crs_users.UsrCod=%ld" " FROM crs_users,"
" AND crs_users.Accepted='Y'" // Only if user accepted "crs_courses"
" AND crs_users.CrsCod=crs_courses.CrsCod" " WHERE crs_users.UsrCod=%ld"
" AND crs_courses.DegCod=%ld", " AND crs_users.Accepted='Y'" // Only if user accepted
UsrCod, " AND crs_users.CrsCod=crs_courses.CrsCod"
DegCod) != 0); " AND crs_courses.DegCod=%ld)",
UsrCod,
DegCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -164,14 +164,15 @@ unsigned Dpt_DB_GetDataOfDepartmentByCod (MYSQL_RES **mysql_res,long DptCod)
bool Dpt_DB_CheckIfDepartmentNameExists (const char *FieldName,const char *Name,long DptCod) bool Dpt_DB_CheckIfDepartmentNameExists (const char *FieldName,const char *Name,long DptCod)
{ {
/***** Get number of departments with a name from database *****/ return
return (DB_QueryCOUNT ("can not check if the department name already existed", DB_QueryEXISTS ("can not check if the department name already existed",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM dpt_departments" "(SELECT *"
" WHERE %s='%s'" " FROM dpt_departments"
" AND DptCod<>%ld", " WHERE %s='%s'"
FieldName,Name, " AND DptCod<>%ld)",
DptCod) != 0); FieldName,Name,
DptCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -117,12 +117,13 @@ unsigned Dup_DB_GetUsrsSimilarTo (MYSQL_RES **mysql_res,const struct UsrData *Us
bool Dup_DB_CheckIfUsrIsDup (long UsrCod) bool Dup_DB_CheckIfUsrIsDup (long UsrCod)
{ {
return (DB_QueryCOUNT ("can not if user is in list" return
" of possible duplicate users", DB_QueryEXISTS ("can not check if user is in list of possible duplicate users",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM usr_duplicated" "(SELECT *"
" WHERE UsrCod=%ld", " FROM usr_duplicated"
UsrCod) != 0); " WHERE UsrCod=%ld)",
UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -152,15 +152,17 @@ bool Enr_DB_CheckIfUsrBelongsToCrs (long UsrCod,long CrsCod,
const char *SubQuery = (CountOnlyAcceptedCourses ? " AND crs_users.Accepted='Y'" : // Only if user accepted const char *SubQuery = (CountOnlyAcceptedCourses ? " AND crs_users.Accepted='Y'" : // Only if user accepted
""); "");
return (DB_QueryCOUNT ("can not check if a user belongs to a course", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if a user belongs to a course",
" FROM crs_users" "SELECT EXISTS"
" WHERE CrsCod=%ld" "(SELECT *"
" AND UsrCod=%ld" " FROM crs_users"
"%s", " WHERE CrsCod=%ld"
CrsCod, " AND UsrCod=%ld"
UsrCod, "%s)",
SubQuery) != 0); CrsCod,
UsrCod,
SubQuery);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -173,14 +175,16 @@ bool Enr_DB_CheckIfUsrSharesAnyOfMyCrs (long UsrCod)
Enr_GetMyCourses (); Enr_GetMyCourses ();
/* Check if user shares any course with me */ /* Check if user shares any course with me */
return (DB_QueryCOUNT ("can not check if a user shares any course with you", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if a user shares any course with you",
" FROM crs_users" "SELECT EXISTS"
" WHERE UsrCod=%ld" "(SELECT *"
" AND CrsCod IN" " FROM crs_users"
" (SELECT CrsCod" " WHERE UsrCod=%ld"
" FROM my_courses_tmp)", " AND CrsCod IN"
UsrCod) != 0); " (SELECT CrsCod"
" FROM my_courses_tmp))",
UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -217,12 +221,13 @@ bool Enr_DB_CheckIfUsrSharesAnyOfMyCrsWithDifferentRole (long UsrCod)
/* Get if a user shares any course with me from database */ /* Get if a user shares any course with me from database */
UsrSharesAnyOfMyCrsWithDifferentRole = UsrSharesAnyOfMyCrsWithDifferentRole =
(DB_QueryCOUNT ("can not check if a user shares any course with you", DB_QueryEXISTS ("can not check if a user shares any course with you",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM my_courses_tmp," "(SELECT *"
"usr_courses_tmp" " FROM my_courses_tmp,"
" WHERE my_courses_tmp.CrsCod=usr_courses_tmp.CrsCod" "usr_courses_tmp"
" AND my_courses_tmp.Role<>usr_courses_tmp.Role") != 0); " WHERE my_courses_tmp.CrsCod=usr_courses_tmp.CrsCod"
" AND my_courses_tmp.Role<>usr_courses_tmp.Role)");
/* Remove temporary table if exists */ /* Remove temporary table if exists */
DB_Query ("can not remove temporary tables", DB_Query ("can not remove temporary tables",

View File

@ -243,15 +243,17 @@ void Exa_DB_GetExamTxt (long ExaCod,char Txt[Cns_MAX_BYTES_TEXT + 1])
bool Exa_DB_CheckIfSimilarExamExists (long CrsCod,long ExaCod,const char *Title) bool Exa_DB_CheckIfSimilarExamExists (long CrsCod,long ExaCod,const char *Title)
{ {
return (DB_QueryCOUNT ("can not get similar exams", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check similar exams",
" FROM exa_exams" "SELECT EXISTS"
" WHERE CrsCod=%ld" "(SELECT *"
" AND Title='%s'" " FROM exa_exams"
" AND ExaCod<>%ld", " WHERE CrsCod=%ld"
CrsCod, " AND Title='%s'"
Title, " AND ExaCod<>%ld)",
ExaCod) != 0); CrsCod,
Title,
ExaCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -708,19 +710,20 @@ unsigned Exa_DB_GetDataOfSetByCod (MYSQL_RES **mysql_res,long SetCod)
bool Exa_DB_CheckIfSimilarSetExists (const struct ExaSet_Set *Set, bool Exa_DB_CheckIfSimilarSetExists (const struct ExaSet_Set *Set,
const char Title[ExaSet_MAX_BYTES_TITLE + 1]) const char Title[ExaSet_MAX_BYTES_TITLE + 1])
{ {
/***** Get number of set of questions with a field value from database *****/ return
return (DB_QueryCOUNT ("can not get similar sets of questions", DB_QueryEXISTS ("can not check similar sets of questions",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM exa_sets," "(SELECT *"
"exa_exams" " FROM exa_sets,"
" WHERE exa_sets.ExaCod=%ld" "exa_exams"
" AND exa_sets.Title='%s'" " WHERE exa_sets.ExaCod=%ld"
" AND exa_sets.SetCod<>%ld" " AND exa_sets.Title='%s'"
" AND exa_sets.ExaCod=exa_exams.ExaCod" " AND exa_sets.SetCod<>%ld"
" AND exa_exams.CrsCod=%ld", // Extra check " AND exa_sets.ExaCod=exa_exams.ExaCod"
Set->ExaCod,Title, " AND exa_exams.CrsCod=%ld)", // Extra check
Set->SetCod, Set->ExaCod,Title,
Gbl.Hierarchy.Crs.CrsCod) != 0); Set->SetCod,
Gbl.Hierarchy.Crs.CrsCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1668,21 +1671,23 @@ unsigned Exa_DB_GetGrpsAssociatedToSes (MYSQL_RES **mysql_res,long SesCod)
bool Exa_DB_CheckIfICanListThisSessionBasedOnGrps (long SesCod) bool Exa_DB_CheckIfICanListThisSessionBasedOnGrps (long SesCod)
{ {
return (DB_QueryCOUNT ("can not check if I can play an exam session", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if I can play an exam session",
" FROM exa_sessions" "SELECT EXISTS"
" WHERE SesCod=%ld" "(SELECT *"
" AND (SesCod NOT IN" " FROM exa_sessions"
" (SELECT SesCod FROM exa_groups)" " WHERE SesCod=%ld"
" AND (SesCod NOT IN"
" (SELECT SesCod FROM exa_groups)"
" OR" " OR"
" SesCod IN" " SesCod IN"
" (SELECT exa_groups.SesCod" " (SELECT exa_groups.SesCod"
" FROM exa_groups," " FROM exa_groups,"
"grp_users" "grp_users"
" WHERE grp_users.UsrCod=%ld" " WHERE grp_users.UsrCod=%ld"
" AND grp_users.GrpCod=exa_groups.GrpCod))", " AND grp_users.GrpCod=exa_groups.GrpCod)))",
SesCod, SesCod,
Gbl.Usrs.Me.UsrDat.UsrCod) != 0); Gbl.Usrs.Me.UsrDat.UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2106,18 +2111,18 @@ void Exa_DB_RemovePrintQstsFromCrs (long CrsCod)
bool Exa_DB_CheckIfSessionIsTheSameAsTheLast (long PrnCod) bool Exa_DB_CheckIfSessionIsTheSameAsTheLast (long PrnCod)
{ {
/***** Check if the current session id return
is the same as the last one stored in database *****/ DB_QueryEXISTS ("can not check session",
return (DB_QueryCOUNT ("can not check session", "SELECT EXISTS"
"SELECT COUNT(*)" "(SELECT *"
" FROM exa_log_sessions" " FROM exa_log_sessions"
" WHERE LogCod=" " WHERE LogCod="
"(SELECT MAX(LogCod)" "(SELECT MAX(LogCod)"
" FROM exa_log_sessions" " FROM exa_log_sessions"
" WHERE PrnCod=%ld)" " WHERE PrnCod=%ld)"
" AND SessionId='%s'", " AND SessionId='%s')",
PrnCod, PrnCod,
Gbl.Session.Id) != 0); Gbl.Session.Id);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2126,18 +2131,18 @@ bool Exa_DB_CheckIfSessionIsTheSameAsTheLast (long PrnCod)
bool Exa_DB_CheckIfUserAgentIsTheSameAsTheLast (long PrnCod,const char *UserAgentDB) bool Exa_DB_CheckIfUserAgentIsTheSameAsTheLast (long PrnCod,const char *UserAgentDB)
{ {
/***** Get if the current user agent return
is the same as the last stored in database *****/ DB_QueryEXISTS ("can not check user agent",
return (DB_QueryCOUNT ("can not check user agent", "SELECT EXISTS"
"SELECT COUNT(*)" "(SELECT *"
" FROM exa_log_user_agents" " FROM exa_log_user_agents"
" WHERE LogCod=" " WHERE LogCod="
"(SELECT MAX(LogCod)" "(SELECT MAX(LogCod)"
" FROM exa_log_user_agents" " FROM exa_log_user_agents"
" WHERE PrnCod=%ld)" " WHERE PrnCod=%ld)"
" AND UserAgent='%s'", " AND UserAgent='%s')",
PrnCod, PrnCod,
UserAgentDB) != 0); UserAgentDB);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -239,12 +239,15 @@ bool Fol_DB_CheckUsrIsFollowerOf (long FollowerCod,long FollowedCod)
return false; return false;
/***** Check if a user is a follower of another user *****/ /***** Check if a user is a follower of another user *****/
return (DB_QueryCOUNT ("can not get if a user is a follower of another one", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if a user is a follower of another one",
" FROM usr_follow" "SELECT EXISTS"
" WHERE FollowerCod=%ld" "(SELECT *"
" AND FollowedCod=%ld", " FROM usr_follow"
FollowerCod,FollowedCod) != 0); " WHERE FollowerCod=%ld"
" AND FollowedCod=%ld)",
FollowerCod,
FollowedCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -451,7 +451,7 @@ void For_DisablePost (void)
For_GetParamsForums (&Forums); For_GetParamsForums (&Forums);
/***** Check if post really exists, if it has not been removed *****/ /***** Check if post really exists, if it has not been removed *****/
if (For_DB_GetIfForumPstExists (Forums.PstCod)) if (For_DB_CheckIfForumPstExists (Forums.PstCod))
{ {
/***** Insert post into table of banned posts *****/ /***** Insert post into table of banned posts *****/
For_DB_InsertPstIntoDisabled (Forums.PstCod); For_DB_InsertPstIntoDisabled (Forums.PstCod);
@ -2890,7 +2890,7 @@ void For_RemovePost (void)
/***** Check if I can remove the post *****/ /***** Check if I can remove the post *****/
/* Check if the message really exists, if it has not been removed */ /* Check if the message really exists, if it has not been removed */
if (!For_DB_GetIfForumPstExists (Forums.PstCod)) if (!For_DB_CheckIfForumPstExists (Forums.PstCod))
Err_WrongPostExit (); Err_WrongPostExit ();
/* Check if I am the author of the message */ /* Check if I am the author of the message */

View File

@ -257,13 +257,15 @@ void For_DB_UpdateNumUsrsNotifiedByEMailAboutPost (long PstCod,
/******************** Get if a forum post exists in database *****************/ /******************** Get if a forum post exists in database *****************/
/*****************************************************************************/ /*****************************************************************************/
bool For_DB_GetIfForumPstExists (long PstCod) bool For_DB_CheckIfForumPstExists (long PstCod)
{ {
return (DB_QueryCOUNT ("can not check if a post of a forum already existed", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if a post of a forum already existed",
" FROM for_posts" "SELECT EXISTS"
" WHERE PstCod=%ld", "(SELECT *"
PstCod) != 0); // Post exists if it appears in table of forum posts " FROM for_posts"
" WHERE PstCod=%ld)",
PstCod); // Post exists if it appears in table of forum posts
} }
/*****************************************************************************/ /*****************************************************************************/
@ -542,15 +544,17 @@ bool For_DB_CheckIfThrBelongsToForum (long ThrCod,const struct For_Forum *Forum)
else else
SubQuery[0] = '\0'; SubQuery[0] = '\0';
return (DB_QueryCOUNT ("can not get if a thread belong to current forum", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if a thread belong to current forum",
" FROM for_threads" "SELECT EXISTS"
" WHERE ThrCod=%ld" "(SELECT *"
" AND ForumType=%u" " FROM for_threads"
"%s", " WHERE ThrCod=%ld"
ThrCod, " AND ForumType=%u"
(unsigned) Forum->Type, "%s)",
SubQuery) != 0); ThrCod,
(unsigned) Forum->Type,
SubQuery);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -627,7 +631,6 @@ unsigned For_DB_GetNumPstsInThr (long ThrCod)
unsigned For_DB_GetNumMyPstsInThr (long ThrCod) unsigned For_DB_GetNumMyPstsInThr (long ThrCod)
{ {
/***** Get if I have write posts in a thread from database *****/
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not check if you have written posts in a thead of a forum", DB_QueryCOUNT ("can not check if you have written posts in a thead of a forum",
"SELECT COUNT(*)" "SELECT COUNT(*)"
@ -696,7 +699,6 @@ void For_DB_UpdateThrReadTime (long ThrCod,
unsigned For_DB_GetNumReadersOfThr (long ThrCod) unsigned For_DB_GetNumReadersOfThr (long ThrCod)
{ {
/***** Get number of distinct readers of a thread from database *****/
return (unsigned) return (unsigned)
DB_QueryCOUNT ("can not get the number of readers of a thread of a forum", DB_QueryCOUNT ("can not get the number of readers of a thread of a forum",
"SELECT COUNT(*)" "SELECT COUNT(*)"
@ -954,11 +956,13 @@ bool For_DB_GetIfPstIsEnabled (long PstCod)
return false; return false;
/***** Get if post is disabled from database *****/ /***** Get if post is disabled from database *****/
return (DB_QueryCOUNT ("can not check if a post of a forum is disabled", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if a post of a forum is disabled",
" FROM for_disabled" "SELECT EXISTS"
" WHERE PstCod=%ld", "(SELECT *"
PstCod) == 0); // Post is enabled if it does not appear in table of disabled posts " FROM for_disabled"
" WHERE PstCod=%ld)",
PstCod); // Post is enabled if it does not appear in table of disabled posts
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -51,7 +51,7 @@ long For_DB_InsertForumPst (long ThrCod,long UsrCod,
long MedCod); long MedCod);
void For_DB_UpdateNumUsrsNotifiedByEMailAboutPost (long PstCod, void For_DB_UpdateNumUsrsNotifiedByEMailAboutPost (long PstCod,
unsigned NumUsrsToBeNotifiedByEMail); unsigned NumUsrsToBeNotifiedByEMail);
bool For_DB_GetIfForumPstExists (long PstCod); bool For_DB_CheckIfForumPstExists (long PstCod);
unsigned For_DB_GetPstData (MYSQL_RES **mysql_res,long PstCod); unsigned For_DB_GetPstData (MYSQL_RES **mysql_res,long PstCod);
unsigned For_DB_GetPstSubjectAndContent (MYSQL_RES **mysql_res,long PstCod); unsigned For_DB_GetPstSubjectAndContent (MYSQL_RES **mysql_res,long PstCod);
unsigned For_DB_GetForumTypeAndLocationOfAPost (MYSQL_RES **mysql_res,long PstCod); unsigned For_DB_GetForumTypeAndLocationOfAPost (MYSQL_RES **mysql_res,long PstCod);

View File

@ -231,15 +231,17 @@ void Gam_DB_GetGameTxt (long GamCod,char Txt[Cns_MAX_BYTES_TEXT + 1])
bool Gam_DB_CheckIfSimilarGameExists (const struct Gam_Game *Game) bool Gam_DB_CheckIfSimilarGameExists (const struct Gam_Game *Game)
{ {
return (DB_QueryCOUNT ("can not get similar games", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check similar games",
" FROM gam_games" "SELECT EXISTS"
" WHERE CrsCod=%ld" "(SELECT *"
" AND Title='%s'" " FROM gam_games"
" AND GamCod<>%ld", " WHERE CrsCod=%ld"
Gbl.Hierarchy.Crs.CrsCod, " AND Title='%s'"
Game->Title, " AND GamCod<>%ld)",
Game->GamCod) != 0); Gbl.Hierarchy.Crs.CrsCod,
Game->Title,
Game->GamCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -196,11 +196,13 @@ unsigned Grp_DB_GetDataOfGroupByCod (MYSQL_RES **mysql_res,long GrpCod)
bool Grp_DB_CheckIfGrpExists (long GrpCod) bool Grp_DB_CheckIfGrpExists (long GrpCod)
{ {
return (DB_QueryCOUNT ("can not check if a group exists", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if a group exists",
" FROM grp_groups" "SELECT EXISTS"
" WHERE GrpCod=%ld", "(SELECT *"
GrpCod) != 0); " FROM grp_groups"
" WHERE GrpCod=%ld)",
GrpCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -209,15 +211,16 @@ bool Grp_DB_CheckIfGrpExists (long GrpCod)
bool Grp_DB_CheckIfGrpBelongsToCrs (long GrpCod,long CrsCod) bool Grp_DB_CheckIfGrpBelongsToCrs (long GrpCod,long CrsCod)
{ {
/***** Get if a group exists from database *****/ return
return (DB_QueryCOUNT ("can not check if a group belongs to a course", DB_QueryEXISTS ("can not check if a group belongs to a course",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM grp_groups," "(SELECT *"
"grp_types" " FROM grp_groups,"
" WHERE grp_groups.GrpCod=%ld" "grp_types"
" AND grp_groups.GrpTypCod=grp_types.GrpTypCod" " WHERE grp_groups.GrpCod=%ld"
" AND grp_types.CrsCod=%ld", " AND grp_groups.GrpTypCod=grp_types.GrpTypCod"
GrpCod,CrsCod) != 0); " AND grp_types.CrsCod=%ld)",
GrpCod,CrsCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -226,17 +229,17 @@ bool Grp_DB_CheckIfGrpBelongsToCrs (long GrpCod,long CrsCod)
bool Grp_DB_CheckIfGrpTypNameExistsInCurrentCrs (const char *GrpTypName,long GrpTypCod) bool Grp_DB_CheckIfGrpTypNameExistsInCurrentCrs (const char *GrpTypName,long GrpTypCod)
{ {
/***** Get number of group types with a name from database *****/ return
return (DB_QueryCOUNT ("can not check if the name of type of group" DB_QueryEXISTS ("can not check if the name of type of group already existed",
" already existed", "SELECT EXISTS"
"SELECT COUNT(*)" "(SELECT *"
" FROM grp_types" " FROM grp_types"
" WHERE CrsCod=%ld" " WHERE CrsCod=%ld"
" AND GrpTypName='%s'" " AND GrpTypName='%s'"
" AND GrpTypCod<>%ld", " AND GrpTypCod<>%ld)",
Gbl.Hierarchy.Crs.CrsCod, Gbl.Hierarchy.Crs.CrsCod,
GrpTypName, GrpTypName,
GrpTypCod) != 0); GrpTypCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -245,16 +248,17 @@ bool Grp_DB_CheckIfGrpTypNameExistsInCurrentCrs (const char *GrpTypName,long Grp
bool Grp_DB_CheckIfGrpNameExistsForGrpTyp (long GrpTypCod,const char *GrpName,long GrpCod) bool Grp_DB_CheckIfGrpNameExistsForGrpTyp (long GrpTypCod,const char *GrpName,long GrpCod)
{ {
/***** Get number of groups with a type and a name from database *****/ return
return (DB_QueryCOUNT ("can not check if the name of group already existed", DB_QueryEXISTS ("can not check if the name of group already existed",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM grp_groups" "(SELECT *"
" WHERE GrpTypCod=%ld" " FROM grp_groups"
" AND GrpName='%s'" " WHERE GrpTypCod=%ld"
" AND GrpCod<>%ld", " AND GrpName='%s'"
GrpTypCod, " AND GrpCod<>%ld)",
GrpName, GrpTypCod,
GrpCod) != 0); GrpName,
GrpCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -372,15 +376,17 @@ unsigned Grp_DB_GetTchsFromCurrentGrpExceptMe (MYSQL_RES **mysql_res)
bool Grp_DB_CheckIfIBelongToGrpsOfType (long GrpTypCod) bool Grp_DB_CheckIfIBelongToGrpsOfType (long GrpTypCod)
{ {
return (DB_QueryCOUNT ("can not check if you belong to a group type", return
"SELECT COUNT(grp_groups.GrpCod)" DB_QueryEXISTS ("can not check if you belong to a group type",
" FROM grp_groups," "SELECT EXISTS"
"grp_users" "(SELECT *"
" WHERE grp_groups.GrpTypCod=%ld" " FROM grp_groups,"
" AND grp_groups.GrpCod=grp_users.GrpCod" "grp_users"
" AND grp_users.UsrCod=%ld", // I belong " WHERE grp_groups.GrpTypCod=%ld"
GrpTypCod, " AND grp_groups.GrpCod=grp_users.GrpCod"
Gbl.Usrs.Me.UsrDat.UsrCod) != 0); " AND grp_users.UsrCod=%ld)", // I belong
GrpTypCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -389,39 +395,41 @@ bool Grp_DB_CheckIfIBelongToGrpsOfType (long GrpTypCod)
bool Grp_DB_CheckIfIBelongToGrp (long GrpCod) bool Grp_DB_CheckIfIBelongToGrp (long GrpCod)
{ {
return (DB_QueryCOUNT ("can not check if you belong to a group", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if you belong to a group",
" FROM grp_users" "SELECT EXISTS"
" WHERE GrpCod=%ld" "(SELECT *"
" AND UsrCod=%ld", // I belong " FROM grp_users"
GrpCod, " WHERE GrpCod=%ld"
Gbl.Usrs.Me.UsrDat.UsrCod) != 0); " AND UsrCod=%ld)", // I belong
GrpCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
/***** Check if a user belongs to any of my groups in the current course *****/ /***** Check if a user belongs to any of my groups in the current course *****/
/*****************************************************************************/ /*****************************************************************************/
unsigned Grp_DB_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (long UsrCod) bool Grp_DB_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (long UsrCod)
{ {
return (unsigned) return
(DB_QueryCOUNT ("can not check if a user shares any group" DB_QueryEXISTS ("can not check if a user shares any group in the current course with you",
" in the current course with you", "SELECT EXISTS"
"SELECT COUNT(*)" "(SELECT *"
" FROM grp_users" " FROM grp_users"
" WHERE UsrCod=%ld" " WHERE UsrCod=%ld"
" AND GrpCod IN" " AND GrpCod IN"
" (SELECT grp_users.GrpCod" " (SELECT grp_users.GrpCod"
" FROM grp_users," " FROM grp_users,"
"grp_groups," "grp_groups,"
"grp_types" "grp_types"
" WHERE grp_users.UsrCod=%ld" " WHERE grp_users.UsrCod=%ld"
" AND grp_users.GrpCod=grp_groups.GrpCod" " AND grp_users.GrpCod=grp_groups.GrpCod"
" AND grp_groups.GrpTypCod=grp_types.GrpTypCod" " AND grp_groups.GrpTypCod=grp_types.GrpTypCod"
" AND grp_types.CrsCod=%ld)", " AND grp_types.CrsCod=%ld))",
UsrCod, UsrCod,
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Hierarchy.Crs.CrsCod) != 0); Gbl.Hierarchy.Crs.CrsCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -678,14 +686,16 @@ long Grp_DB_GetGrpTypeFromGrp (long GrpCod)
bool Grp_DB_CheckIfAssociatedToGrp (const char *Table,const char *Field, bool Grp_DB_CheckIfAssociatedToGrp (const char *Table,const char *Field,
long Cod,long GrpCod) long Cod,long GrpCod)
{ {
return (DB_QueryCOUNT ("can not check if associated to a group", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if associated to a group",
" FROM %s" "SELECT EXISTS"
" WHERE %s=%ld" "(SELECT *"
" AND GrpCod=%ld", " FROM %s"
Table, " WHERE %s=%ld"
Field,Cod, " AND GrpCod=%ld)",
GrpCod) != 0); Table,
Field,Cod,
GrpCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -701,12 +711,14 @@ bool Grp_DB_CheckIfAssociatedToGrps (const char *Table,const char *Field,long Co
/***** Check if an assignment, attendance event, survey, /***** Check if an assignment, attendance event, survey,
exam session or match is associated to any group *****/ exam session or match is associated to any group *****/
return (DB_QueryCOUNT ("can not check if associated to groups", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if associated to groups",
" FROM %s" "SELECT EXISTS"
" WHERE %s=%ld", "(SELECT *"
Table, " FROM %s"
Field,Cod) != 0); " WHERE %s=%ld)",
Table,
Field,Cod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -65,7 +65,7 @@ unsigned Grp_DB_GetTchsFromCurrentGrpExceptMe (MYSQL_RES **mysql_res);
bool Grp_DB_CheckIfIBelongToGrpsOfType (long GrpTypCod); bool Grp_DB_CheckIfIBelongToGrpsOfType (long GrpTypCod);
bool Grp_DB_CheckIfIBelongToGrp (long GrpCod); bool Grp_DB_CheckIfIBelongToGrp (long GrpCod);
unsigned Grp_DB_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (long UsrCod); bool Grp_DB_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (long UsrCod);
unsigned Grp_DB_GetGrpTypesWithGrpsInCurrentCrs (MYSQL_RES **mysql_res); unsigned Grp_DB_GetGrpTypesWithGrpsInCurrentCrs (MYSQL_RES **mysql_res);
unsigned Grp_DB_GetAllGrpTypesInCurrentCrs (MYSQL_RES **mysql_res); unsigned Grp_DB_GetAllGrpTypesInCurrentCrs (MYSQL_RES **mysql_res);

View File

@ -277,15 +277,17 @@ void Inf_DB_SetIHaveRead (bool IHaveRead)
bool Inf_DB_CheckIfIHaveReadInfo (void) bool Inf_DB_CheckIfIHaveReadInfo (void)
{ {
return (DB_QueryCOUNT ("can not get if I have read course info", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if I have read course info",
" FROM crs_info_read" "SELECT EXISTS"
" WHERE UsrCod=%ld" "(SELECT *"
" AND CrsCod=%ld" " FROM crs_info_read"
" AND InfoType='%s'", " WHERE UsrCod=%ld"
Gbl.Usrs.Me.UsrDat.UsrCod, " AND CrsCod=%ld"
Gbl.Hierarchy.Crs.CrsCod, " AND InfoType='%s')",
Inf_DB_NamesForInfoType[Gbl.Crs.Info.Type]) != 0); Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Hierarchy.Crs.CrsCod,
Inf_DB_NamesForInfoType[Gbl.Crs.Info.Type]);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -1973,7 +1973,7 @@ static void Ins_FormToGoToMap (struct Ins_Instit *Ins)
{ {
extern const char *Txt_Map; extern const char *Txt_Map;
if (Ctr_DB_GetIfMapIsAvailableInIns (Ins->InsCod)) if (Ctr_DB_CheckIfMapIsAvailableInIns (Ins->InsCod))
{ {
Ins_EditingIns = Ins; // Used to pass parameter with the code of the institution Ins_EditingIns = Ins; // Used to pass parameter with the code of the institution
Lay_PutContextualLinkOnlyIcon (ActSeeInsInf,NULL, Lay_PutContextualLinkOnlyIcon (ActSeeInsInf,NULL,

View File

@ -210,14 +210,17 @@ bool Ins_DB_CheckIfInsNameExistsInCty (const char *FieldName,
long InsCod, long InsCod,
long CtyCod) long CtyCod)
{ {
return (DB_QueryCOUNT ("can not check if the name of an institution" return
" already existed", DB_QueryEXISTS ("can not check if the name of an institution already existed",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM ins_instits" "(SELECT *"
" WHERE CtyCod=%ld" " FROM ins_instits"
" AND %s='%s'" " WHERE CtyCod=%ld"
" AND InsCod<>%ld", " AND %s='%s'"
CtyCod,FieldName,Name,InsCod) != 0); " AND InsCod<>%ld)",
CtyCod,
FieldName,Name,
InsCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -131,14 +131,15 @@ unsigned Lnk_DB_GetDataOfLinkByCod (MYSQL_RES **mysql_res,long LnkCod)
bool Lnk_DB_CheckIfLinkNameExists (const char *FieldName,const char *Name,long LnkCod) bool Lnk_DB_CheckIfLinkNameExists (const char *FieldName,const char *Name,long LnkCod)
{ {
return (DB_QueryCOUNT ("can not check if the name of an institutional link" return
" already existed", DB_QueryEXISTS ("can not check if the name of an institutional link already existed",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM lnk_links" "(SELECT *"
" WHERE %s='%s'" " FROM lnk_links"
" AND LnkCod<>%ld", " WHERE %s='%s'"
FieldName,Name, " AND LnkCod<>%ld)",
LnkCod) != 0); FieldName,Name,
LnkCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -165,14 +165,16 @@ char Mai_DB_CheckIfEmailIsConfirmed (long UsrCod,const char Email[Cns_MAX_BYTES_
bool Mai_DB_CheckIfEmailBelongToAnotherUsr (long UsrCod,const char Email[Cns_MAX_BYTES_EMAIL_ADDRESS + 1]) bool Mai_DB_CheckIfEmailBelongToAnotherUsr (long UsrCod,const char Email[Cns_MAX_BYTES_EMAIL_ADDRESS + 1])
{ {
return (DB_QueryCOUNT ("can not check if email already existed", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if email already existed",
" FROM usr_emails" "SELECT EXISTS"
" WHERE E_mail='%s'" "(SELECT *"
" AND Confirmed='Y'" " FROM usr_emails"
" AND UsrCod<>%ld", " WHERE E_mail='%s'"
Email, " AND Confirmed='Y'"
UsrCod) != 0); " AND UsrCod<>%ld)",
Email,
UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -411,15 +413,15 @@ unsigned Mai_DB_GetDataOfMailDomainByCod (MYSQL_RES **mysql_res,long MaiCod)
bool Mai_DB_CheckIfMailDomainNameExists (const char *FieldName,const char *Name,long MaiCod) bool Mai_DB_CheckIfMailDomainNameExists (const char *FieldName,const char *Name,long MaiCod)
{ {
/***** Get number of mail_domains with a name from database *****/ return
return (DB_QueryCOUNT ("can not check if the name" DB_QueryEXISTS ("can not check if the name of a mail domain already existed",
" of a mail domain already existed", "SELECT EXISTS"
"SELECT COUNT(*)" "(SELECT *"
" FROM ntf_mail_domains" " FROM ntf_mail_domains"
" WHERE %s='%s'" " WHERE %s='%s'"
" AND MaiCod<>%ld", " AND MaiCod<>%ld)",
FieldName,Name, FieldName,Name,
MaiCod) != 0); MaiCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -428,13 +430,13 @@ bool Mai_DB_CheckIfMailDomainNameExists (const char *FieldName,const char *Name,
bool Mai_DB_CheckIfMailDomainIsAllowedForNotif (const char MailDomain[Cns_MAX_BYTES_EMAIL_ADDRESS + 1]) bool Mai_DB_CheckIfMailDomainIsAllowedForNotif (const char MailDomain[Cns_MAX_BYTES_EMAIL_ADDRESS + 1])
{ {
/***** Get number of mail_domains with a name from database *****/ return
return (DB_QueryCOUNT ("can not check if a mail domain" DB_QueryEXISTS ("can not check if a mail domain is allowed for notifications",
" is allowed for notifications", "SELECT EXISTS"
"SELECT COUNT(*)" "(SELECT *"
" FROM ntf_mail_domains" " FROM ntf_mail_domains"
" WHERE Domain='%s'", " WHERE Domain='%s')",
MailDomain) != 0); MailDomain);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -966,7 +966,7 @@ static void Mch_GetMatchDataFromRow (MYSQL_RES *mysql_res,
if (Match->Status.Showing == Mch_END) // Match over if (Match->Status.Showing == Mch_END) // Match over
Match->Status.Playing = false; Match->Status.Playing = false;
else // Match not over else // Match not over
Match->Status.Playing = Mch_DB_GetIfMatchIsBeingPlayed (Match->MchCod); Match->Status.Playing = Mch_DB_CheckIfMatchIsBeingPlayed (Match->MchCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -493,22 +493,24 @@ unsigned Mch_DB_GetGrpsAssociatedToMatch (MYSQL_RES **mysql_res,long MchCod)
bool Mch_DB_CheckIfICanPlayThisMatchBasedOnGrps (long MchCod) bool Mch_DB_CheckIfICanPlayThisMatchBasedOnGrps (long MchCod)
{ {
return (DB_QueryCOUNT ("can not check if I can play a match", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if I can play a match",
" FROM mch_matches" "SELECT EXISTS"
" WHERE MchCod=%ld" "(SELECT *"
" AND (MchCod NOT IN" " FROM mch_matches"
" (SELECT MchCod" " WHERE MchCod=%ld"
" FROM mch_groups)" " AND (MchCod NOT IN"
" OR" " (SELECT MchCod"
" MchCod IN" " FROM mch_groups)"
" (SELECT mch_groups.MchCod" " OR"
" FROM grp_users," " MchCod IN"
"mch_groups" " (SELECT mch_groups.MchCod"
" WHERE grp_users.UsrCod=%ld" " FROM grp_users,"
" AND grp_users.GrpCod=mch_groups.GrpCod))", "mch_groups"
MchCod, " WHERE grp_users.UsrCod=%ld"
Gbl.Usrs.Me.UsrDat.UsrCod) != 0); " AND grp_users.GrpCod=mch_groups.GrpCod)))",
MchCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -750,16 +752,18 @@ void Mch_DB_RegisterMeAsPlayerInMatch (long MchCod)
} }
/*****************************************************************************/ /*****************************************************************************/
/*********************** Get if match is being played ************************/ /********************** Check if match is being played ***********************/
/*****************************************************************************/ /*****************************************************************************/
bool Mch_DB_GetIfMatchIsBeingPlayed (long MchCod) bool Mch_DB_CheckIfMatchIsBeingPlayed (long MchCod)
{ {
return (DB_QueryCOUNT ("can not get if match is being played", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if match is being played",
" FROM mch_playing" "SELECT EXISTS"
" WHERE MchCod=%ld", "(SELECT *"
MchCod) != 0); " FROM mch_playing"
" WHERE MchCod=%ld)",
MchCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -923,13 +927,15 @@ void Mch_DB_UpdateMatchPrint (const struct MchPrn_Print *Print)
bool Mch_DB_CheckIfMatchPrintExists (const struct MchPrn_Print *Print) bool Mch_DB_CheckIfMatchPrintExists (const struct MchPrn_Print *Print)
{ {
return (DB_QueryCOUNT ("can not get if match print exists", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if match print exists",
" FROM mch_results" "SELECT EXISTS"
" WHERE MchCod=%ld" "(SELECT *"
" AND UsrCod=%ld", " FROM mch_results"
Print->MchCod, " WHERE MchCod=%ld"
Print->UsrCod) != 0); " AND UsrCod=%ld)",
Print->MchCod,
Print->UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -95,7 +95,7 @@ void Mch_DB_GetIndexes (long MchCod,unsigned QstInd,
void Mch_DB_UpdateMatchAsBeingPlayed (long MchCod); void Mch_DB_UpdateMatchAsBeingPlayed (long MchCod);
void Mch_DB_RegisterMeAsPlayerInMatch (long MchCod); void Mch_DB_RegisterMeAsPlayerInMatch (long MchCod);
bool Mch_DB_GetIfMatchIsBeingPlayed (long MchCod); bool Mch_DB_CheckIfMatchIsBeingPlayed (long MchCod);
unsigned Mch_DB_GetNumPlayers (long MchCod); unsigned Mch_DB_GetNumPlayers (long MchCod);
void Mch_DB_RemoveMatchFromBeingPlayed (long MchCod); void Mch_DB_RemoveMatchFromBeingPlayed (long MchCod);

View File

@ -773,13 +773,15 @@ void Msg_DB_GetStatusOfRcvMsg (long MsgCod,
bool Msg_DB_CheckIfSntMsgIsDeleted (long MsgCod) bool Msg_DB_CheckIfSntMsgIsDeleted (long MsgCod)
{ {
return (DB_QueryCOUNT ("can not check if a sent message is deleted", return
"SELECT COUNT(*)" !DB_QueryEXISTS ("can not check if a sent message is deleted",
" FROM msg_snt" "SELECT EXISTS"
" WHERE MsgCod=%ld", "(SELECT *"
MsgCod) == 0); // The message has been deleted " FROM msg_snt"
// by its author when it is not present " WHERE MsgCod=%ld)",
// in table of sent messages undeleted MsgCod); // The message has been deleted
// by its author when it is not present
// in table of sent messages undeleted
} }
/*****************************************************************************/ /*****************************************************************************/
@ -788,14 +790,15 @@ bool Msg_DB_CheckIfSntMsgIsDeleted (long MsgCod)
bool Msg_DB_CheckIfRcvMsgIsDeletedForAllItsRecipients (long MsgCod) bool Msg_DB_CheckIfRcvMsgIsDeletedForAllItsRecipients (long MsgCod)
{ {
return (DB_QueryCOUNT ("can not check if a received message" return
" is deleted by all recipients", !DB_QueryEXISTS ("can not check if a received message is deleted by all recipients",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM msg_rcv" "(SELECT *"
" WHERE MsgCod=%ld", " FROM msg_rcv"
MsgCod) == 0); // The message has been deleted " WHERE MsgCod=%ld)",
// by all its recipients when it is not present MsgCod); // The message has been deleted
// in table of received messages undeleted // by all its recipients when it is not present
// in table of received messages undeleted
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1440,13 +1443,15 @@ unsigned Msg_DB_GetUsrsBannedBy (MYSQL_RES **mysql_res,long UsrCod)
bool Msg_DB_CheckIfUsrIsBanned (long FromUsrCod,long ToUsrCod) bool Msg_DB_CheckIfUsrIsBanned (long FromUsrCod,long ToUsrCod)
{ {
/***** Get if FromUsrCod is banned by ToUsrCod *****/ return
return (DB_QueryCOUNT ("can not check if a user is banned", DB_QueryEXISTS ("can not check if a user is banned",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM msg_banned" "(SELECT *"
" WHERE FromUsrCod=%ld" " FROM msg_banned"
" AND ToUsrCod=%ld", " WHERE FromUsrCod=%ld"
FromUsrCod,ToUsrCod) != 0); " AND ToUsrCod=%ld)",
FromUsrCod,
ToUsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -117,13 +117,15 @@ unsigned Nck_DB_GetUsrNicknames (MYSQL_RES **mysql_res,long UsrCod)
bool Nck_DB_CheckIfNickMatchesAnyUsrNick (long UsrCod,const char *NickWithoutArr) bool Nck_DB_CheckIfNickMatchesAnyUsrNick (long UsrCod,const char *NickWithoutArr)
{ {
return (DB_QueryCOUNT ("can not check if nickname already existed", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if nickname already existed",
" FROM usr_nicknames" "SELECT EXISTS"
" WHERE UsrCod=%ld" "(SELECT *"
" AND Nickname='%s'", " FROM usr_nicknames"
UsrCod, " WHERE UsrCod=%ld"
NickWithoutArr) != 0); " AND Nickname='%s')",
UsrCod,
NickWithoutArr);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -132,13 +134,15 @@ bool Nck_DB_CheckIfNickMatchesAnyUsrNick (long UsrCod,const char *NickWithoutArr
bool Nck_DB_CheckIfNickMatchesAnyOtherUsrsNicks (long UsrCod,const char *NickWithoutArr) bool Nck_DB_CheckIfNickMatchesAnyOtherUsrsNicks (long UsrCod,const char *NickWithoutArr)
{ {
return (DB_QueryCOUNT ("can not check if nickname already existed", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if nickname already existed",
" FROM usr_nicknames" "SELECT EXISTS"
" WHERE Nickname='%s'" "(SELECT *"
" AND UsrCod<>%ld", " FROM usr_nicknames"
NickWithoutArr, " WHERE Nickname='%s'"
UsrCod) != 0); // A nickname of another user is the same that user's nickname " AND UsrCod<>%ld)",
NickWithoutArr,
UsrCod); // A nickname of another user is the same that user's nickname
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -164,16 +164,17 @@ unsigned Plc_DB_GetDataOfPlaceByCod (MYSQL_RES **mysql_res,long PlcCod)
bool Plc_DB_CheckIfPlaceNameExists (long PlcCod, bool Plc_DB_CheckIfPlaceNameExists (long PlcCod,
const char *FieldName,const char *Name) const char *FieldName,const char *Name)
{ {
return (DB_QueryCOUNT ("can not check if the name of a place" return
" already existed", DB_QueryEXISTS ("can not check if the name of a place already existed",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM plc_places" "(SELECT *"
" WHERE InsCod=%ld" " FROM plc_places"
" AND %s='%s'" " WHERE InsCod=%ld"
" AND PlcCod<>%ld", " AND %s='%s'"
Gbl.Hierarchy.Ins.InsCod, " AND PlcCod<>%ld)",
FieldName,Name, Gbl.Hierarchy.Ins.InsCod,
PlcCod) != 0); FieldName,Name,
PlcCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -200,15 +200,15 @@ unsigned Plg_DB_GetDataOfPluginByCod (MYSQL_RES **mysql_res,long PlgCod)
bool Plg_DB_CheckIfPluginNameExists (const char *Name,long PlgCod) bool Plg_DB_CheckIfPluginNameExists (const char *Name,long PlgCod)
{ {
/***** Get number of plugins with a name from database *****/ return
return (DB_QueryCOUNT ("can not check if the name of a plugin" DB_QueryEXISTS ("can not check if the name of a plugin already existed",
" already existed", "SELECT EXISTS"
"SELECT COUNT(*)" "(SELECT *"
" FROM plg_plugins" " FROM plg_plugins"
" WHERE Name='%s'" " WHERE Name='%s'"
" AND PlgCod<>%ld", " AND PlgCod<>%ld)",
Name, Name,
PlgCod) != 0); PlgCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -279,17 +279,17 @@ unsigned Roo_DB_GetListRooms (MYSQL_RES **mysql_res,
bool Roo_DB_CheckIfRoomNameExists (long CtrCod,long RooCod, bool Roo_DB_CheckIfRoomNameExists (long CtrCod,long RooCod,
const char *FieldName,const char *Name) const char *FieldName,const char *Name)
{ {
/***** Get number of rooms with a name from database *****/ return
return (DB_QueryCOUNT ("can not check if the name of a room" DB_QueryEXISTS ("can not check if the name of a room already existed",
" already existed", "SELECT EXISTS"
"SELECT COUNT(*)" "(SELECT *"
" FROM roo_rooms" " FROM roo_rooms"
" WHERE CtrCod=%ld" " WHERE CtrCod=%ld"
" AND %s='%s'" " AND %s='%s'"
" AND RooCod<>%ld", " AND RooCod<>%ld)",
CtrCod, CtrCod,
FieldName,Name, FieldName,Name,
RooCod) != 0); RooCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -155,12 +155,13 @@ void Ses_DB_UpdateSessionLastRefresh (void)
bool Ses_DB_CheckIfSessionExists (const char *IdSes) bool Ses_DB_CheckIfSessionExists (const char *IdSes)
{ {
/***** Get if session already exists in database *****/ return
return (DB_QueryCOUNT ("can not check if a session already existed", DB_QueryEXISTS ("can not check if a session already existed",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM ses_sessions" "(SELECT *"
" WHERE SessionId='%s'", " FROM ses_sessions"
IdSes) != 0); " WHERE SessionId='%s')",
IdSes);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -277,14 +278,15 @@ void Ses_DB_InsertParam (const char *ParamName,const char *ParamValue)
bool Ses_DB_CheckIfParamIsAlreadyStored (const char *ParamName) bool Ses_DB_CheckIfParamIsAlreadyStored (const char *ParamName)
{ {
return (DB_QueryCOUNT ("can not check if a session parameter" return
" is already in database", DB_QueryEXISTS ("can not check if a session parameter is already in database",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM ses_params" "(SELECT *"
" WHERE SessionId='%s'" " FROM ses_params"
" AND ParamName='%s'", " WHERE SessionId='%s'"
Gbl.Session.Id, " AND ParamName='%s')",
ParamName) != 0); Gbl.Session.Id,
ParamName);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -332,18 +332,19 @@ void Svy_DB_GetSurveyTxt (long SvyCod,char Txt[Cns_MAX_BYTES_TEXT + 1])
bool Svy_DB_CheckIfSimilarSurveyExists (const struct Svy_Survey *Svy) bool Svy_DB_CheckIfSimilarSurveyExists (const struct Svy_Survey *Svy)
{ {
/***** Get number of surveys with a field value from database *****/ return
return (DB_QueryCOUNT ("can not get similar surveys", DB_QueryEXISTS ("can not get similar surveys",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM svy_surveys" "(SELECT *"
" WHERE Scope='%s'" " FROM svy_surveys"
" AND Cod=%ld" " WHERE Scope='%s'"
" AND Title='%s'" " AND Cod=%ld"
" AND SvyCod<>%ld", " AND Title='%s'"
Sco_GetDBStrFromScope (Svy->Scope), " AND SvyCod<>%ld)",
Svy->Cod, Sco_GetDBStrFromScope (Svy->Scope),
Svy->Title, Svy->Cod,
Svy->SvyCod) != 0); Svy->Title,
Svy->SvyCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -749,22 +750,24 @@ unsigned Svy_DB_GetGrpNamesAssociatedToSvy (MYSQL_RES **mysql_res,long SvyCod)
bool Svy_DB_CheckIfICanDoThisSurveyBasedOnGrps (long SvyCod) bool Svy_DB_CheckIfICanDoThisSurveyBasedOnGrps (long SvyCod)
{ {
return (DB_QueryCOUNT ("can not check if I can do a survey", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if I can do a survey",
" FROM svy_surveys" "SELECT EXISTS"
" WHERE SvyCod=%ld" "(SELECT *"
" AND (SvyCod NOT IN" " FROM svy_surveys"
" (SELECT SvyCod" " WHERE SvyCod=%ld"
" FROM svy_groups)" " AND (SvyCod NOT IN"
" OR" " (SELECT SvyCod"
" SvyCod IN" " FROM svy_groups)"
" (SELECT svy_groups.SvyCod" " OR"
" FROM grp_users," " SvyCod IN"
"svy_groups" " (SELECT svy_groups.SvyCod"
" WHERE grp_users.UsrCod=%ld" " FROM grp_users,"
" AND grp_users.GrpCod=svy_groups.GrpCod))", "svy_groups"
SvyCod, " WHERE grp_users.UsrCod=%ld"
Gbl.Usrs.Me.UsrDat.UsrCod) != 0); " AND grp_users.GrpCod=svy_groups.GrpCod)))",
SvyCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1087,13 +1090,15 @@ void Svy_DB_IncreaseAnswer (long QstCod,unsigned AnsInd)
bool Svy_DB_CheckIfAnswerExists (long QstCod,unsigned AnsInd) bool Svy_DB_CheckIfAnswerExists (long QstCod,unsigned AnsInd)
{ {
return (DB_QueryCOUNT ("can not check if an answer exists", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if an answer exists",
" FROM svy_answers" "SELECT EXISTS"
" WHERE QstCod=%ld" "(SELECT *"
" AND AnsInd=%u", " FROM svy_answers"
QstCod, " WHERE QstCod=%ld"
AnsInd) != 0); " AND AnsInd=%u)",
QstCod,
AnsInd);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1220,13 +1225,15 @@ void Svy_DB_RegisterIHaveAnsweredSvy (long SvyCod)
bool Svy_DB_CheckIfIHaveAnsweredSvy (long SvyCod) bool Svy_DB_CheckIfIHaveAnsweredSvy (long SvyCod)
{ {
return (DB_QueryCOUNT ("can not check if you have answered a survey", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if you have answered a survey",
" FROM svy_users" "SELECT EXISTS"
" WHERE SvyCod=%ld" "(SELECT *"
" AND UsrCod=%ld", " FROM svy_users"
SvyCod, " WHERE SvyCod=%ld"
Gbl.Usrs.Me.UsrDat.UsrCod) != 0); " AND UsrCod=%ld)",
SvyCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -245,12 +245,13 @@ unsigned Tag_DB_GetEnabledTagsFromThisCrs (MYSQL_RES **mysql_res)
bool Tag_DB_CheckIfCurrentCrsHasTestTags (void) bool Tag_DB_CheckIfCurrentCrsHasTestTags (void)
{ {
/***** Get available tags from database *****/ return
return (DB_QueryCOUNT ("can not check if course has tags", DB_QueryEXISTS ("can not check if course has tags",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM tst_tags" "(SELECT *"
" WHERE CrsCod=%ld", " FROM tst_tags"
Gbl.Hierarchy.Crs.CrsCod) != 0); " WHERE CrsCod=%ld)",
Gbl.Hierarchy.Crs.CrsCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -663,7 +663,8 @@ unsigned Tml_DB_GetNumCommsInNote (long NotCod)
" FROM tml_pubs" " FROM tml_pubs"
" WHERE NotCod=%ld" " WHERE NotCod=%ld"
" AND PubType=%u", " AND PubType=%u",
NotCod,(unsigned) Tml_Pub_COMMENT_TO_NOTE); NotCod,
(unsigned) Tml_Pub_COMMENT_TO_NOTE);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1186,13 +1187,15 @@ void Tml_DB_RemoveAllPubsPublishedBy (long UsrCod)
bool Tml_DB_CheckIfFavedByUsr (Tml_Usr_FavSha_t FavSha,long Cod,long UsrCod) bool Tml_DB_CheckIfFavedByUsr (Tml_Usr_FavSha_t FavSha,long Cod,long UsrCod)
{ {
return (DB_QueryCOUNT ("can not check if a user has favourited", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if a user has favourited",
" FROM %s" "SELECT EXISTS"
" WHERE %s=%ld" "(SELECT *"
" AND UsrCod=%ld", " FROM %s"
Tml_DB_TableFav[FavSha], " WHERE %s=%ld"
Tml_DB_FieldFav[FavSha],Cod,UsrCod) != 0); " AND UsrCod=%ld)",
Tml_DB_TableFav[FavSha],
Tml_DB_FieldFav[FavSha],Cod,UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1325,15 +1328,17 @@ void Tml_DB_RemoveAllFavsToAllCommsInAllNotesBy (long UsrCod)
bool Tml_DB_CheckIfSharedByUsr (long NotCod,long UsrCod) bool Tml_DB_CheckIfSharedByUsr (long NotCod,long UsrCod)
{ {
return (DB_QueryCOUNT ("can not check if a user has shared a note", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if a user has shared a note",
" FROM tml_pubs" "SELECT EXISTS"
" WHERE NotCod=%ld" "(SELECT *"
" AND PublisherCod=%ld" " FROM tml_pubs"
" AND PubType=%u", " WHERE NotCod=%ld"
NotCod, " AND PublisherCod=%ld"
UsrCod, " AND PubType=%u)",
(unsigned) Tml_Pub_SHARED_NOTE) != 0); NotCod,
UsrCod,
(unsigned) Tml_Pub_SHARED_NOTE);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -441,26 +441,9 @@ bool Usr_ItsMe (long UsrCod)
void Usr_GetUsrCodFromEncryptedUsrCod (struct UsrData *UsrDat) void Usr_GetUsrCodFromEncryptedUsrCod (struct UsrData *UsrDat)
{ {
MYSQL_RES *mysql_res;
MYSQL_ROW row;
if (UsrDat->EnUsrCod[0]) if (UsrDat->EnUsrCod[0])
{
/***** Get user's code from database *****/ /***** Get user's code from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get user's code", UsrDat->UsrCod = Usr_DB_GetUsrCodFromEncryptedUsrCod (UsrDat->EnUsrCod);
"SELECT UsrCod"
" FROM usr_data"
" WHERE EncryptedUsrCod='%s'",
UsrDat->EnUsrCod) != 1)
Err_ShowErrorAndExit ("Error when getting user's code.");
/***** Get user's code *****/
row = mysql_fetch_row (mysql_res);
UsrDat->UsrCod = Str_ConvertStrCodToLongCod (row[0]);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
else else
UsrDat->UsrCod = -1L; UsrDat->UsrCod = -1L;
} }
@ -919,13 +902,14 @@ bool Usr_CheckIfUsrIsSuperuser (long UsrCod)
/***** 3. Slow check: If not cached, get if a user is superuser from database *****/ /***** 3. Slow check: If not cached, get if a user is superuser from database *****/
Gbl.Cache.UsrIsSuperuser.UsrCod = UsrCod; Gbl.Cache.UsrIsSuperuser.UsrCod = UsrCod;
Gbl.Cache.UsrIsSuperuser.IsSuperuser = Gbl.Cache.UsrIsSuperuser.IsSuperuser =
(DB_QueryCOUNT ("can not check if a user is superuser", DB_QueryEXISTS ("can not check if a user is superuser",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM usr_admins" "(SELECT *"
" WHERE UsrCod=%ld" " FROM usr_admins"
" AND Scope='%s'", " WHERE UsrCod=%ld"
UsrCod, " AND Scope='%s')",
Sco_GetDBStrFromScope (HieLvl_SYS)) != 0); UsrCod,
Sco_GetDBStrFromScope (HieLvl_SYS));
return Gbl.Cache.UsrIsSuperuser.IsSuperuser; return Gbl.Cache.UsrIsSuperuser.IsSuperuser;
} }
@ -2306,11 +2290,12 @@ bool Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (struct UsrData *UsrDat,
void Usr_UpdateMyLastData (void) void Usr_UpdateMyLastData (void)
{ {
/***** Check if it exists an entry for me *****/ /***** Check if it exists an entry for me *****/
if (DB_QueryCOUNT ("can not get last user's click", if (DB_QueryEXISTS ("can not check last user's click",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM usr_last" "(SELECT *"
" WHERE UsrCod=%ld", " FROM usr_last"
Gbl.Usrs.Me.UsrDat.UsrCod)) " WHERE UsrCod=%ld)",
Gbl.Usrs.Me.UsrDat.UsrCod))
/***** Update my last accessed course, tab and time of click in database *****/ /***** Update my last accessed course, tab and time of click in database *****/
// WhatToSearch, LastAccNotif remain unchanged // WhatToSearch, LastAccNotif remain unchanged
DB_QueryUPDATE ("can not update last user's data", DB_QueryUPDATE ("can not update last user's data",

View File

@ -161,27 +161,29 @@ bool Usr_DB_ChkIfUsrCodExists (long UsrCod)
if (UsrCod <= 0) // Wrong user's code if (UsrCod <= 0) // Wrong user's code
return false; return false;
/***** Get if a user exists in database *****/ /***** Check if a user exists in database *****/
return (DB_QueryCOUNT ("can not check if a user exists", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if a user exists",
" FROM usr_data" "SELECT EXISTS"
" WHERE UsrCod=%ld", "(SELECT *"
UsrCod) != 0); " FROM usr_data"
" WHERE UsrCod=%ld)",
UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
/******** Check if a user exists with a given encrypted user's code **********/ /******** Get user's code from database using encrypted user's code **********/
/*****************************************************************************/ /*****************************************************************************/
// Input: UsrDat->EncryptedUsrCod must hold user's encrypted code
bool Usr_DB_ChkIfEncryptedUsrCodExists (const char EncryptedUsrCod[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64]) long Usr_DB_GetUsrCodFromEncryptedUsrCod (const char EncryptedUsrCod[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1])
{ {
/***** Get if an encrypted user's code already existed in database *****/ return
return (DB_QueryCOUNT ("can not check if an encrypted user's code" DB_QuerySELECTCode ("can not get user's code",
" already existed", "SELECT UsrCod"
"SELECT COUNT(*)" " FROM usr_data"
" FROM usr_data" " WHERE EncryptedUsrCod='%s'",
" WHERE EncryptedUsrCod='%s'", EncryptedUsrCod);
EncryptedUsrCod) != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -190,16 +192,17 @@ bool Usr_DB_ChkIfEncryptedUsrCodExists (const char EncryptedUsrCod[Cry_BYTES_ENC
bool Usr_DB_FindStrInUsrsNames (const char *Str) bool Usr_DB_FindStrInUsrsNames (const char *Str)
{ {
return (DB_QueryCOUNT ("can not check if a string matches" return
" a first name or a surname", DB_QueryEXISTS ("can not check if a string matches a first name or a surname",
"SELECT COUNT(*)" "SELECT EXISTS"
" FROM usr_data" "(SELECT *"
" WHERE FirstName='%s'" " FROM usr_data"
" OR Surname1='%s'" " WHERE FirstName='%s'"
" OR Surname2='%s'", " OR Surname1='%s'"
Str, " OR Surname2='%s')",
Str, Str,
Str) != 0); Str,
Str);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -363,11 +366,13 @@ void Usr_DB_MarkMyBirthdayAsCongratulated (void)
bool Usr_DB_CheckIfMyBirthdayHasNotBeenCongratulated (void) bool Usr_DB_CheckIfMyBirthdayHasNotBeenCongratulated (void)
{ {
return (DB_QueryCOUNT ("can not check if my birthday has been congratulated", return
"SELECT COUNT(*)" DB_QueryEXISTS ("can not check if my birthday has been congratulated",
" FROM usr_birthdays_today" "SELECT EXISTS"
" WHERE UsrCod=%ld", "(SELECT *"
Gbl.Usrs.Me.UsrDat.UsrCod) == 0); " FROM usr_birthdays_today"
" WHERE UsrCod=%ld)",
Gbl.Usrs.Me.UsrDat.UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -66,7 +66,7 @@ void Usr_DB_UpdateMyOfficePhone (void);
void Usr_DB_UpdateMyLastWhatToSearch (void); void Usr_DB_UpdateMyLastWhatToSearch (void);
bool Usr_DB_ChkIfUsrCodExists (long UsrCod); bool Usr_DB_ChkIfUsrCodExists (long UsrCod);
bool Usr_DB_ChkIfEncryptedUsrCodExists (const char EncryptedUsrCod[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64]); long Usr_DB_GetUsrCodFromEncryptedUsrCod (const char EncryptedUsrCod[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1]);
bool Usr_DB_FindStrInUsrsNames (const char *Str); bool Usr_DB_FindStrInUsrsNames (const char *Str);
unsigned Usr_DB_GetNumUsrsWhoChoseAnOption (const char *SubQuery); unsigned Usr_DB_GetNumUsrsWhoChoseAnOption (const char *SubQuery);
unsigned Usr_DB_GetOldUsrs (MYSQL_RES **mysql_res,time_t SecondsWithoutAccess); unsigned Usr_DB_GetOldUsrs (MYSQL_RES **mysql_res,time_t SecondsWithoutAccess);