Version 18.8.9

This commit is contained in:
Antonio Cañas Vargas 2018-10-26 19:59:39 +02:00
parent ddb0259495
commit 187ac31346
17 changed files with 576 additions and 675 deletions

View File

@ -844,14 +844,11 @@ static void ID_RemoveUsrID (const struct UsrData *UsrDat,bool ItsMe)
static bool ID_CheckIfConfirmed (long UsrCod,const char *UsrID) static bool ID_CheckIfConfirmed (long UsrCod,const char *UsrID)
{ {
char *Query;
/***** Get if ID is confirmed from database *****/ /***** Get if ID is confirmed from database *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_IDs" DB_BuildQuery ("SELECT COUNT(*) FROM usr_IDs"
" WHERE UsrCod=%ld AND UsrID='%s' AND Confirmed='Y'", " WHERE UsrCod=%ld AND UsrID='%s' AND Confirmed='Y'",
UsrCod,UsrID) < 0) UsrCod,UsrID);
Lay_NotEnoughMemoryExit (); return (DB_QueryCOUNT_new ("can not check if ID is confirmed") != 0);
return (DB_QueryCOUNT_free (Query,"can not check if ID is confirmed") != 0);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -355,10 +355,11 @@ En OpenSWAD:
ps2pdf source.ps destination.pdf ps2pdf source.ps destination.pdf
*/ */
#define Log_PLATFORM_VERSION "SWAD 18.8.8 (2018-10-26)" #define Log_PLATFORM_VERSION "SWAD 18.8.9 (2018-10-26)"
#define CSS_FILE "swad18.4.css" #define CSS_FILE "swad18.4.css"
#define JS_FILE "swad17.17.1.js" #define JS_FILE "swad17.17.1.js"
/* /*
Version 18.8.9: Oct 26, 2018 Some asprintf for database queries changed by internal function. (237082 lines)
Version 18.8.8: Oct 26, 2018 Some asprintf for database queries changed by internal function. (237154 lines) Version 18.8.8: Oct 26, 2018 Some asprintf for database queries changed by internal function. (237154 lines)
Version 18.8.7: Oct 26, 2018 Some asprintf for database queries changed by internal function. (237172 lines) Version 18.8.7: Oct 26, 2018 Some asprintf for database queries changed by internal function. (237172 lines)
Version 18.8.6: Oct 26, 2018 Some asprintf for database queries changed by internal function. (237407 lines) Version 18.8.6: Oct 26, 2018 Some asprintf for database queries changed by internal function. (237407 lines)

View File

@ -3228,6 +3228,23 @@ unsigned long DB_QueryCOUNT (const char *Query,const char *MsgError)
/******************** Make an INSERT query in database ***********************/ /******************** Make an INSERT query in database ***********************/
/*****************************************************************************/ /*****************************************************************************/
void DB_QueryINSERT_new (const char *MsgError)
{
int Result;
/***** Check that query string pointer
does not point to an allocated string *****/
if (Gbl.DB.QueryPtr == NULL)
Lay_ShowErrorAndExit ("Wrong query string.");
/***** Query database and free query string pointer *****/
Result = mysql_query (&Gbl.mysql,Gbl.DB.QueryPtr); // Returns 0 on success
free ((void *) Gbl.DB.QueryPtr);
Gbl.DB.QueryPtr = NULL;
if (Result)
DB_ExitOnMySQLError (MsgError);
}
void DB_QueryINSERT_free (const char *Query,const char *MsgError) void DB_QueryINSERT_free (const char *Query,const char *MsgError)
{ {
int Result; int Result;
@ -3250,6 +3267,26 @@ void DB_QueryINSERT (const char *Query,const char *MsgError)
/** Make an INSERT query in database and return code of last inserted item ***/ /** Make an INSERT query in database and return code of last inserted item ***/
/*****************************************************************************/ /*****************************************************************************/
long DB_QueryINSERTandReturnCode_new (const char *MsgError)
{
int Result;
/***** Check that query string pointer
does not point to an allocated string *****/
if (Gbl.DB.QueryPtr == NULL)
Lay_ShowErrorAndExit ("Wrong query string.");
/***** Query database and free query string pointer *****/
Result = mysql_query (&Gbl.mysql,Gbl.DB.QueryPtr); // Returns 0 on success
free ((void *) Gbl.DB.QueryPtr);
Gbl.DB.QueryPtr = NULL;
if (Result)
DB_ExitOnMySQLError (MsgError);
/***** Return the code of the inserted item *****/
return (long) mysql_insert_id (&Gbl.mysql);
}
long DB_QueryINSERTandReturnCode_free (const char *Query,const char *MsgError) long DB_QueryINSERTandReturnCode_free (const char *Query,const char *MsgError)
{ {
int Result; int Result;
@ -3278,6 +3315,23 @@ long DB_QueryINSERTandReturnCode (const char *Query,const char *MsgError)
/******************** Make an REPLACE query in database **********************/ /******************** Make an REPLACE query in database **********************/
/*****************************************************************************/ /*****************************************************************************/
void DB_QueryREPLACE_new (const char *MsgError)
{
int Result;
/***** Check that query string pointer
does not point to an allocated string *****/
if (Gbl.DB.QueryPtr == NULL)
Lay_ShowErrorAndExit ("Wrong query string.");
/***** Query database and free query string pointer *****/
Result = mysql_query (&Gbl.mysql,Gbl.DB.QueryPtr); // Returns 0 on success
free ((void *) Gbl.DB.QueryPtr);
Gbl.DB.QueryPtr = NULL;
if (Result)
DB_ExitOnMySQLError (MsgError);
}
void DB_QueryREPLACE_free (const char *Query,const char *MsgError) void DB_QueryREPLACE_free (const char *Query,const char *MsgError)
{ {
int Result; int Result;
@ -3300,6 +3354,26 @@ void DB_QueryREPLACE (const char *Query,const char *MsgError)
/******************** Make a UPDATE query from database **********************/ /******************** Make a UPDATE query from database **********************/
/*****************************************************************************/ /*****************************************************************************/
void DB_QueryUPDATE_new (const char *MsgError)
{
int Result;
/***** Check that query string pointer
does not point to an allocated string *****/
if (Gbl.DB.QueryPtr == NULL)
Lay_ShowErrorAndExit ("Wrong query string.");
/***** Query database and free query string pointer *****/
Result = mysql_query (&Gbl.mysql,Gbl.DB.QueryPtr); // Returns 0 on success
free ((void *) Gbl.DB.QueryPtr);
Gbl.DB.QueryPtr = NULL;
if (Result)
DB_ExitOnMySQLError (MsgError);
/***** Return number of rows updated *****/
//return (unsigned long) mysql_affected_rows (&Gbl.mysql);
}
void DB_QueryUPDATE_free (const char *Query,const char *MsgError) void DB_QueryUPDATE_free (const char *Query,const char *MsgError)
{ {
int Result; int Result;
@ -3328,6 +3402,23 @@ void DB_QueryUPDATE (const char *Query,const char *MsgError)
/******************** Make a DELETE query from database **********************/ /******************** Make a DELETE query from database **********************/
/*****************************************************************************/ /*****************************************************************************/
void DB_QueryDELETE_new (const char *MsgError)
{
int Result;
/***** Check that query string pointer
does not point to an allocated string *****/
if (Gbl.DB.QueryPtr == NULL)
Lay_ShowErrorAndExit ("Wrong query string.");
/***** Query database and free query string pointer *****/
Result = mysql_query (&Gbl.mysql,Gbl.DB.QueryPtr); // Returns 0 on success
free ((void *) Gbl.DB.QueryPtr);
Gbl.DB.QueryPtr = NULL;
if (Result)
DB_ExitOnMySQLError (MsgError);
}
void DB_QueryDELETE_free (const char *Query,const char *MsgError) void DB_QueryDELETE_free (const char *Query,const char *MsgError)
{ {
int Result; int Result;

View File

@ -47,18 +47,23 @@ unsigned long DB_QueryCOUNT_new (const char *MsgError);
unsigned long DB_QueryCOUNT_free (const char *Query,const char *MsgError); unsigned long DB_QueryCOUNT_free (const char *Query,const char *MsgError);
unsigned long DB_QueryCOUNT (const char *Query,const char *MsgError); unsigned long DB_QueryCOUNT (const char *Query,const char *MsgError);
void DB_QueryINSERT_new (const char *MsgError);
void DB_QueryINSERT_free (const char *Query,const char *MsgError); void DB_QueryINSERT_free (const char *Query,const char *MsgError);
void DB_QueryINSERT (const char *Query,const char *MsgError); void DB_QueryINSERT (const char *Query,const char *MsgError);
long DB_QueryINSERTandReturnCode_new (const char *MsgError);
long DB_QueryINSERTandReturnCode_free (const char *Query,const char *MsgError); long DB_QueryINSERTandReturnCode_free (const char *Query,const char *MsgError);
long DB_QueryINSERTandReturnCode (const char *Query,const char *MsgError); long DB_QueryINSERTandReturnCode (const char *Query,const char *MsgError);
void DB_QueryREPLACE_new (const char *MsgError);
void DB_QueryREPLACE_free (const char *Query,const char *MsgError); void DB_QueryREPLACE_free (const char *Query,const char *MsgError);
void DB_QueryREPLACE (const char *Query,const char *MsgError); void DB_QueryREPLACE (const char *Query,const char *MsgError);
void DB_QueryUPDATE_new (const char *MsgError);
void DB_QueryUPDATE_free (const char *Query,const char *MsgError); void DB_QueryUPDATE_free (const char *Query,const char *MsgError);
void DB_QueryUPDATE (const char *Query,const char *MsgError); void DB_QueryUPDATE (const char *Query,const char *MsgError);
void DB_QueryDELETE_new (const char *MsgError);
void DB_QueryDELETE_free (const char *Query,const char *MsgError); void DB_QueryDELETE_free (const char *Query,const char *MsgError);
void DB_QueryDELETE (const char *Query,const char *MsgError); void DB_QueryDELETE (const char *Query,const char *MsgError);

View File

@ -3797,15 +3797,12 @@ void Grp_RecFormNewGrp (void)
static bool Grp_CheckIfGroupTypeNameExists (const char *GrpTypName,long GrpTypCod) static bool Grp_CheckIfGroupTypeNameExists (const char *GrpTypName,long GrpTypCod)
{ {
char *Query;
/***** Get number of group types with a name from database *****/ /***** Get number of group types with a name from database *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM crs_grp_types" DB_BuildQuery ("SELECT COUNT(*) FROM crs_grp_types"
" WHERE CrsCod=%ld AND GrpTypName='%s'" " WHERE CrsCod=%ld AND GrpTypName='%s'"
" AND GrpTypCod<>%ld", " AND GrpTypCod<>%ld",
Gbl.CurrentCrs.Crs.CrsCod,GrpTypName,GrpTypCod) < 0) Gbl.CurrentCrs.Crs.CrsCod,GrpTypName,GrpTypCod);
Lay_NotEnoughMemoryExit (); return (DB_QueryCOUNT_new ("can not check if the name of type of group already existed") != 0);
return (DB_QueryCOUNT_free (Query,"can not check if the name of type of group already existed") != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -3814,14 +3811,11 @@ static bool Grp_CheckIfGroupTypeNameExists (const char *GrpTypName,long GrpTypCo
static bool Grp_CheckIfGroupNameExists (long GrpTypCod,const char *GrpName,long GrpCod) static bool Grp_CheckIfGroupNameExists (long GrpTypCod,const char *GrpName,long GrpCod)
{ {
char *Query;
/***** Get number of groups with a type and a name from database *****/ /***** Get number of groups with a type and a name from database *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM crs_grp" DB_BuildQuery ("SELECT COUNT(*) FROM crs_grp"
" WHERE GrpTypCod=%ld AND GrpName='%s' AND GrpCod<>%ld", " WHERE GrpTypCod=%ld AND GrpName='%s' AND GrpCod<>%ld",
GrpTypCod,GrpName,GrpCod) < 0) GrpTypCod,GrpName,GrpCod);
Lay_NotEnoughMemoryExit (); return (DB_QueryCOUNT_new ("can not check if the name of group already existed") != 0);
return (DB_QueryCOUNT_free (Query,"can not check if the name of group already existed") != 0);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -522,16 +522,13 @@ static void Inf_PutCheckboxConfirmIHaveReadInfo (void)
static bool Inf_CheckIfIHaveReadInfo (void) static bool Inf_CheckIfIHaveReadInfo (void)
{ {
char *Query;
/***** Get if info source is already stored in database *****/ /***** Get if info source is already stored in database *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM crs_info_read" DB_BuildQuery ("SELECT COUNT(*) FROM crs_info_read"
" WHERE UsrCod=%ld AND CrsCod=%ld AND InfoType='%s'", " WHERE UsrCod=%ld AND CrsCod=%ld AND InfoType='%s'",
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.CurrentCrs.Crs.CrsCod, Gbl.CurrentCrs.Crs.CrsCod,
Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]) < 0) Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]);
Lay_NotEnoughMemoryExit (); return (DB_QueryCOUNT_new ("can not get if I have read course info") != 0);
return (DB_QueryCOUNT_free (Query,"can not get if I have read course info") != 0);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -1863,14 +1863,11 @@ static void Ins_RenameInstitution (struct Instit *Ins,Cns_ShrtOrFullName_t ShrtO
static bool Ins_CheckIfInsNameExistsInCty (const char *FieldName,const char *Name,long InsCod,long CtyCod) static bool Ins_CheckIfInsNameExistsInCty (const char *FieldName,const char *Name,long InsCod,long CtyCod)
{ {
char *Query;
/***** Get number of institutions in current country with a name from database *****/ /***** Get number of institutions in current country with a name from database *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM institutions" DB_BuildQuery ("SELECT COUNT(*) FROM institutions"
" WHERE CtyCod=%ld AND %s='%s' AND InsCod<>%ld", " WHERE CtyCod=%ld AND %s='%s' AND InsCod<>%ld",
CtyCod,FieldName,Name,InsCod) < 0) CtyCod,FieldName,Name,InsCod);
Lay_NotEnoughMemoryExit (); return (DB_QueryCOUNT_new ("can not check if the name of an institution already existed") != 0);
return (DB_QueryCOUNT_free (Query,"can not check if the name of an institution already existed") != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2447,12 +2444,9 @@ static void Ins_CreateInstitution (unsigned Status)
unsigned Ins_GetNumInssTotal (void) unsigned Ins_GetNumInssTotal (void)
{ {
char *Query;
/***** Get total number of degrees from database *****/ /***** Get total number of degrees from database *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM institutions") < 0) DB_BuildQuery ("SELECT COUNT(*) FROM institutions");
Lay_NotEnoughMemoryExit (); return (unsigned) DB_QueryCOUNT_new ("can not get the total number of institutions");
return (unsigned) DB_QueryCOUNT_free (Query,"can not get the total number of institutions");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2461,13 +2455,9 @@ unsigned Ins_GetNumInssTotal (void)
unsigned Ins_GetNumInssInCty (long CtyCod) unsigned Ins_GetNumInssInCty (long CtyCod)
{ {
char *Query;
/***** Get number of degrees of a place from database *****/ /***** Get number of degrees of a place from database *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM institutions WHERE CtyCod=%ld", DB_BuildQuery ("SELECT COUNT(*) FROM institutions WHERE CtyCod=%ld",CtyCod);
CtyCod) < 0) return (unsigned) DB_QueryCOUNT_new ("can not get the number of institutions in a country");
Lay_NotEnoughMemoryExit ();
return (unsigned) DB_QueryCOUNT_free (Query,"can not get the number of institutions in a country");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2476,15 +2466,12 @@ unsigned Ins_GetNumInssInCty (long CtyCod)
unsigned Ins_GetNumInssWithCtrs (const char *SubQuery) unsigned Ins_GetNumInssWithCtrs (const char *SubQuery)
{ {
char *Query;
/***** Get number of institutions with centres from database *****/ /***** Get number of institutions with centres from database *****/
if (asprintf (&Query,"SELECT COUNT(DISTINCT institutions.InsCod)" DB_BuildQuery ("SELECT COUNT(DISTINCT institutions.InsCod)"
" FROM institutions,centres" " FROM institutions,centres"
" WHERE %sinstitutions.InsCod=centres.InsCod", " WHERE %sinstitutions.InsCod=centres.InsCod",
SubQuery) < 0) SubQuery);
Lay_NotEnoughMemoryExit (); return (unsigned) DB_QueryCOUNT_new ("can not get number of institutions with centres");
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of institutions with centres");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2493,16 +2480,13 @@ unsigned Ins_GetNumInssWithCtrs (const char *SubQuery)
unsigned Ins_GetNumInssWithDegs (const char *SubQuery) unsigned Ins_GetNumInssWithDegs (const char *SubQuery)
{ {
char *Query;
/***** Get number of institutions with degrees from database *****/ /***** Get number of institutions with degrees from database *****/
if (asprintf (&Query,"SELECT COUNT(DISTINCT institutions.InsCod)" DB_BuildQuery ("SELECT COUNT(DISTINCT institutions.InsCod)"
" FROM institutions,centres,degrees" " FROM institutions,centres,degrees"
" WHERE %sinstitutions.InsCod=centres.InsCod" " WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod", " AND centres.CtrCod=degrees.CtrCod",
SubQuery) < 0) SubQuery);
Lay_NotEnoughMemoryExit (); return (unsigned) DB_QueryCOUNT_new ("can not get number of institutions with degrees");
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of institutions with degrees");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2511,17 +2495,14 @@ unsigned Ins_GetNumInssWithDegs (const char *SubQuery)
unsigned Ins_GetNumInssWithCrss (const char *SubQuery) unsigned Ins_GetNumInssWithCrss (const char *SubQuery)
{ {
char *Query;
/***** Get number of institutions with courses from database *****/ /***** Get number of institutions with courses from database *****/
if (asprintf (&Query,"SELECT COUNT(DISTINCT institutions.InsCod)" DB_BuildQuery ("SELECT COUNT(DISTINCT institutions.InsCod)"
" FROM institutions,centres,degrees,courses" " FROM institutions,centres,degrees,courses"
" WHERE %sinstitutions.InsCod=centres.InsCod" " WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod" " AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod", " AND degrees.DegCod=courses.DegCod",
SubQuery) < 0) SubQuery);
Lay_NotEnoughMemoryExit (); return (unsigned) DB_QueryCOUNT_new ("can not get number of institutions with courses");
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of institutions with courses");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2530,19 +2511,16 @@ unsigned Ins_GetNumInssWithCrss (const char *SubQuery)
unsigned Ins_GetNumInssWithUsrs (Rol_Role_t Role,const char *SubQuery) unsigned Ins_GetNumInssWithUsrs (Rol_Role_t Role,const char *SubQuery)
{ {
char *Query;
/***** Get number of institutions with users from database *****/ /***** Get number of institutions with users from database *****/
if (asprintf (&Query,"SELECT COUNT(DISTINCT institutions.InsCod)" DB_BuildQuery ("SELECT COUNT(DISTINCT institutions.InsCod)"
" FROM institutions,centres,degrees,courses,crs_usr" " FROM institutions,centres,degrees,courses,crs_usr"
" WHERE %sinstitutions.InsCod=centres.InsCod" " WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod" " AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod" " AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod" " AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u", " AND crs_usr.Role=%u",
SubQuery,(unsigned) Role) < 0) SubQuery,(unsigned) Role);
Lay_NotEnoughMemoryExit (); return (unsigned) DB_QueryCOUNT_new ("can not get number of institutions with users");
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of institutions with users");
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -630,13 +630,10 @@ static void Lnk_RenameLink (Cns_ShrtOrFullName_t ShrtOrFullName)
static bool Lnk_CheckIfLinkNameExists (const char *FieldName,const char *Name,long LnkCod) static bool Lnk_CheckIfLinkNameExists (const char *FieldName,const char *Name,long LnkCod)
{ {
char *Query;
/***** Get number of links with a name from database *****/ /***** Get number of links with a name from database *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM links WHERE %s='%s' AND LnkCod<>%ld", DB_BuildQuery ("SELECT COUNT(*) FROM links WHERE %s='%s' AND LnkCod<>%ld",
FieldName,Name,LnkCod) < 0) FieldName,Name,LnkCod);
Lay_NotEnoughMemoryExit (); return (DB_QueryCOUNT_new ("can not check if the name of an institutional link already existed") != 0);
return (DB_QueryCOUNT_free (Query,"can not check if the name of an institutional link already existed") != 0);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -357,13 +357,10 @@ static void Mai_GetMailDomain (const char *Email,char MailDomain[Cns_MAX_BYTES_E
static bool Mai_CheckIfMailDomainIsAllowedForNotif (const char MailDomain[Cns_MAX_BYTES_EMAIL_ADDRESS + 1]) static bool Mai_CheckIfMailDomainIsAllowedForNotif (const char MailDomain[Cns_MAX_BYTES_EMAIL_ADDRESS + 1])
{ {
char *Query;
/***** Get number of mail_domains with a name from database *****/ /***** Get number of mail_domains with a name from database *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM mail_domains WHERE Domain='%s'", DB_BuildQuery ("SELECT COUNT(*) FROM mail_domains WHERE Domain='%s'",
MailDomain) < 0) MailDomain);
Lay_NotEnoughMemoryExit (); return (DB_QueryCOUNT_new ("can not check if a mail domain is allowed for notifications") != 0);
return (DB_QueryCOUNT_free (Query,"can not check if a mail domain is allowed for notifications") != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -693,14 +690,11 @@ static void Mai_RenameMailDomain (Cns_ShrtOrFullName_t ShrtOrFullName)
static bool Mai_CheckIfMailDomainNameExists (const char *FieldName,const char *Name,long MaiCod) static bool Mai_CheckIfMailDomainNameExists (const char *FieldName,const char *Name,long MaiCod)
{ {
char *Query;
/***** Get number of mail_domains with a name from database *****/ /***** Get number of mail_domains with a name from database *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM mail_domains" DB_BuildQuery ("SELECT COUNT(*) FROM mail_domains"
" WHERE %s='%s' AND MaiCod<>%ld", " WHERE %s='%s' AND MaiCod<>%ld",
FieldName,Name,MaiCod) < 0) FieldName,Name,MaiCod);
Lay_NotEnoughMemoryExit (); return (DB_QueryCOUNT_new ("can not check if the name of a mail domain already existed") != 0);
return (DB_QueryCOUNT_free (Query,"can not check if the name of a mail domain already existed") != 0);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1639,12 +1633,11 @@ bool Mai_UpdateEmailInDB (const struct UsrData *UsrDat,const char NewEmail[Cns_M
char *Query; char *Query;
/***** 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 (asprintf (&Query,"SELECT COUNT(*) FROM usr_emails" DB_BuildQuery ("SELECT COUNT(*) FROM usr_emails"
" WHERE E_mail='%s' AND Confirmed='Y'" " WHERE E_mail='%s' AND Confirmed='Y'"
" AND UsrCod<>%ld", " AND UsrCod<>%ld",
NewEmail,UsrDat->UsrCod) < 0) NewEmail,UsrDat->UsrCod);
Lay_NotEnoughMemoryExit (); if (DB_QueryCOUNT_new ("can not check if email already existed")) // An email of another user is the same that my email
if (DB_QueryCOUNT_free (Query,"can not check if email already existed")) // An email of another user is the same that my email
return false; // Don't update return false; // Don't update
/***** Delete email (not confirmed) for other users *****/ /***** Delete email (not confirmed) for other users *****/

File diff suppressed because it is too large Load Diff

View File

@ -557,7 +557,6 @@ static void Nck_UpdateUsrNick (struct UsrData *UsrDat)
extern const char *Txt_The_nickname_X_had_been_registered_by_another_user; extern const char *Txt_The_nickname_X_had_been_registered_by_another_user;
extern const char *Txt_The_nickname_X_has_been_registered_successfully; extern const char *Txt_The_nickname_X_has_been_registered_successfully;
extern const char *Txt_The_nickname_entered_X_is_not_valid_; extern const char *Txt_The_nickname_entered_X_is_not_valid_;
char *Query;
char NewNicknameWithArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1]; char NewNicknameWithArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
char NewNicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1]; char NewNicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
@ -583,18 +582,16 @@ static void Nck_UpdateUsrNick (struct UsrData *UsrDat)
else if (strcasecmp (UsrDat->Nickname,NewNicknameWithoutArroba)) // User's nickname does not match, not even case insensitive, the new nickname else if (strcasecmp (UsrDat->Nickname,NewNicknameWithoutArroba)) // User's nickname does not match, not even case insensitive, the new nickname
{ {
/***** Check if the new nickname matches any of my old nicknames *****/ /***** Check if the new nickname matches any of my old nicknames *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_nicknames" DB_BuildQuery ("SELECT COUNT(*) FROM usr_nicknames"
" WHERE UsrCod=%ld AND Nickname='%s'", " WHERE UsrCod=%ld AND Nickname='%s'",
UsrDat->UsrCod,NewNicknameWithoutArroba) < 0) UsrDat->UsrCod,NewNicknameWithoutArroba);
Lay_NotEnoughMemoryExit (); if (!DB_QueryCOUNT_new ("can not check if nickname already existed")) // No matches
if (!DB_QueryCOUNT_free (Query,"can not check if nickname already existed")) // No matches
{ {
/***** 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 (asprintf (&Query,"SELECT COUNT(*) FROM usr_nicknames" DB_BuildQuery ("SELECT COUNT(*) FROM usr_nicknames"
" WHERE Nickname='%s' AND UsrCod<>%ld", " WHERE Nickname='%s' AND UsrCod<>%ld",
NewNicknameWithoutArroba,UsrDat->UsrCod) < 0) NewNicknameWithoutArroba,UsrDat->UsrCod);
Lay_NotEnoughMemoryExit (); if (DB_QueryCOUNT_new ("can not check if nickname already existed")) // A nickname of another user is the same that user's nickname
if (DB_QueryCOUNT_free (Query,"can not check if nickname already existed")) // A nickname of another user is the same that user's nickname
{ {
Gbl.Alert.Type = Ale_WARNING; Gbl.Alert.Type = Ale_WARNING;
Gbl.Alert.Section = Nck_NICKNAME_SECTION_ID; Gbl.Alert.Section = Nck_NICKNAME_SECTION_ID;

View File

@ -2120,15 +2120,12 @@ void Ntf_WriteNumberOfNewNtfs (void)
static unsigned Ntf_GetNumberOfAllMyUnseenNtfs (void) static unsigned Ntf_GetNumberOfAllMyUnseenNtfs (void)
{ {
char *Query;
/***** Get number of places with a name from database *****/ /***** Get number of places with a name from database *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM notif" DB_BuildQuery ("SELECT COUNT(*) FROM notif"
" WHERE ToUsrCod=%ld AND (Status & %u)=0", " WHERE ToUsrCod=%ld AND (Status & %u)=0",
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED)) < 0) (unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED));
Lay_NotEnoughMemoryExit (); return DB_QueryCOUNT_new ("can not get number of unseen notifications");
return DB_QueryCOUNT_free (Query,"can not get number of unseen notifications");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -2137,17 +2134,14 @@ static unsigned Ntf_GetNumberOfAllMyUnseenNtfs (void)
static unsigned Ntf_GetNumberOfMyNewUnseenNtfs (void) static unsigned Ntf_GetNumberOfMyNewUnseenNtfs (void)
{ {
char *Query;
/***** Get number of places with a name from database *****/ /***** Get number of places with a name from database *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM notif" DB_BuildQuery ("SELECT COUNT(*) FROM notif"
" WHERE ToUsrCod=%ld AND (Status & %u)=0" " WHERE ToUsrCod=%ld AND (Status & %u)=0"
" AND TimeNotif>FROM_UNIXTIME(%ld)", " AND TimeNotif>FROM_UNIXTIME(%ld)",
Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED), (unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED),
Gbl.Usrs.Me.UsrLast.LastAccNotif) < 0) Gbl.Usrs.Me.UsrLast.LastAccNotif);
Lay_NotEnoughMemoryExit (); return DB_QueryCOUNT_new ("can not get number of unseen notifications");
return DB_QueryCOUNT_free (Query,"can not get number of unseen notifications");
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -578,23 +578,20 @@ bool Pwd_SlowCheckIfPasswordIsGood (const char *PlainPassword,
static bool Pwd_CheckIfPasswdIsUsrIDorName (const char *PlainPassword) static bool Pwd_CheckIfPasswdIsUsrIDorName (const char *PlainPassword)
{ {
char *Query;
bool Found; bool Found;
/***** Get if password is found in user's ID from database *****/ /***** Get if password is found in user's ID from database *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_IDs WHERE UsrID='%s'", DB_BuildQuery ("SELECT COUNT(*) FROM usr_IDs WHERE UsrID='%s'",
PlainPassword) < 0) PlainPassword);
Lay_NotEnoughMemoryExit (); Found = (DB_QueryCOUNT_new ("can not check if a password matches a user's ID") != 0);
Found = (DB_QueryCOUNT_free (Query,"can not check if a password matches a user's ID") != 0);
/***** Get if password is found in first name or surnames of anybody, from database *****/ /***** Get if password is found in first name or surnames of anybody, from database *****/
if (!Found) if (!Found)
{ {
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_data" DB_BuildQuery ("SELECT COUNT(*) FROM usr_data"
" WHERE FirstName='%s' OR Surname1='%s' OR Surname2='%s'", " WHERE FirstName='%s' OR Surname1='%s' OR Surname2='%s'",
PlainPassword,PlainPassword,PlainPassword) < 0) PlainPassword,PlainPassword,PlainPassword);
Lay_NotEnoughMemoryExit (); Found = (DB_QueryCOUNT_new ("can not check if a password matches a first name or a surname") != 0);
Found = (DB_QueryCOUNT_free (Query,"can not check if a password matches a first name or a surname") != 0);
} }
return Found; return Found;
@ -606,25 +603,17 @@ static bool Pwd_CheckIfPasswdIsUsrIDorName (const char *PlainPassword)
static unsigned Pwd_GetNumOtherUsrsWhoUseThisPassword (const char *EncryptedPassword,long UsrCod) static unsigned Pwd_GetNumOtherUsrsWhoUseThisPassword (const char *EncryptedPassword,long UsrCod)
{ {
char *Query;
/***** Get number of other users who use a password from database *****/ /***** Get number of other users who use a password from database *****/
/* Query database */ /* Query database */
if (UsrCod > 0) if (UsrCod > 0)
{ DB_BuildQuery ("SELECT COUNT(*) FROM usr_data"
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_data" " WHERE Password='%s' AND UsrCod<>%ld",
" WHERE Password='%s' AND UsrCod<>%ld", EncryptedPassword,UsrCod);
EncryptedPassword,UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
}
else else
{ DB_BuildQuery ("SELECT COUNT(*) FROM usr_data"
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_data" " WHERE Password='%s'",
" WHERE Password='%s'", EncryptedPassword);
EncryptedPassword) < 0) return (unsigned) DB_QueryCOUNT_new ("can not check if a password is trivial");
Lay_NotEnoughMemoryExit ();
}
return (unsigned) DB_QueryCOUNT_free (Query,"can not check if a password is trivial");
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -705,14 +705,11 @@ static void Plc_RenamePlace (Cns_ShrtOrFullName_t ShrtOrFullName)
static bool Plc_CheckIfPlaceNameExists (const char *FieldName,const char *Name,long PlcCod) static bool Plc_CheckIfPlaceNameExists (const char *FieldName,const char *Name,long PlcCod)
{ {
char *Query;
/***** Get number of places with a name from database *****/ /***** Get number of places with a name from database *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM places" DB_BuildQuery ("SELECT COUNT(*) FROM places"
" WHERE InsCod=%ld AND %s='%s' AND PlcCod<>%ld", " WHERE InsCod=%ld AND %s='%s' AND PlcCod<>%ld",
Gbl.CurrentIns.Ins.InsCod,FieldName,Name,PlcCod) < 0) Gbl.CurrentIns.Ins.InsCod,FieldName,Name,PlcCod);
Lay_NotEnoughMemoryExit (); return (DB_QueryCOUNT_new ("can not check if the name of a place already existed") != 0);
return (DB_QueryCOUNT_free (Query,"can not check if the name of a place already existed") != 0);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -596,14 +596,11 @@ void Plg_RenamePlugin (void)
static bool Plg_CheckIfPluginNameExists (const char *Name,long PlgCod) static bool Plg_CheckIfPluginNameExists (const char *Name,long PlgCod)
{ {
char *Query;
/***** Get number of plugins with a name from database *****/ /***** Get number of plugins with a name from database *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM plugins" DB_BuildQuery ("SELECT COUNT(*) FROM plugins"
" WHERE Name='%s' AND PlgCod<>%ld", " WHERE Name='%s' AND PlgCod<>%ld",
Name,PlgCod) < 0) Name,PlgCod);
Lay_NotEnoughMemoryExit (); return (DB_QueryCOUNT_new ("can not check if the name of a plugin already existed") != 0);
return (DB_QueryCOUNT_free (Query,"can not check if the name of a plugin already existed") != 0);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -679,17 +679,14 @@ void Prf_GetUsrFigures (long UsrCod,struct UsrFigures *UsrFigures)
static unsigned long Prf_GetRankingFigure (long UsrCod,const char *FieldName) static unsigned long Prf_GetRankingFigure (long UsrCod,const char *FieldName)
{ {
char *Query;
/***** Select number of rows with figure /***** Select number of rows with figure
greater than the figure of this user *****/ greater than the figure of this user *****/
if (asprintf (&Query,"SELECT COUNT(*)+1 FROM usr_figures" DB_BuildQuery ("SELECT COUNT(*)+1 FROM usr_figures"
" WHERE UsrCod<>%ld" // Really not necessary here " WHERE UsrCod<>%ld" // Really not necessary here
" AND %s>" " AND %s>"
"(SELECT %s FROM usr_figures WHERE UsrCod=%ld)", "(SELECT %s FROM usr_figures WHERE UsrCod=%ld)",
UsrCod,FieldName,FieldName,UsrCod) < 0) UsrCod,FieldName,FieldName,UsrCod);
Lay_NotEnoughMemoryExit (); return DB_QueryCOUNT_new ("can not get ranking using a figure");
return DB_QueryCOUNT_free (Query,"can not get ranking using a figure");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -698,13 +695,9 @@ static unsigned long Prf_GetRankingFigure (long UsrCod,const char *FieldName)
static unsigned long Prf_GetNumUsrsWithFigure (const char *FieldName) static unsigned long Prf_GetNumUsrsWithFigure (const char *FieldName)
{ {
char *Query;
/***** Select number of rows with values already calculated *****/ /***** Select number of rows with values already calculated *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_figures WHERE %s>=0", DB_BuildQuery ("SELECT COUNT(*) FROM usr_figures WHERE %s>=0",FieldName);
FieldName) < 0) return DB_QueryCOUNT_new ("can not get number of users with a figure");
Lay_NotEnoughMemoryExit ();
return DB_QueryCOUNT_free (Query,"can not get number of users with a figure");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -713,27 +706,24 @@ static unsigned long Prf_GetNumUsrsWithFigure (const char *FieldName)
static unsigned long Prf_GetRankingNumClicksPerDay (long UsrCod) static unsigned long Prf_GetRankingNumClicksPerDay (long UsrCod)
{ {
char *Query;
/***** Select number of rows with number of clicks per day /***** Select number of rows with number of clicks per day
greater than the clicks per day of this user *****/ greater than the clicks per day of this user *****/
if (asprintf (&Query,"SELECT COUNT(*)+1 FROM" DB_BuildQuery ("SELECT COUNT(*)+1 FROM"
" (SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)" " (SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)"
" AS NumClicksPerDay" " AS NumClicksPerDay"
" FROM usr_figures" " FROM usr_figures"
" WHERE UsrCod<>%ld" // Necessary because the following comparison is not exact in floating point " WHERE UsrCod<>%ld" // Necessary because the following comparison is not exact in floating point
" AND NumClicks>0" " AND NumClicks>0"
" AND UNIX_TIMESTAMP(FirstClickTime)>0)" " AND UNIX_TIMESTAMP(FirstClickTime)>0)"
" AS TableNumClicksPerDay" " AS TableNumClicksPerDay"
" WHERE NumClicksPerDay>" " WHERE NumClicksPerDay>"
"(SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)" "(SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)"
" FROM usr_figures" " FROM usr_figures"
" WHERE UsrCod=%ld" " WHERE UsrCod=%ld"
" AND NumClicks>0" " AND NumClicks>0"
" AND UNIX_TIMESTAMP(FirstClickTime)>0)", " AND UNIX_TIMESTAMP(FirstClickTime)>0)",
UsrCod,UsrCod) < 0) UsrCod,UsrCod);
Lay_NotEnoughMemoryExit (); return DB_QueryCOUNT_new ("can not get ranking using number of clicks per day");
return DB_QueryCOUNT_free (Query,"can not get ranking using number of clicks per day");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -742,14 +732,11 @@ static unsigned long Prf_GetRankingNumClicksPerDay (long UsrCod)
static unsigned long Prf_GetNumUsrsWithNumClicksPerDay (void) static unsigned long Prf_GetNumUsrsWithNumClicksPerDay (void)
{ {
char *Query;
/***** Select number of rows with values already calculated *****/ /***** Select number of rows with values already calculated *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_figures" DB_BuildQuery ("SELECT COUNT(*) FROM usr_figures"
" WHERE NumClicks>0" " WHERE NumClicks>0"
" AND UNIX_TIMESTAMP(FirstClickTime)>0") < 0) " AND UNIX_TIMESTAMP(FirstClickTime)>0");
Lay_NotEnoughMemoryExit (); return DB_QueryCOUNT_new ("can not get number of users with number of clicks per day");
return DB_QueryCOUNT_free (Query,"can not get number of users with number of clicks per day");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -900,10 +887,8 @@ static void Prf_GetNumClicksAndStoreAsUsrFigure (long UsrCod)
Prf_ResetUsrFigures (&UsrFigures); Prf_ResetUsrFigures (&UsrFigures);
/***** Get number of clicks from database *****/ /***** Get number of clicks from database *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM log_full WHERE UsrCod=%ld", DB_BuildQuery ("SELECT COUNT(*) FROM log_full WHERE UsrCod=%ld",UsrCod);
UsrCod) < 0) UsrFigures.NumClicks = (long) DB_QueryCOUNT_new ("can not get number of clicks");
Lay_NotEnoughMemoryExit ();
UsrFigures.NumClicks = (long) DB_QueryCOUNT_free (Query,"can not get number of clicks");
/***** Update number of clicks in user's figures *****/ /***** Update number of clicks in user's figures *****/
if (Prf_CheckIfUsrFiguresExists (UsrCod)) if (Prf_CheckIfUsrFiguresExists (UsrCod))
@ -1101,12 +1086,8 @@ void Prf_RemoveUsrFigures (long UsrCod)
static bool Prf_CheckIfUsrFiguresExists (long UsrCod) static bool Prf_CheckIfUsrFiguresExists (long UsrCod)
{ {
char *Query; DB_BuildQuery ("SELECT COUNT(*) FROM usr_figures WHERE UsrCod=%ld",UsrCod);
return (DB_QueryCOUNT_new ("can not get user's first click") != 0);
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_figures WHERE UsrCod=%ld",
UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
return (DB_QueryCOUNT_free (Query,"can not get user's first click") != 0);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -629,15 +629,12 @@ long Rec_GetFieldCod (void)
unsigned Rec_CountNumRecordsInCurrCrsWithField (long FieldCod) unsigned Rec_CountNumRecordsInCurrCrsWithField (long FieldCod)
{ {
char *Query;
/***** Get number of cards with a given field in a course from database *****/ /***** Get number of cards with a given field in a course from database *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM crs_records WHERE FieldCod=%ld", DB_BuildQuery ("SELECT COUNT(*) FROM crs_records WHERE FieldCod=%ld",
FieldCod) < 0) FieldCod);
Lay_NotEnoughMemoryExit (); return (unsigned) DB_QueryCOUNT_new ("can not get number of cards"
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of cards" " with a given field not empty"
" with a given field not empty" " in a course");
" in a course");
} }
/*****************************************************************************/ /*****************************************************************************/