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

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

View File

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

View File

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

View File

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

View File

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

View File

@ -349,7 +349,6 @@ void Agd_DB_RemoveUsrEvents (long UsrCod)
unsigned Agd_DB_GetNumEventsFromUsr (long UsrCod)
{
/***** Get number of events in a course from database *****/
return (unsigned)
DB_QueryCOUNT ("can not get number of events from user",
"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,
long AsgCod)
{
/***** Get number of assignments with a field value from database *****/
return (DB_QueryCOUNT ("can not get similar assignments",
"SELECT COUNT(*)"
" FROM asg_assignments"
" WHERE CrsCod=%ld"
" AND %s='%s'"
" AND AsgCod<>%ld",
Gbl.Hierarchy.Crs.CrsCod,
Field,Value,AsgCod) != 0);
return
DB_QueryEXISTS ("can not check if similar assignments exist",
"SELECT EXISTS"
"(SELECT *"
" FROM asg_assignments"
" WHERE CrsCod=%ld"
" AND %s='%s'"
" AND AsgCod<>%ld)",
Gbl.Hierarchy.Crs.CrsCod,
Field,Value,
AsgCod);
}
/*****************************************************************************/
@ -309,33 +311,34 @@ void Asg_DB_RemoveAssignment (long AsgCod)
}
/*****************************************************************************/
/******************* Get groups associated to an assignment ******************/
/********************* Check if I can do an assignment ***********************/
/*****************************************************************************/
bool Asg_DB_CheckIfICanDoAssignment (long AsgCod)
{
// Students and teachers can do assignments depending on groups
/***** Get if I can do an assignment from database *****/
return (DB_QueryCOUNT ("can not check if I can do an assignment",
"SELECT COUNT(*)"
" FROM asg_assignments"
" WHERE AsgCod=%ld"
" AND ("
// Assignment is for the whole course
"AsgCod NOT IN"
" (SELECT AsgCod"
" FROM asg_groups)"
" OR "
// Assignment is for some of my groups
"AsgCod IN"
" (SELECT asg_groups.AsgCod"
" FROM grp_users,"
"asg_groups"
" WHERE grp_users.UsrCod=%ld"
" AND asg_groups.GrpCod=grp_users.GrpCod)"
")",
AsgCod,
Gbl.Usrs.Me.UsrDat.UsrCod) != 0);
return
DB_QueryEXISTS ("can not check if I can do an assignment",
"SELECT EXISTS"
"(SELECT *"
" FROM asg_assignments"
" WHERE AsgCod=%ld"
" AND ("
// Assignment is for the whole course
"AsgCod NOT IN"
" (SELECT AsgCod"
" FROM asg_groups)"
" OR "
// Assignment is for some of my groups
"AsgCod IN"
" (SELECT asg_groups.AsgCod"
" FROM grp_users,"
"asg_groups"
" WHERE grp_users.UsrCod=%ld"
" AND asg_groups.GrpCod=grp_users.GrpCod)"
"))",
AsgCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/
@ -568,7 +571,7 @@ unsigned Asg_DB_GetNumCoursesWithAssignments (HieLvl_Level_t Scope)
Gbl.Hierarchy.Crs.CrsCod);
default:
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)
{
/***** Get number of attendance events
with a field value from database *****/
return (DB_QueryCOUNT ("can not get similar attendance events",
"SELECT COUNT(*)"
" FROM att_events"
" WHERE CrsCod=%ld"
" AND %s='%s'"
" AND AttCod<>%ld",
Gbl.Hierarchy.Crs.CrsCod,
Field,Value,
AttCod) != 0);
return
DB_QueryEXISTS ("can not check similar attendance events",
"SELECT EXISTS"
"(SELECT *"
" FROM att_events"
" WHERE CrsCod=%ld"
" AND %s='%s'"
" AND AttCod<>%ld)",
Gbl.Hierarchy.Crs.CrsCod,
Field,Value,
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)
{
/***** Get number of banners with a name from database *****/
return (DB_QueryCOUNT ("can not check if the name of a banner already existed",
"SELECT COUNT(*)"
" FROM ban_banners"
" WHERE %s='%s'"
" AND BanCod<>%ld",
FieldName,Name,
BanCod) != 0);
return
DB_QueryEXISTS ("can not check if the name of a banner already existed",
"SELECT EXISTS"
"(SELECT *"
" FROM ban_banners"
" WHERE %s='%s'"
" AND BanCod<>%ld)",
FieldName,Name,
BanCod);
}
/*****************************************************************************/

View File

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

View File

@ -134,16 +134,17 @@ unsigned Bld_DB_GetDataOfBuildingByCod (MYSQL_RES **mysql_res,long BldCod)
bool Bld_DB_CheckIfBuildingNameExists (const char *FieldName,const char *Name,long BldCod)
{
/***** Get number of buildings with a name from database *****/
return (DB_QueryCOUNT ("can not check if the name of a building"
" already existed",
"SELECT COUNT(*)"
" FROM bld_buildings"
" WHERE CtrCod=%ld"
" AND %s='%s'"
" AND BldCod<>%ld",
Gbl.Hierarchy.Ctr.CtrCod,
FieldName,Name,BldCod) != 0);
return
DB_QueryEXISTS ("can not check if the name of a building already existed",
"SELECT EXISTS"
"(SELECT *"
" FROM bld_buildings"
" WHERE CtrCod=%ld"
" AND %s='%s'"
" AND BldCod<>%ld)",
Gbl.Hierarchy.Ctr.CtrCod,
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,
long CtrCod,long InsCod)
{
/***** Get number of centers with a name from database *****/
return (DB_QueryCOUNT ("can not check if the name of a center"
" already existed",
"SELECT COUNT(*)"
" FROM ctr_centers"
" WHERE InsCod=%ld"
" AND %s='%s'"
" AND CtrCod<>%ld",
InsCod,
FieldName,
Name,
CtrCod) != 0);
return
DB_QueryEXISTS ("can not check if the name of a center already existed",
"SELECT EXISTS"
"(SELECT *"
" FROM ctr_centers"
" WHERE InsCod=%ld"
" AND %s='%s'"
" AND CtrCod<>%ld)",
InsCod,
FieldName,
Name,
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 ************/
/*****************************************************************************/
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
(coordinates 0, 0 means not set ==> don't show map) *****/
if (DB_QuerySELECT (&mysql_res,"can not get if map is available",
"SELECT EXISTS" // row[0]
"(SELECT *"
" FROM ctr_centers"
" WHERE InsCod=%ld"
" AND (Latitude<>0"
" OR"
" Longitude<>0))",
InsCod))
{
/* Get if map is available */
row = mysql_fetch_row (mysql_res);
MapIsAvailable = (row[0][0] == '1');
}
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
return MapIsAvailable;
return
DB_QueryEXISTS ("can not check if map is available",
"SELECT EXISTS"
"(SELECT *"
" FROM ctr_centers"
" WHERE InsCod=%ld"
" AND (Latitude<>0"
" OR"
" Longitude<>0))",
InsCod);
}
/*****************************************************************************/

View File

@ -81,7 +81,7 @@ void Ctr_DB_UpdateCtrCoordinate (long CtrCod,
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_GetCoordAndZoomInCurrentIns (struct Map_Coordinates *Coord,unsigned *Zoom);
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.
*/
#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 JS_FILE "swad20.69.1.js"
/*
TODO: Rename CENTRE to CENTER in help wiki.
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.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)

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)
{
/***** Get number of connected users with a role from database *****/
return (unsigned)
DB_QueryCOUNT ("can not get number of connected users",
"SELECT COUNT(*)"

View File

@ -1879,7 +1879,7 @@ static void Cty_FormToGoToMap (struct Cty_Countr *Cty)
{
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
Lay_PutContextualLinkOnlyIcon (ActSeeCtyInf,NULL,

View File

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

View File

@ -69,7 +69,7 @@ unsigned Cty_DB_SearchCtys (MYSQL_RES **mysql_res,
void Cty_DB_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom);
unsigned Cty_DB_GetCtrsWithCoordsInCurrentCty (MYSQL_RES **mysql_res);
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_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,
long DegCod,unsigned Year)
{
/***** Get number of courses in a year of a degree and with a name from database *****/
return (DB_QueryCOUNT ("can not check if the name"
" of a course already existed",
"SELECT COUNT(*)"
" FROM crs_courses"
" WHERE DegCod=%ld"
" AND Year=%u"
" AND %s='%s'"
" AND CrsCod<>%ld",
DegCod,
Year,
FieldName,
Name,
CrsCod) != 0);
return
DB_QueryEXISTS ("can not check if the name of a course already existed",
"SELECT EXISTS"
"(SELECT *"
" FROM crs_courses"
" WHERE DegCod=%ld"
" AND Year=%u"
" AND %s='%s'"
" AND CrsCod<>%ld)",
DegCod,
Year,
FieldName,
Name,
CrsCod);
}
/*****************************************************************************/

View File

@ -4077,6 +4077,34 @@ unsigned long DB_QueryCOUNT (const char *MsgError,const char *fmt,...)
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 ***********************/
/*****************************************************************************/

View File

@ -57,6 +57,7 @@ void DB_QuerySELECTString (char *Str,size_t StrSize,const char *MsgError,
long DB_GetNextCode (MYSQL_RES *mysql_res);
unsigned long DB_GetNumRowsTable (const char *Table);
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,...);

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

View File

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

View File

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

View File

@ -152,15 +152,17 @@ bool Enr_DB_CheckIfUsrBelongsToCrs (long UsrCod,long CrsCod,
const char *SubQuery = (CountOnlyAcceptedCourses ? " AND crs_users.Accepted='Y'" : // Only if user accepted
"");
return (DB_QueryCOUNT ("can not check if a user belongs to a course",
"SELECT COUNT(*)"
" FROM crs_users"
" WHERE CrsCod=%ld"
" AND UsrCod=%ld"
"%s",
CrsCod,
UsrCod,
SubQuery) != 0);
return
DB_QueryEXISTS ("can not check if a user belongs to a course",
"SELECT EXISTS"
"(SELECT *"
" FROM crs_users"
" WHERE CrsCod=%ld"
" AND UsrCod=%ld"
"%s)",
CrsCod,
UsrCod,
SubQuery);
}
/*****************************************************************************/
@ -173,14 +175,16 @@ bool Enr_DB_CheckIfUsrSharesAnyOfMyCrs (long UsrCod)
Enr_GetMyCourses ();
/* Check if user shares any course with me */
return (DB_QueryCOUNT ("can not check if a user shares any course with you",
"SELECT COUNT(*)"
" FROM crs_users"
" WHERE UsrCod=%ld"
" AND CrsCod IN"
" (SELECT CrsCod"
" FROM my_courses_tmp)",
UsrCod) != 0);
return
DB_QueryEXISTS ("can not check if a user shares any course with you",
"SELECT EXISTS"
"(SELECT *"
" FROM crs_users"
" WHERE UsrCod=%ld"
" AND CrsCod IN"
" (SELECT CrsCod"
" FROM my_courses_tmp))",
UsrCod);
}
/*****************************************************************************/
@ -217,12 +221,13 @@ bool Enr_DB_CheckIfUsrSharesAnyOfMyCrsWithDifferentRole (long UsrCod)
/* Get if a user shares any course with me from database */
UsrSharesAnyOfMyCrsWithDifferentRole =
(DB_QueryCOUNT ("can not check if a user shares any course with you",
"SELECT COUNT(*)"
" FROM my_courses_tmp,"
"usr_courses_tmp"
" WHERE my_courses_tmp.CrsCod=usr_courses_tmp.CrsCod"
" AND my_courses_tmp.Role<>usr_courses_tmp.Role") != 0);
DB_QueryEXISTS ("can not check if a user shares any course with you",
"SELECT EXISTS"
"(SELECT *"
" FROM my_courses_tmp,"
"usr_courses_tmp"
" WHERE my_courses_tmp.CrsCod=usr_courses_tmp.CrsCod"
" AND my_courses_tmp.Role<>usr_courses_tmp.Role)");
/* Remove temporary table if exists */
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)
{
return (DB_QueryCOUNT ("can not get similar exams",
"SELECT COUNT(*)"
" FROM exa_exams"
" WHERE CrsCod=%ld"
" AND Title='%s'"
" AND ExaCod<>%ld",
CrsCod,
Title,
ExaCod) != 0);
return
DB_QueryEXISTS ("can not check similar exams",
"SELECT EXISTS"
"(SELECT *"
" FROM exa_exams"
" WHERE CrsCod=%ld"
" AND Title='%s'"
" AND ExaCod<>%ld)",
CrsCod,
Title,
ExaCod);
}
/*****************************************************************************/
@ -708,19 +710,20 @@ unsigned Exa_DB_GetDataOfSetByCod (MYSQL_RES **mysql_res,long SetCod)
bool Exa_DB_CheckIfSimilarSetExists (const struct ExaSet_Set *Set,
const char Title[ExaSet_MAX_BYTES_TITLE + 1])
{
/***** Get number of set of questions with a field value from database *****/
return (DB_QueryCOUNT ("can not get similar sets of questions",
"SELECT COUNT(*)"
" FROM exa_sets,"
"exa_exams"
" WHERE exa_sets.ExaCod=%ld"
" AND exa_sets.Title='%s'"
" AND exa_sets.SetCod<>%ld"
" AND exa_sets.ExaCod=exa_exams.ExaCod"
" AND exa_exams.CrsCod=%ld", // Extra check
Set->ExaCod,Title,
Set->SetCod,
Gbl.Hierarchy.Crs.CrsCod) != 0);
return
DB_QueryEXISTS ("can not check similar sets of questions",
"SELECT EXISTS"
"(SELECT *"
" FROM exa_sets,"
"exa_exams"
" WHERE exa_sets.ExaCod=%ld"
" AND exa_sets.Title='%s'"
" AND exa_sets.SetCod<>%ld"
" AND exa_sets.ExaCod=exa_exams.ExaCod"
" AND exa_exams.CrsCod=%ld)", // Extra check
Set->ExaCod,Title,
Set->SetCod,
Gbl.Hierarchy.Crs.CrsCod);
}
/*****************************************************************************/
@ -1668,21 +1671,23 @@ unsigned Exa_DB_GetGrpsAssociatedToSes (MYSQL_RES **mysql_res,long SesCod)
bool Exa_DB_CheckIfICanListThisSessionBasedOnGrps (long SesCod)
{
return (DB_QueryCOUNT ("can not check if I can play an exam session",
"SELECT COUNT(*)"
" FROM exa_sessions"
" WHERE SesCod=%ld"
" AND (SesCod NOT IN"
" (SELECT SesCod FROM exa_groups)"
return
DB_QueryEXISTS ("can not check if I can play an exam session",
"SELECT EXISTS"
"(SELECT *"
" FROM exa_sessions"
" WHERE SesCod=%ld"
" AND (SesCod NOT IN"
" (SELECT SesCod FROM exa_groups)"
" OR"
" SesCod IN"
" (SELECT exa_groups.SesCod"
" FROM exa_groups,"
"grp_users"
" WHERE grp_users.UsrCod=%ld"
" AND grp_users.GrpCod=exa_groups.GrpCod))",
SesCod,
Gbl.Usrs.Me.UsrDat.UsrCod) != 0);
" SesCod IN"
" (SELECT exa_groups.SesCod"
" FROM exa_groups,"
"grp_users"
" WHERE grp_users.UsrCod=%ld"
" AND grp_users.GrpCod=exa_groups.GrpCod)))",
SesCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/
@ -2106,18 +2111,18 @@ void Exa_DB_RemovePrintQstsFromCrs (long CrsCod)
bool Exa_DB_CheckIfSessionIsTheSameAsTheLast (long PrnCod)
{
/***** Check if the current session id
is the same as the last one stored in database *****/
return (DB_QueryCOUNT ("can not check session",
"SELECT COUNT(*)"
" FROM exa_log_sessions"
" WHERE LogCod="
"(SELECT MAX(LogCod)"
" FROM exa_log_sessions"
" WHERE PrnCod=%ld)"
" AND SessionId='%s'",
PrnCod,
Gbl.Session.Id) != 0);
return
DB_QueryEXISTS ("can not check session",
"SELECT EXISTS"
"(SELECT *"
" FROM exa_log_sessions"
" WHERE LogCod="
"(SELECT MAX(LogCod)"
" FROM exa_log_sessions"
" WHERE PrnCod=%ld)"
" AND SessionId='%s')",
PrnCod,
Gbl.Session.Id);
}
/*****************************************************************************/
@ -2126,18 +2131,18 @@ bool Exa_DB_CheckIfSessionIsTheSameAsTheLast (long PrnCod)
bool Exa_DB_CheckIfUserAgentIsTheSameAsTheLast (long PrnCod,const char *UserAgentDB)
{
/***** Get if the current user agent
is the same as the last stored in database *****/
return (DB_QueryCOUNT ("can not check user agent",
"SELECT COUNT(*)"
" FROM exa_log_user_agents"
" WHERE LogCod="
"(SELECT MAX(LogCod)"
" FROM exa_log_user_agents"
" WHERE PrnCod=%ld)"
" AND UserAgent='%s'",
PrnCod,
UserAgentDB) != 0);
return
DB_QueryEXISTS ("can not check user agent",
"SELECT EXISTS"
"(SELECT *"
" FROM exa_log_user_agents"
" WHERE LogCod="
"(SELECT MAX(LogCod)"
" FROM exa_log_user_agents"
" WHERE PrnCod=%ld)"
" AND UserAgent='%s')",
PrnCod,
UserAgentDB);
}
/*****************************************************************************/

View File

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

View File

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

View File

@ -51,7 +51,7 @@ long For_DB_InsertForumPst (long ThrCod,long UsrCod,
long MedCod);
void For_DB_UpdateNumUsrsNotifiedByEMailAboutPost (long PstCod,
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_GetPstSubjectAndContent (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)
{
return (DB_QueryCOUNT ("can not get similar games",
"SELECT COUNT(*)"
" FROM gam_games"
" WHERE CrsCod=%ld"
" AND Title='%s'"
" AND GamCod<>%ld",
Gbl.Hierarchy.Crs.CrsCod,
Game->Title,
Game->GamCod) != 0);
return
DB_QueryEXISTS ("can not check similar games",
"SELECT EXISTS"
"(SELECT *"
" FROM gam_games"
" WHERE CrsCod=%ld"
" AND Title='%s'"
" AND GamCod<>%ld)",
Gbl.Hierarchy.Crs.CrsCod,
Game->Title,
Game->GamCod);
}
/*****************************************************************************/

View File

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

View File

@ -65,7 +65,7 @@ unsigned Grp_DB_GetTchsFromCurrentGrpExceptMe (MYSQL_RES **mysql_res);
bool Grp_DB_CheckIfIBelongToGrpsOfType (long GrpTypCod);
bool Grp_DB_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_GetAllGrpTypesInCurrentCrs (MYSQL_RES **mysql_res);

View File

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

View File

@ -1973,7 +1973,7 @@ static void Ins_FormToGoToMap (struct Ins_Instit *Ins)
{
extern const char *Txt_Map;
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
Lay_PutContextualLinkOnlyIcon (ActSeeInsInf,NULL,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -441,26 +441,9 @@ bool Usr_ItsMe (long UsrCod)
void Usr_GetUsrCodFromEncryptedUsrCod (struct UsrData *UsrDat)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
if (UsrDat->EnUsrCod[0])
{
/***** Get user's code from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get user's code",
"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);
}
UsrDat->UsrCod = Usr_DB_GetUsrCodFromEncryptedUsrCod (UsrDat->EnUsrCod);
else
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 *****/
Gbl.Cache.UsrIsSuperuser.UsrCod = UsrCod;
Gbl.Cache.UsrIsSuperuser.IsSuperuser =
(DB_QueryCOUNT ("can not check if a user is superuser",
"SELECT COUNT(*)"
" FROM usr_admins"
" WHERE UsrCod=%ld"
" AND Scope='%s'",
UsrCod,
Sco_GetDBStrFromScope (HieLvl_SYS)) != 0);
DB_QueryEXISTS ("can not check if a user is superuser",
"SELECT EXISTS"
"(SELECT *"
" FROM usr_admins"
" WHERE UsrCod=%ld"
" AND Scope='%s')",
UsrCod,
Sco_GetDBStrFromScope (HieLvl_SYS));
return Gbl.Cache.UsrIsSuperuser.IsSuperuser;
}
@ -2306,11 +2290,12 @@ bool Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (struct UsrData *UsrDat,
void Usr_UpdateMyLastData (void)
{
/***** Check if it exists an entry for me *****/
if (DB_QueryCOUNT ("can not get last user's click",
"SELECT COUNT(*)"
" FROM usr_last"
" WHERE UsrCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod))
if (DB_QueryEXISTS ("can not check last user's click",
"SELECT EXISTS"
"(SELECT *"
" FROM usr_last"
" WHERE UsrCod=%ld)",
Gbl.Usrs.Me.UsrDat.UsrCod))
/***** Update my last accessed course, tab and time of click in database *****/
// WhatToSearch, LastAccNotif remain unchanged
DB_QueryUPDATE ("can not update last user's data",

View File

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

View File

@ -66,7 +66,7 @@ void Usr_DB_UpdateMyOfficePhone (void);
void Usr_DB_UpdateMyLastWhatToSearch (void);
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);
unsigned Usr_DB_GetNumUsrsWhoChoseAnOption (const char *SubQuery);
unsigned Usr_DB_GetOldUsrs (MYSQL_RES **mysql_res,time_t SecondsWithoutAccess);