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,10 +535,11 @@ 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"
"(SELECT *"
" FROM api_keys" " FROM api_keys"
" WHERE WSKey='%s'", " WHERE WSKey='%s')",
WSKey)) WSKey))
return soap_receiver_fault (soap, return soap_receiver_fault (soap,
"Error when generating key", "Error when generating key",
@ -769,10 +770,11 @@ 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"
"(SELECT *"
" FROM usr_nicknames" " FROM usr_nicknames"
" WHERE Nickname='%s'", // A nickname of another user is the same that this nickname " WHERE Nickname='%s')", // A nickname of another user is the same that this nickname
CopyOfNewNick)) // Already without leading arrobas 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;
@ -786,11 +788,12 @@ 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"
"(SELECT *"
" FROM usr_emails" " FROM usr_emails"
" WHERE E_mail='%s'" " WHERE E_mail='%s'"
" AND Confirmed='Y'", " AND Confirmed='Y')",
NewEmail)) // An email of another user is the same that my email 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;
} }
@ -6052,9 +6055,10 @@ 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 (SELECT DISTINCT deg_degrees.CtrCod"
" FROM crs_users," " FROM crs_users,"
"crs_courses," "crs_courses,"
"deg_degrees" "deg_degrees"
@ -6068,7 +6072,7 @@ int swad__getLastLocation (struct soap *soap,
" WHERE crs_users.UsrCod=%d" " WHERE crs_users.UsrCod=%d"
" AND crs_users.CrsCod=crs_courses.CrsCod" " AND crs_users.CrsCod=crs_courses.CrsCod"
" AND crs_courses.DegCod=deg_degrees.DegCod) AS C2" // centers of user's courses " AND crs_courses.DegCod=deg_degrees.DegCod) AS C2" // centers of user's courses
" WHERE C1.CtrCod=C2.CtrCod", " 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"
"(SELECT *"
" FROM usr_ids" " FROM usr_ids"
" WHERE UsrCod=%ld" " WHERE UsrCod=%ld"
" AND UsrID='%s'" " AND UsrID='%s'"
" AND Confirmed='Y'", " AND Confirmed='Y')",
UsrCod, UsrCod,
ID) != 0); 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",
"SELECT EXISTS"
"(SELECT *"
" FROM usr_ids" " FROM usr_ids"
" WHERE UsrID='%s'", " WHERE UsrID='%s')",
Str) != 0); Str);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -787,7 +787,7 @@ 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)

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",
"SELECT EXISTS"
"(SELECT *"
" FROM usr_nicknames" " FROM usr_nicknames"
" WHERE Nickname='%s'" " WHERE Nickname='%s'"
" AND UsrCod<>%ld", " AND UsrCod<>%ld)",
NewNickWithoutArr, NewNickWithoutArr,
Gbl.Usrs.Me.UsrDat.UsrCod) != 0); // A nickname of another user is the same that this nickname 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",
"SELECT EXISTS"
"(SELECT *"
" FROM usr_emails" " FROM usr_emails"
" WHERE E_mail='%s'" " WHERE E_mail='%s'"
" AND Confirmed='Y'", " AND Confirmed='Y')",
NewEmail) != 0); // An email of another user is the same that my email 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"
"(SELECT *"
" FROM usr_admins" " FROM usr_admins"
" WHERE UsrCod=%ld" " WHERE UsrCod=%ld"
" AND Scope='%s'" " AND Scope='%s'"
" AND Cod=%ld", " AND Cod=%ld)",
UsrCod, UsrCod,
Sco_GetDBStrFromScope (Scope), Sco_GetDBStrFromScope (Scope),
Cod) != 0); 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"
"(SELECT *"
" FROM asg_assignments" " FROM asg_assignments"
" WHERE CrsCod=%ld" " WHERE CrsCod=%ld"
" AND %s='%s'" " AND %s='%s'"
" AND AsgCod<>%ld", " AND AsgCod<>%ld)",
Gbl.Hierarchy.Crs.CrsCod, Gbl.Hierarchy.Crs.CrsCod,
Field,Value,AsgCod) != 0); Field,Value,
AsgCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -309,15 +311,16 @@ 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"
"(SELECT *"
" FROM asg_assignments" " FROM asg_assignments"
" WHERE AsgCod=%ld" " WHERE AsgCod=%ld"
" AND (" " AND ("
@ -333,9 +336,9 @@ bool Asg_DB_CheckIfICanDoAssignment (long AsgCod)
"asg_groups" "asg_groups"
" WHERE grp_users.UsrCod=%ld" " WHERE grp_users.UsrCod=%ld"
" AND asg_groups.GrpCod=grp_users.GrpCod)" " AND asg_groups.GrpCod=grp_users.GrpCod)"
")", "))",
AsgCod, AsgCod,
Gbl.Usrs.Me.UsrDat.UsrCod) != 0); 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"
"(SELECT *"
" FROM ban_banners" " FROM ban_banners"
" WHERE %s='%s'" " WHERE %s='%s'"
" AND BanCod<>%ld", " AND BanCod<>%ld)",
FieldName,Name, FieldName,Name,
BanCod) != 0); 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"
"(SELECT *"
" FROM brw_files" " FROM brw_files"
" WHERE FileBrowser=%u" " WHERE FileBrowser=%u"
" AND Cod=%ld" " AND Cod=%ld"
" AND ZoneUsrCod=%ld" " AND ZoneUsrCod=%ld"
" AND Path LIKE '%s/%%'" " AND Path LIKE '%s/%%'"
" AND Public='Y'", " AND Public='Y')",
(unsigned) Brw_DB_FileBrowserForDB_files[Gbl.FileBrowser.Type], (unsigned) Brw_DB_FileBrowserForDB_files[Gbl.FileBrowser.Type],
Cod, Cod,
ZoneUsrCod, ZoneUsrCod,
Path) != 0); Path);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2325,8 +2326,10 @@ 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",
"SELECT EXISTS"
"(SELECT *"
" FROM brw_files" " FROM brw_files"
" WHERE FileBrowser=%u" " WHERE FileBrowser=%u"
" AND Cod=%ld" " AND Cod=%ld"
@ -2334,12 +2337,12 @@ bool Brw_DB_CheckIfFileOrFolderIsSetAsHiddenUsingMetadata (const struct FileMeta
" AND Hidden='Y'" " AND Hidden='Y'"
" AND (Path='%s'" " AND (Path='%s'"
" OR" " OR"
" LOCATE(CONCAT(Path,'/'),'%s')=1)", " LOCATE(CONCAT(Path,'/'),'%s')=1))",
FileMetadata->FileBrowser, FileMetadata->FileBrowser,
FileMetadata->Cod, FileMetadata->Cod,
FileMetadata->ZoneUsrCod, FileMetadata->ZoneUsrCod,
FileMetadata->FilFolLnk.Full, FileMetadata->FilFolLnk.Full,
FileMetadata->FilFolLnk.Full) != 0); 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",
"SELECT EXISTS"
"(SELECT *"
" FROM brw_expanded" " FROM brw_expanded"
" WHERE UsrCod=%ld" " WHERE UsrCod=%ld"
" AND FileBrowser=%u" " AND FileBrowser=%u"
" AND Cod=%ld" " AND Cod=%ld"
" AND WorksUsrCod=%ld" " AND WorksUsrCod=%ld"
" AND Path='%s/'", " AND Path='%s/')",
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) FileBrowserForExpandedFolders, (unsigned) FileBrowserForExpandedFolders,
Cod, Cod,
WorksUsrCod, WorksUsrCod,
Path) != 0); 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",
"SELECT EXISTS"
"(SELECT *"
" FROM brw_expanded" " FROM brw_expanded"
" WHERE UsrCod=%ld" " WHERE UsrCod=%ld"
" AND FileBrowser=%u" " AND FileBrowser=%u"
" AND Cod=%ld" " AND Cod=%ld"
" AND Path='%s/'", " AND Path='%s/')",
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) FileBrowserForExpandedFolders, (unsigned) FileBrowserForExpandedFolders,
Cod, Cod,
Path) != 0); 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",
"SELECT EXISTS"
"(SELECT *"
" FROM brw_expanded" " FROM brw_expanded"
" WHERE UsrCod=%ld" " WHERE UsrCod=%ld"
" AND FileBrowser=%u" " AND FileBrowser=%u"
" AND Path='%s/'", " AND Path='%s/')",
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) FileBrowserForExpandedFolders, (unsigned) FileBrowserForExpandedFolders,
Path) != 0); 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 EXISTS"
"(SELECT *" "(SELECT *"
" FROM ctr_centers" " FROM ctr_centers"
" WHERE InsCod=%ld" " WHERE InsCod=%ld"
" AND (Latitude<>0" " AND (Latitude<>0"
" OR" " OR"
" Longitude<>0))", " Longitude<>0))",
InsCod)) 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,15 +504,12 @@ 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
DB_QueryEXISTS ("can not check if map is available",
"SELECT EXISTS" "SELECT EXISTS"
"(SELECT *" "(SELECT *"
" FROM ins_instits," " FROM ins_instits,"
@ -521,17 +518,7 @@ bool Cty_DB_GetIfMapIsAvailable (long CtyCod)
" AND ins_instits.InsCod=ctr_centers.InsCod" " AND ins_instits.InsCod=ctr_centers.InsCod"
" AND (ctr_centers.Latitude<>0" " AND (ctr_centers.Latitude<>0"
" OR ctr_centers.Longitude<>0))", " OR ctr_centers.Longitude<>0))",
CtyCod)) 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",
"SELECT EXISTS"
"(SELECT *"
" FROM crs_users," " FROM crs_users,"
"crs_courses" "crs_courses"
" WHERE crs_users.UsrCod=%ld" " WHERE crs_users.UsrCod=%ld"
" AND crs_users.Accepted='Y'" // Only if user accepted " AND crs_users.Accepted='Y'" // Only if user accepted
" AND crs_users.CrsCod=crs_courses.CrsCod" " AND crs_users.CrsCod=crs_courses.CrsCod"
" AND crs_courses.DegCod=%ld", " AND crs_courses.DegCod=%ld)",
UsrCod, UsrCod,
DegCod) != 0); 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"
"(SELECT *"
" FROM dpt_departments" " FROM dpt_departments"
" WHERE %s='%s'" " WHERE %s='%s'"
" AND DptCod<>%ld", " AND DptCod<>%ld)",
FieldName,Name, FieldName,Name,
DptCod) != 0); 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"
"(SELECT *"
" FROM usr_duplicated" " FROM usr_duplicated"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld)",
UsrCod) != 0); 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",
"SELECT EXISTS"
"(SELECT *"
" FROM crs_users" " FROM crs_users"
" WHERE CrsCod=%ld" " WHERE CrsCod=%ld"
" AND UsrCod=%ld" " AND UsrCod=%ld"
"%s", "%s)",
CrsCod, CrsCod,
UsrCod, UsrCod,
SubQuery) != 0); 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",
"SELECT EXISTS"
"(SELECT *"
" FROM crs_users" " FROM crs_users"
" WHERE UsrCod=%ld" " WHERE UsrCod=%ld"
" AND CrsCod IN" " AND CrsCod IN"
" (SELECT CrsCod" " (SELECT CrsCod"
" FROM my_courses_tmp)", " FROM my_courses_tmp))",
UsrCod) != 0); 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"
"(SELECT *"
" FROM my_courses_tmp," " FROM my_courses_tmp,"
"usr_courses_tmp" "usr_courses_tmp"
" WHERE my_courses_tmp.CrsCod=usr_courses_tmp.CrsCod" " WHERE my_courses_tmp.CrsCod=usr_courses_tmp.CrsCod"
" AND my_courses_tmp.Role<>usr_courses_tmp.Role") != 0); " 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",
"SELECT EXISTS"
"(SELECT *"
" FROM exa_exams" " FROM exa_exams"
" WHERE CrsCod=%ld" " WHERE CrsCod=%ld"
" AND Title='%s'" " AND Title='%s'"
" AND ExaCod<>%ld", " AND ExaCod<>%ld)",
CrsCod, CrsCod,
Title, Title,
ExaCod) != 0); 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"
"(SELECT *"
" FROM exa_sets," " FROM exa_sets,"
"exa_exams" "exa_exams"
" WHERE exa_sets.ExaCod=%ld" " WHERE exa_sets.ExaCod=%ld"
" AND exa_sets.Title='%s'" " AND exa_sets.Title='%s'"
" AND exa_sets.SetCod<>%ld" " AND exa_sets.SetCod<>%ld"
" AND exa_sets.ExaCod=exa_exams.ExaCod" " AND exa_sets.ExaCod=exa_exams.ExaCod"
" AND exa_exams.CrsCod=%ld", // Extra check " AND exa_exams.CrsCod=%ld)", // Extra check
Set->ExaCod,Title, Set->ExaCod,Title,
Set->SetCod, Set->SetCod,
Gbl.Hierarchy.Crs.CrsCod) != 0); Gbl.Hierarchy.Crs.CrsCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1668,8 +1671,10 @@ 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",
"SELECT EXISTS"
"(SELECT *"
" FROM exa_sessions" " FROM exa_sessions"
" WHERE SesCod=%ld" " WHERE SesCod=%ld"
" AND (SesCod NOT IN" " AND (SesCod NOT IN"
@ -1680,9 +1685,9 @@ bool Exa_DB_CheckIfICanListThisSessionBasedOnGrps (long 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",
"SELECT EXISTS"
"(SELECT *"
" FROM usr_follow" " FROM usr_follow"
" WHERE FollowerCod=%ld" " WHERE FollowerCod=%ld"
" AND FollowedCod=%ld", " AND FollowedCod=%ld)",
FollowerCod,FollowedCod) != 0); 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",
"SELECT EXISTS"
"(SELECT *"
" FROM for_posts" " FROM for_posts"
" WHERE PstCod=%ld", " WHERE PstCod=%ld)",
PstCod) != 0); // Post exists if it appears in table of forum posts 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",
"SELECT EXISTS"
"(SELECT *"
" FROM for_threads" " FROM for_threads"
" WHERE ThrCod=%ld" " WHERE ThrCod=%ld"
" AND ForumType=%u" " AND ForumType=%u"
"%s", "%s)",
ThrCod, ThrCod,
(unsigned) Forum->Type, (unsigned) Forum->Type,
SubQuery) != 0); 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",
"SELECT EXISTS"
"(SELECT *"
" FROM for_disabled" " FROM for_disabled"
" WHERE PstCod=%ld", " WHERE PstCod=%ld)",
PstCod) == 0); // Post is enabled if it does not appear in table of disabled posts 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",
"SELECT EXISTS"
"(SELECT *"
" FROM gam_games" " FROM gam_games"
" WHERE CrsCod=%ld" " WHERE CrsCod=%ld"
" AND Title='%s'" " AND Title='%s'"
" AND GamCod<>%ld", " AND GamCod<>%ld)",
Gbl.Hierarchy.Crs.CrsCod, Gbl.Hierarchy.Crs.CrsCod,
Game->Title, Game->Title,
Game->GamCod) != 0); 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",
"SELECT EXISTS"
"(SELECT *"
" FROM grp_groups" " FROM grp_groups"
" WHERE GrpCod=%ld", " WHERE GrpCod=%ld)",
GrpCod) != 0); 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"
"(SELECT *"
" FROM grp_groups," " FROM grp_groups,"
"grp_types" "grp_types"
" WHERE grp_groups.GrpCod=%ld" " WHERE grp_groups.GrpCod=%ld"
" AND grp_groups.GrpTypCod=grp_types.GrpTypCod" " AND grp_groups.GrpTypCod=grp_types.GrpTypCod"
" AND grp_types.CrsCod=%ld", " AND grp_types.CrsCod=%ld)",
GrpCod,CrsCod) != 0); 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"
"(SELECT *"
" FROM grp_groups" " FROM grp_groups"
" WHERE GrpTypCod=%ld" " WHERE GrpTypCod=%ld"
" AND GrpName='%s'" " AND GrpName='%s'"
" AND GrpCod<>%ld", " AND GrpCod<>%ld)",
GrpTypCod, GrpTypCod,
GrpName, GrpName,
GrpCod) != 0); 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",
"SELECT EXISTS"
"(SELECT *"
" FROM grp_groups," " FROM grp_groups,"
"grp_users" "grp_users"
" WHERE grp_groups.GrpTypCod=%ld" " WHERE grp_groups.GrpTypCod=%ld"
" AND grp_groups.GrpCod=grp_users.GrpCod" " AND grp_groups.GrpCod=grp_users.GrpCod"
" AND grp_users.UsrCod=%ld", // I belong " AND grp_users.UsrCod=%ld)", // I belong
GrpTypCod, GrpTypCod,
Gbl.Usrs.Me.UsrDat.UsrCod) != 0); Gbl.Usrs.Me.UsrDat.UsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -389,25 +395,27 @@ 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",
"SELECT EXISTS"
"(SELECT *"
" FROM grp_users" " FROM grp_users"
" WHERE GrpCod=%ld" " WHERE GrpCod=%ld"
" AND UsrCod=%ld", // I belong " AND UsrCod=%ld)", // I belong
GrpCod, GrpCod,
Gbl.Usrs.Me.UsrDat.UsrCod) != 0); 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"
@ -418,10 +426,10 @@ unsigned Grp_DB_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (long UsrCod)
" 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",
"SELECT EXISTS"
"(SELECT *"
" FROM %s" " FROM %s"
" WHERE %s=%ld" " WHERE %s=%ld"
" AND GrpCod=%ld", " AND GrpCod=%ld)",
Table, Table,
Field,Cod, Field,Cod,
GrpCod) != 0); 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",
"SELECT EXISTS"
"(SELECT *"
" FROM %s" " FROM %s"
" WHERE %s=%ld", " WHERE %s=%ld)",
Table, Table,
Field,Cod) != 0); 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",
"SELECT EXISTS"
"(SELECT *"
" FROM crs_info_read" " FROM crs_info_read"
" WHERE UsrCod=%ld" " WHERE UsrCod=%ld"
" AND CrsCod=%ld" " AND CrsCod=%ld"
" AND InfoType='%s'", " AND InfoType='%s')",
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Hierarchy.Crs.CrsCod, Gbl.Hierarchy.Crs.CrsCod,
Inf_DB_NamesForInfoType[Gbl.Crs.Info.Type]) != 0); 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"
"(SELECT *"
" FROM ins_instits" " FROM ins_instits"
" WHERE CtyCod=%ld" " WHERE CtyCod=%ld"
" AND %s='%s'" " AND %s='%s'"
" AND InsCod<>%ld", " AND InsCod<>%ld)",
CtyCod,FieldName,Name,InsCod) != 0); 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"
"(SELECT *"
" FROM lnk_links" " FROM lnk_links"
" WHERE %s='%s'" " WHERE %s='%s'"
" AND LnkCod<>%ld", " AND LnkCod<>%ld)",
FieldName,Name, FieldName,Name,
LnkCod) != 0); 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",
"SELECT EXISTS"
"(SELECT *"
" FROM usr_emails" " FROM usr_emails"
" WHERE E_mail='%s'" " WHERE E_mail='%s'"
" AND Confirmed='Y'" " AND Confirmed='Y'"
" AND UsrCod<>%ld", " AND UsrCod<>%ld)",
Email, Email,
UsrCod) != 0); 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,8 +493,10 @@ 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",
"SELECT EXISTS"
"(SELECT *"
" FROM mch_matches" " FROM mch_matches"
" WHERE MchCod=%ld" " WHERE MchCod=%ld"
" AND (MchCod NOT IN" " AND (MchCod NOT IN"
@ -506,9 +508,9 @@ bool Mch_DB_CheckIfICanPlayThisMatchBasedOnGrps (long MchCod)
" FROM grp_users," " FROM grp_users,"
"mch_groups" "mch_groups"
" WHERE grp_users.UsrCod=%ld" " WHERE grp_users.UsrCod=%ld"
" AND grp_users.GrpCod=mch_groups.GrpCod))", " AND grp_users.GrpCod=mch_groups.GrpCod)))",
MchCod, MchCod,
Gbl.Usrs.Me.UsrDat.UsrCod) != 0); 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",
"SELECT EXISTS"
"(SELECT *"
" FROM mch_playing" " FROM mch_playing"
" WHERE MchCod=%ld", " WHERE MchCod=%ld)",
MchCod) != 0); 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",
"SELECT EXISTS"
"(SELECT *"
" FROM mch_results" " FROM mch_results"
" WHERE MchCod=%ld" " WHERE MchCod=%ld"
" AND UsrCod=%ld", " AND UsrCod=%ld)",
Print->MchCod, Print->MchCod,
Print->UsrCod) != 0); 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,11 +773,13 @@ 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",
"SELECT EXISTS"
"(SELECT *"
" FROM msg_snt" " FROM msg_snt"
" WHERE MsgCod=%ld", " WHERE MsgCod=%ld)",
MsgCod) == 0); // The message has been deleted MsgCod); // The message has been deleted
// by its author when it is not present // by its author when it is not present
// in table of sent messages undeleted // in table of sent messages undeleted
} }
@ -788,12 +790,13 @@ 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"
"(SELECT *"
" FROM msg_rcv" " FROM msg_rcv"
" WHERE MsgCod=%ld", " WHERE MsgCod=%ld)",
MsgCod) == 0); // The message has been deleted MsgCod); // The message has been deleted
// by all its recipients when it is not present // by all its recipients when it is not present
// in table of received messages undeleted // 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"
"(SELECT *"
" FROM msg_banned" " FROM msg_banned"
" WHERE FromUsrCod=%ld" " WHERE FromUsrCod=%ld"
" AND ToUsrCod=%ld", " AND ToUsrCod=%ld)",
FromUsrCod,ToUsrCod) != 0); 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",
"SELECT EXISTS"
"(SELECT *"
" FROM usr_nicknames" " FROM usr_nicknames"
" WHERE UsrCod=%ld" " WHERE UsrCod=%ld"
" AND Nickname='%s'", " AND Nickname='%s')",
UsrCod, UsrCod,
NickWithoutArr) != 0); 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",
"SELECT EXISTS"
"(SELECT *"
" FROM usr_nicknames" " FROM usr_nicknames"
" WHERE Nickname='%s'" " WHERE Nickname='%s'"
" AND UsrCod<>%ld", " AND UsrCod<>%ld)",
NickWithoutArr, NickWithoutArr,
UsrCod) != 0); // A nickname of another user is the same that user's nickname 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"
"(SELECT *"
" FROM plc_places" " FROM plc_places"
" WHERE InsCod=%ld" " WHERE InsCod=%ld"
" AND %s='%s'" " AND %s='%s'"
" AND PlcCod<>%ld", " AND PlcCod<>%ld)",
Gbl.Hierarchy.Ins.InsCod, Gbl.Hierarchy.Ins.InsCod,
FieldName,Name, FieldName,Name,
PlcCod) != 0); 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"
"(SELECT *"
" FROM ses_sessions" " FROM ses_sessions"
" WHERE SessionId='%s'", " WHERE SessionId='%s')",
IdSes) != 0); 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"
"(SELECT *"
" FROM ses_params" " FROM ses_params"
" WHERE SessionId='%s'" " WHERE SessionId='%s'"
" AND ParamName='%s'", " AND ParamName='%s')",
Gbl.Session.Id, Gbl.Session.Id,
ParamName) != 0); 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"
"(SELECT *"
" FROM svy_surveys" " FROM svy_surveys"
" WHERE Scope='%s'" " WHERE Scope='%s'"
" AND Cod=%ld" " AND Cod=%ld"
" AND Title='%s'" " AND Title='%s'"
" AND SvyCod<>%ld", " AND SvyCod<>%ld)",
Sco_GetDBStrFromScope (Svy->Scope), Sco_GetDBStrFromScope (Svy->Scope),
Svy->Cod, Svy->Cod,
Svy->Title, Svy->Title,
Svy->SvyCod) != 0); Svy->SvyCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -749,8 +750,10 @@ 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",
"SELECT EXISTS"
"(SELECT *"
" FROM svy_surveys" " FROM svy_surveys"
" WHERE SvyCod=%ld" " WHERE SvyCod=%ld"
" AND (SvyCod NOT IN" " AND (SvyCod NOT IN"
@ -762,9 +765,9 @@ bool Svy_DB_CheckIfICanDoThisSurveyBasedOnGrps (long SvyCod)
" FROM grp_users," " FROM grp_users,"
"svy_groups" "svy_groups"
" WHERE grp_users.UsrCod=%ld" " WHERE grp_users.UsrCod=%ld"
" AND grp_users.GrpCod=svy_groups.GrpCod))", " AND grp_users.GrpCod=svy_groups.GrpCod)))",
SvyCod, SvyCod,
Gbl.Usrs.Me.UsrDat.UsrCod) != 0); 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",
"SELECT EXISTS"
"(SELECT *"
" FROM svy_answers" " FROM svy_answers"
" WHERE QstCod=%ld" " WHERE QstCod=%ld"
" AND AnsInd=%u", " AND AnsInd=%u)",
QstCod, QstCod,
AnsInd) != 0); 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",
"SELECT EXISTS"
"(SELECT *"
" FROM svy_users" " FROM svy_users"
" WHERE SvyCod=%ld" " WHERE SvyCod=%ld"
" AND UsrCod=%ld", " AND UsrCod=%ld)",
SvyCod, SvyCod,
Gbl.Usrs.Me.UsrDat.UsrCod) != 0); 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"
"(SELECT *"
" FROM tst_tags" " FROM tst_tags"
" WHERE CrsCod=%ld", " WHERE CrsCod=%ld)",
Gbl.Hierarchy.Crs.CrsCod) != 0); 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",
"SELECT EXISTS"
"(SELECT *"
" FROM %s" " FROM %s"
" WHERE %s=%ld" " WHERE %s=%ld"
" AND UsrCod=%ld", " AND UsrCod=%ld)",
Tml_DB_TableFav[FavSha], Tml_DB_TableFav[FavSha],
Tml_DB_FieldFav[FavSha],Cod,UsrCod) != 0); 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",
"SELECT EXISTS"
"(SELECT *"
" FROM tml_pubs" " FROM tml_pubs"
" WHERE NotCod=%ld" " WHERE NotCod=%ld"
" AND PublisherCod=%ld" " AND PublisherCod=%ld"
" AND PubType=%u", " AND PubType=%u)",
NotCod, NotCod,
UsrCod, UsrCod,
(unsigned) Tml_Pub_SHARED_NOTE) != 0); (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"
"(SELECT *"
" FROM usr_admins" " FROM usr_admins"
" WHERE UsrCod=%ld" " WHERE UsrCod=%ld"
" AND Scope='%s'", " AND Scope='%s')",
UsrCod, UsrCod,
Sco_GetDBStrFromScope (HieLvl_SYS)) != 0); Sco_GetDBStrFromScope (HieLvl_SYS));
return Gbl.Cache.UsrIsSuperuser.IsSuperuser; return Gbl.Cache.UsrIsSuperuser.IsSuperuser;
} }
@ -2306,10 +2290,11 @@ 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"
"(SELECT *"
" FROM usr_last" " FROM usr_last"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld)",
Gbl.Usrs.Me.UsrDat.UsrCod)) 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

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",
"SELECT EXISTS"
"(SELECT *"
" FROM usr_data" " FROM usr_data"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld)",
UsrCod) != 0); 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) != 0); EncryptedUsrCod);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -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"
"(SELECT *"
" FROM usr_data" " FROM usr_data"
" WHERE FirstName='%s'" " WHERE FirstName='%s'"
" OR Surname1='%s'" " OR Surname1='%s'"
" OR Surname2='%s'", " OR Surname2='%s')",
Str, Str,
Str, Str,
Str) != 0); 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",
"SELECT EXISTS"
"(SELECT *"
" FROM usr_birthdays_today" " FROM usr_birthdays_today"
" WHERE UsrCod=%ld", " WHERE UsrCod=%ld)",
Gbl.Usrs.Me.UsrDat.UsrCod) == 0); 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);