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)
{
char *Query;
/***** 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'",
UsrCod,UsrID) < 0)
Lay_NotEnoughMemoryExit ();
return (DB_QueryCOUNT_free (Query,"can not check if ID is confirmed") != 0);
UsrCod,UsrID);
return (DB_QueryCOUNT_new ("can not check if ID is confirmed") != 0);
}
/*****************************************************************************/

View File

@ -355,10 +355,11 @@ En OpenSWAD:
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 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.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)

View File

@ -3228,6 +3228,23 @@ unsigned long DB_QueryCOUNT (const char *Query,const char *MsgError)
/******************** 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)
{
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 ***/
/*****************************************************************************/
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)
{
int Result;
@ -3278,6 +3315,23 @@ long DB_QueryINSERTandReturnCode (const char *Query,const char *MsgError)
/******************** 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)
{
int Result;
@ -3300,6 +3354,26 @@ void DB_QueryREPLACE (const char *Query,const char *MsgError)
/******************** 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)
{
int Result;
@ -3328,6 +3402,23 @@ void DB_QueryUPDATE (const char *Query,const char *MsgError)
/******************** 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)
{
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 (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 (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 (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 (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 (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 (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)
{
char *Query;
/***** 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'"
" AND GrpTypCod<>%ld",
Gbl.CurrentCrs.Crs.CrsCod,GrpTypName,GrpTypCod) < 0)
Lay_NotEnoughMemoryExit ();
return (DB_QueryCOUNT_free (Query,"can not check if the name of type of group already existed") != 0);
Gbl.CurrentCrs.Crs.CrsCod,GrpTypName,GrpTypCod);
return (DB_QueryCOUNT_new ("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)
{
char *Query;
/***** 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",
GrpTypCod,GrpName,GrpCod) < 0)
Lay_NotEnoughMemoryExit ();
return (DB_QueryCOUNT_free (Query,"can not check if the name of group already existed") != 0);
GrpTypCod,GrpName,GrpCod);
return (DB_QueryCOUNT_new ("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)
{
char *Query;
/***** 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'",
Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.CurrentCrs.Crs.CrsCod,
Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]) < 0)
Lay_NotEnoughMemoryExit ();
return (DB_QueryCOUNT_free (Query,"can not get if I have read course info") != 0);
Inf_NamesInDBForInfoType[Gbl.CurrentCrs.Info.Type]);
return (DB_QueryCOUNT_new ("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)
{
char *Query;
/***** 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",
CtyCod,FieldName,Name,InsCod) < 0)
Lay_NotEnoughMemoryExit ();
return (DB_QueryCOUNT_free (Query,"can not check if the name of an institution already existed") != 0);
CtyCod,FieldName,Name,InsCod);
return (DB_QueryCOUNT_new ("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)
{
char *Query;
/***** Get total number of degrees from database *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM institutions") < 0)
Lay_NotEnoughMemoryExit ();
return (unsigned) DB_QueryCOUNT_free (Query,"can not get the total number of institutions");
DB_BuildQuery ("SELECT COUNT(*) FROM institutions");
return (unsigned) DB_QueryCOUNT_new ("can not get the total number of institutions");
}
/*****************************************************************************/
@ -2461,13 +2455,9 @@ unsigned Ins_GetNumInssTotal (void)
unsigned Ins_GetNumInssInCty (long CtyCod)
{
char *Query;
/***** Get number of degrees of a place from database *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM institutions WHERE CtyCod=%ld",
CtyCod) < 0)
Lay_NotEnoughMemoryExit ();
return (unsigned) DB_QueryCOUNT_free (Query,"can not get the number of institutions in a country");
DB_BuildQuery ("SELECT COUNT(*) FROM institutions WHERE CtyCod=%ld",CtyCod);
return (unsigned) DB_QueryCOUNT_new ("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)
{
char *Query;
/***** 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"
" WHERE %sinstitutions.InsCod=centres.InsCod",
SubQuery) < 0)
Lay_NotEnoughMemoryExit ();
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of institutions with centres");
SubQuery);
return (unsigned) DB_QueryCOUNT_new ("can not get number of institutions with centres");
}
/*****************************************************************************/
@ -2493,16 +2480,13 @@ unsigned Ins_GetNumInssWithCtrs (const char *SubQuery)
unsigned Ins_GetNumInssWithDegs (const char *SubQuery)
{
char *Query;
/***** 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"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod",
SubQuery) < 0)
Lay_NotEnoughMemoryExit ();
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of institutions with degrees");
SubQuery);
return (unsigned) DB_QueryCOUNT_new ("can not get number of institutions with degrees");
}
/*****************************************************************************/
@ -2511,17 +2495,14 @@ unsigned Ins_GetNumInssWithDegs (const char *SubQuery)
unsigned Ins_GetNumInssWithCrss (const char *SubQuery)
{
char *Query;
/***** 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"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod",
SubQuery) < 0)
Lay_NotEnoughMemoryExit ();
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of institutions with courses");
SubQuery);
return (unsigned) DB_QueryCOUNT_new ("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)
{
char *Query;
/***** 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"
" WHERE %sinstitutions.InsCod=centres.InsCod"
" AND centres.CtrCod=degrees.CtrCod"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=crs_usr.CrsCod"
" AND crs_usr.Role=%u",
SubQuery,(unsigned) Role) < 0)
Lay_NotEnoughMemoryExit ();
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of institutions with users");
SubQuery,(unsigned) Role);
return (unsigned) DB_QueryCOUNT_new ("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)
{
char *Query;
/***** Get number of links with a name from database *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM links WHERE %s='%s' AND LnkCod<>%ld",
FieldName,Name,LnkCod) < 0)
Lay_NotEnoughMemoryExit ();
return (DB_QueryCOUNT_free (Query,"can not check if the name of an institutional link already existed") != 0);
DB_BuildQuery ("SELECT COUNT(*) FROM links WHERE %s='%s' AND LnkCod<>%ld",
FieldName,Name,LnkCod);
return (DB_QueryCOUNT_new ("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])
{
char *Query;
/***** Get number of mail_domains with a name from database *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM mail_domains WHERE Domain='%s'",
MailDomain) < 0)
Lay_NotEnoughMemoryExit ();
return (DB_QueryCOUNT_free (Query,"can not check if a mail domain is allowed for notifications") != 0);
DB_BuildQuery ("SELECT COUNT(*) FROM mail_domains WHERE Domain='%s'",
MailDomain);
return (DB_QueryCOUNT_new ("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)
{
char *Query;
/***** 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",
FieldName,Name,MaiCod) < 0)
Lay_NotEnoughMemoryExit ();
return (DB_QueryCOUNT_free (Query,"can not check if the name of a mail domain already existed") != 0);
FieldName,Name,MaiCod);
return (DB_QueryCOUNT_new ("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;
/***** 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'"
" AND UsrCod<>%ld",
NewEmail,UsrDat->UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
if (DB_QueryCOUNT_free (Query,"can not check if email already existed")) // An email of another user is the same that my email
NewEmail,UsrDat->UsrCod);
if (DB_QueryCOUNT_new ("can not check if email already existed")) // An email of another user is the same that my email
return false; // Don't update
/***** Delete email (not confirmed) for other users *****/

View File

@ -25,10 +25,8 @@
/********************************* Headers ***********************************/
/*****************************************************************************/
#define _GNU_SOURCE // For asprintf
#include <linux/limits.h> // For PATH_MAX
#include <linux/stddef.h> // For NULL
#include <stdio.h> // For asprintf
#include <stdlib.h> // For free
#include <string.h> // For string functions
#include <time.h> // For time
@ -1225,21 +1223,17 @@ void Msg_ConRecMsg (void)
static void Msg_ExpandSentMsg (long MsgCod)
{
char *Query;
/***** Expand message in sent message table *****/
if (asprintf (&Query,"UPDATE msg_snt SET Expanded='Y'"
DB_BuildQuery ("UPDATE msg_snt SET Expanded='Y'"
" WHERE MsgCod=%ld AND UsrCod=%ld",
MsgCod,Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not expand a sent message");
MsgCod,Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryUPDATE_new ("can not expand a sent message");
/***** Contract all my other messages in sent message table *****/
if (asprintf (&Query,"UPDATE msg_snt SET Expanded='N'"
DB_BuildQuery ("UPDATE msg_snt SET Expanded='N'"
" WHERE UsrCod=%ld AND MsgCod<>%ld",
Gbl.Usrs.Me.UsrDat.UsrCod,MsgCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE (Query,"can not contract a sent message");
Gbl.Usrs.Me.UsrDat.UsrCod,MsgCod);
DB_QueryUPDATE_new ("can not contract a sent message");
}
/*****************************************************************************/
@ -1248,21 +1242,17 @@ static void Msg_ExpandSentMsg (long MsgCod)
static void Msg_ExpandReceivedMsg (long MsgCod)
{
char *Query;
/***** Expand message in received message table and mark it as read by me *****/
if (asprintf (&Query,"UPDATE msg_rcv SET Open='Y',Expanded='Y'"
DB_BuildQuery ("UPDATE msg_rcv SET Open='Y',Expanded='Y'"
" WHERE MsgCod=%ld AND UsrCod=%ld",
MsgCod,Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not expand a received message");
MsgCod,Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryUPDATE_new ("can not expand a received message");
/***** Contract all my other messages in received message table *****/
if (asprintf (&Query,"UPDATE msg_rcv SET Expanded='N'"
DB_BuildQuery ("UPDATE msg_rcv SET Expanded='N'"
" WHERE UsrCod=%ld AND MsgCod<>%ld",
Gbl.Usrs.Me.UsrDat.UsrCod,MsgCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not contract a received message");
Gbl.Usrs.Me.UsrDat.UsrCod,MsgCod);
DB_QueryUPDATE_new ("can not contract a received message");
}
/*****************************************************************************/
@ -1271,14 +1261,11 @@ static void Msg_ExpandReceivedMsg (long MsgCod)
static void Msg_ContractSentMsg (long MsgCod)
{
char *Query;
/***** Contract message in sent message table *****/
if (asprintf (&Query,"UPDATE msg_snt SET Expanded='N'"
DB_BuildQuery ("UPDATE msg_snt SET Expanded='N'"
" WHERE MsgCod=%ld AND UsrCod=%ld",
MsgCod,Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not contract a sent message");
MsgCod,Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryUPDATE_new ("can not contract a sent message");
}
/*****************************************************************************/
@ -1287,14 +1274,11 @@ static void Msg_ContractSentMsg (long MsgCod)
static void Msg_ContractReceivedMsg (long MsgCod)
{
char *Query;
/***** Contract message in received message table *****/
if (asprintf (&Query,"UPDATE msg_rcv SET Expanded='N'"
DB_BuildQuery ("UPDATE msg_rcv SET Expanded='N'"
" WHERE MsgCod=%ld AND UsrCod=%ld",
MsgCod,Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not contract a received message");
MsgCod,Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryUPDATE_new ("can not contract a received message");
}
/*****************************************************************************/
@ -1303,14 +1287,11 @@ static void Msg_ContractReceivedMsg (long MsgCod)
void Msg_SetReceivedMsgAsOpen (long MsgCod,long UsrCod)
{
char *Query;
/***** Mark message as read by user *****/
if (asprintf (&Query,"UPDATE msg_rcv SET Open='Y'"
DB_BuildQuery ("UPDATE msg_rcv SET Open='Y'"
" WHERE MsgCod=%ld AND UsrCod=%ld",
MsgCod,UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not mark a received message as open");
MsgCod,UsrCod);
DB_QueryUPDATE_new ("can not mark a received message as open");
}
/*****************************************************************************/
@ -1321,7 +1302,6 @@ void Msg_SetReceivedMsgAsOpen (long MsgCod,long UsrCod)
static long Msg_InsertNewMsg (const char *Subject,const char *Content,
struct Image *Image)
{
char *Query;
long MsgCod;
/***** Check if image is received and processed *****/
@ -1331,27 +1311,25 @@ static long Msg_InsertNewMsg (const char *Subject,const char *Content,
Img_MoveImageToDefinitiveDirectory (Image);
/***** Insert message subject and content in the database *****/
if (asprintf (&Query,"INSERT INTO msg_content"
DB_BuildQuery ("INSERT INTO msg_content"
" (Subject,Content,ImageName,ImageTitle,ImageURL)"
" VALUES"
" ('%s','%s','%s','%s','%s')",
Subject,Content,
Image->Name,
Image->Title ? Image->Title : "",
Image->URL ? Image->URL : "") < 0)
Lay_NotEnoughMemoryExit ();
MsgCod = DB_QueryINSERTandReturnCode_free (Query,"can not create message");
Image->URL ? Image->URL : "");
MsgCod = DB_QueryINSERTandReturnCode_new ("can not create message");
/***** Insert message in sent messages *****/
if (asprintf (&Query,"INSERT INTO msg_snt"
DB_BuildQuery ("INSERT INTO msg_snt"
" (MsgCod,CrsCod,UsrCod,Expanded,CreatTime)"
" VALUES"
" (%ld,%ld,%ld,'N',NOW())",
MsgCod,
Gbl.CurrentCrs.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryINSERT_free (Query,"can not create message");
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryINSERT_new ("can not create message");
/***** Increment number of messages sent by me *****/
Prf_IncrementNumMsgSntUsr (Gbl.Usrs.Me.UsrDat.UsrCod);
@ -1410,36 +1388,30 @@ static unsigned long Msg_DelSomeRecOrSntMsgsUsr (Msg_TypeOfMessages_t TypeOfMess
void Msg_DelAllRecAndSntMsgsUsr (long UsrCod)
{
char *Query;
/***** Move messages from msg_rcv to msg_rcv_deleted *****/
/* Insert messages into msg_rcv_deleted */
if (asprintf (&Query,"INSERT IGNORE INTO msg_rcv_deleted"
DB_BuildQuery ("INSERT IGNORE INTO msg_rcv_deleted"
" (MsgCod,UsrCod,Notified,Open,Replied)"
" SELECT MsgCod,UsrCod,Notified,Open,Replied FROM msg_rcv WHERE UsrCod=%ld",
UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryINSERT_free (Query,"can not remove received messages");
UsrCod);
DB_QueryINSERT_new ("can not remove received messages");
/* Delete messages from msg_rcv *****/
if (asprintf (&Query,"DELETE FROM msg_rcv WHERE UsrCod=%ld",UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove received messages");
DB_BuildQuery ("DELETE FROM msg_rcv WHERE UsrCod=%ld",UsrCod);
DB_QueryDELETE_new ("can not remove received messages");
/***** Move message from msg_snt to msg_snt_deleted *****/
/* Insert message into msg_snt_deleted */
if (asprintf (&Query,"INSERT IGNORE INTO msg_snt_deleted"
DB_BuildQuery ("INSERT IGNORE INTO msg_snt_deleted"
" (MsgCod,CrsCod,UsrCod,CreatTime)"
" SELECT MsgCod,CrsCod,UsrCod,CreatTime"
" FROM msg_snt WHERE UsrCod=%ld",
UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryINSERT_free (Query,"can not remove sent messages");
UsrCod);
DB_QueryINSERT_new ("can not remove sent messages");
/* Delete message from msg_snt *****/
if (asprintf (&Query,"DELETE FROM msg_snt WHERE UsrCod=%ld",UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove sent messages");
DB_BuildQuery ("DELETE FROM msg_snt WHERE UsrCod=%ld",UsrCod);
DB_QueryDELETE_new ("can not remove sent messages");
}
/*****************************************************************************/
@ -1448,18 +1420,15 @@ void Msg_DelAllRecAndSntMsgsUsr (long UsrCod)
static void Msg_InsertReceivedMsgIntoDB (long MsgCod,long UsrCod,bool NotifyByEmail)
{
char *Query;
/***** Insert message received in the database *****/
if (asprintf (&Query,"INSERT INTO msg_rcv"
DB_BuildQuery ("INSERT INTO msg_rcv"
" (MsgCod,UsrCod,Notified,Open,Replied,Expanded)"
" VALUES"
" (%ld,%ld,'%c','N','N','N')",
MsgCod,UsrCod,
NotifyByEmail ? 'Y' :
'N') < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryINSERT_free (Query,"can not create received message");
'N');
DB_QueryINSERT_new ("can not create received message");
}
/*****************************************************************************/
@ -1468,14 +1437,11 @@ static void Msg_InsertReceivedMsgIntoDB (long MsgCod,long UsrCod,bool NotifyByEm
static void Msg_SetReceivedMsgAsReplied (long MsgCod)
{
char *Query;
/***** Update received message by setting Replied field to true *****/
if (asprintf (&Query,"UPDATE msg_rcv SET Replied='Y'"
DB_BuildQuery ("UPDATE msg_rcv SET Replied='Y'"
" WHERE MsgCod=%ld AND UsrCod=%ld",
MsgCod,Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not update a received message");
MsgCod,Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryUPDATE_new ("can not update a received message");
}
/*****************************************************************************/
@ -1484,23 +1450,19 @@ static void Msg_SetReceivedMsgAsReplied (long MsgCod)
static void Msg_MoveReceivedMsgToDeleted (long MsgCod,long UsrCod)
{
char *Query;
/***** Move message from msg_rcv to msg_rcv_deleted *****/
/* Insert message into msg_rcv_deleted */
if (asprintf (&Query,"INSERT IGNORE INTO msg_rcv_deleted"
DB_BuildQuery ("INSERT IGNORE INTO msg_rcv_deleted"
" (MsgCod,UsrCod,Notified,Open,Replied)"
" SELECT MsgCod,UsrCod,Notified,Open,Replied"
" FROM msg_rcv WHERE MsgCod=%ld AND UsrCod=%ld",
MsgCod,UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryINSERT_free (Query,"can not remove a received message");
MsgCod,UsrCod);
DB_QueryINSERT_new ("can not remove a received message");
/* Delete message from msg_rcv *****/
if (asprintf (&Query,"DELETE FROM msg_rcv WHERE MsgCod=%ld AND UsrCod=%ld",
MsgCod,UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove a received message");
DB_BuildQuery ("DELETE FROM msg_rcv WHERE MsgCod=%ld AND UsrCod=%ld",
MsgCod,UsrCod);
DB_QueryDELETE_new ("can not remove a received message");
/***** If message content is not longer necessary, move it to msg_content_deleted *****/
if (Msg_CheckIfSentMsgIsDeleted (MsgCod))
@ -1517,22 +1479,18 @@ static void Msg_MoveReceivedMsgToDeleted (long MsgCod,long UsrCod)
static void Msg_MoveSentMsgToDeleted (long MsgCod)
{
char *Query;
/***** Move message from msg_snt to msg_snt_deleted *****/
/* Insert message into msg_snt_deleted */
if (asprintf (&Query,"INSERT IGNORE INTO msg_snt_deleted"
DB_BuildQuery ("INSERT IGNORE INTO msg_snt_deleted"
" (MsgCod,CrsCod,UsrCod,CreatTime)"
" SELECT MsgCod,CrsCod,UsrCod,CreatTime"
" FROM msg_snt WHERE MsgCod=%ld",
MsgCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryINSERT_free (Query,"can not remove a sent message");
MsgCod);
DB_QueryINSERT_new ("can not remove a sent message");
/* Delete message from msg_snt *****/
if (asprintf (&Query,"DELETE FROM msg_snt WHERE MsgCod=%ld",MsgCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove a sent message");
DB_BuildQuery ("DELETE FROM msg_snt WHERE MsgCod=%ld",MsgCod);
DB_QueryDELETE_new ("can not remove a sent message");
/***** If message content is not longer necessary, move it to msg_content_deleted *****/
if (Msg_CheckIfReceivedMsgIsDeletedForAllItsRecipients (MsgCod))
@ -1545,25 +1503,21 @@ static void Msg_MoveSentMsgToDeleted (long MsgCod)
static void Msg_MoveMsgContentToDeleted (long MsgCod)
{
char *Query;
/***** Move message from msg_content to msg_content_deleted *****/
/* Insert message content into msg_content_deleted */
if (asprintf (&Query,"INSERT IGNORE INTO msg_content_deleted"
DB_BuildQuery ("INSERT IGNORE INTO msg_content_deleted"
" (MsgCod,Subject,Content,ImageName,ImageTitle,ImageURL)"
" SELECT MsgCod,Subject,Content,ImageName,ImageTitle,ImageURL"
" FROM msg_content WHERE MsgCod=%ld",
MsgCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryINSERT_free (Query,"can not remove the content of a message");
MsgCod);
DB_QueryINSERT_new ("can not remove the content of a message");
/* TODO: Messages in msg_content_deleted older than a certain time
should be deleted to ensure the protection of personal data */
/* Delete message from msg_content *****/
if (asprintf (&Query,"DELETE FROM msg_content WHERE MsgCod=%ld",MsgCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not remove the content of a message");
DB_BuildQuery ("DELETE FROM msg_content WHERE MsgCod=%ld",MsgCod);
DB_QueryUPDATE_new ("can not remove the content of a message");
}
/*****************************************************************************/
@ -1572,27 +1526,23 @@ static void Msg_MoveMsgContentToDeleted (long MsgCod)
void Msg_MoveUnusedMsgsContentToDeleted (void)
{
char *Query;
/***** Move messages from msg_content to msg_content_deleted *****/
/* Insert message content into msg_content_deleted */
if (asprintf (&Query,"INSERT IGNORE INTO msg_content_deleted"
DB_BuildQuery ("INSERT IGNORE INTO msg_content_deleted"
" (MsgCod,Subject,Content)"
" SELECT MsgCod,Subject,Content FROM msg_content"
" WHERE MsgCod NOT IN (SELECT MsgCod FROM msg_snt)"
" AND MsgCod NOT IN (SELECT DISTINCT MsgCod FROM msg_rcv)") < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryINSERT_free (Query,"can not remove the content of some messages");
" AND MsgCod NOT IN (SELECT DISTINCT MsgCod FROM msg_rcv)");
DB_QueryINSERT_new ("can not remove the content of some messages");
/* Messages in msg_content_deleted older than a certain time
should be deleted to ensure the protection of personal data */
/* Delete message from msg_content *****/
if (asprintf (&Query,"DELETE FROM msg_content"
DB_BuildQuery ("DELETE FROM msg_content"
" WHERE MsgCod NOT IN (SELECT MsgCod FROM msg_snt)"
" AND MsgCod NOT IN (SELECT DISTINCT MsgCod FROM msg_rcv)") < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryUPDATE_free (Query,"can not remove the content of some messages");
" AND MsgCod NOT IN (SELECT DISTINCT MsgCod FROM msg_rcv)");
DB_QueryUPDATE_new ("can not remove the content of some messages");
}
/*****************************************************************************/
@ -1601,13 +1551,10 @@ void Msg_MoveUnusedMsgsContentToDeleted (void)
static bool Msg_CheckIfSentMsgIsDeleted (long MsgCod)
{
char *Query;
/***** Get if the message code is in table of sent messages not deleted *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM msg_snt"
" WHERE MsgCod=%ld",MsgCod) < 0)
Lay_NotEnoughMemoryExit ();
return (DB_QueryCOUNT_free (Query,"can not check if a sent message is deleted") == 0); // The message has been deleted by its author when it is not present in table of sent messages undeleted
DB_BuildQuery ("SELECT COUNT(*) FROM msg_snt"
" WHERE MsgCod=%ld",MsgCod);
return (DB_QueryCOUNT_new ("can not check if a sent message is deleted") == 0); // The message has been deleted by its author when it is not present in table of sent messages undeleted
}
/*****************************************************************************/
@ -1616,13 +1563,10 @@ static bool Msg_CheckIfSentMsgIsDeleted (long MsgCod)
static bool Msg_CheckIfReceivedMsgIsDeletedForAllItsRecipients (long MsgCod)
{
char *Query;
/***** Get if the message code is in table of received messages not deleted *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM msg_rcv"
" WHERE MsgCod=%ld",MsgCod) < 0)
Lay_NotEnoughMemoryExit ();
return (DB_QueryCOUNT_free (Query,"can not check if a received message is deleted by all recipients") == 0); // The message has been deleted by all its recipients when it is not present in table of received messages undeleted
DB_BuildQuery ("SELECT COUNT(*) FROM msg_rcv"
" WHERE MsgCod=%ld",MsgCod);
return (DB_QueryCOUNT_new ("can not check if a received message is deleted by all recipients") == 0); // The message has been deleted by all its recipients when it is not present in table of received messages undeleted
}
/*****************************************************************************/
@ -1632,7 +1576,6 @@ static bool Msg_CheckIfReceivedMsgIsDeletedForAllItsRecipients (long MsgCod)
static unsigned Msg_GetNumUnreadMsgs (long FilterCrsCod,const char *FilterFromToSubquery)
{
char SubQuery[Msg_MAX_BYTES_MESSAGES_QUERY + 1];
char *Query;
/***** Get number of unread messages from database *****/
if (FilterCrsCod >= 0) // If origin course selected
@ -1670,21 +1613,15 @@ static unsigned Msg_GetNumUnreadMsgs (long FilterCrsCod,const char *FilterFromTo
}
if (Gbl.Msg.FilterContent[0])
{
if (asprintf (&Query,"SELECT COUNT(*) FROM msg_content"
DB_BuildQuery ("SELECT COUNT(*) FROM msg_content"
" WHERE MsgCod IN (%s)"
" AND MATCH (Subject,Content) AGAINST ('%s')",
SubQuery,
Gbl.Msg.FilterContent) < 0)
Lay_NotEnoughMemoryExit ();
}
Gbl.Msg.FilterContent);
else
{
if (asprintf (&Query,"SELECT COUNT(*) FROM (%s) AS T",
SubQuery) < 0)
Lay_NotEnoughMemoryExit ();
}
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of unread messages");
DB_BuildQuery ("SELECT COUNT(*) FROM (%s) AS T",
SubQuery);
return (unsigned) DB_QueryCOUNT_new ("can not get number of unread messages");
}
/*****************************************************************************/
@ -1897,13 +1834,10 @@ static void Msg_ShowSentOrReceivedMessages (void)
static unsigned long Msg_GetNumUsrsBannedByMe (void)
{
char *Query;
/***** Get number of users I have banned *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM msg_banned WHERE ToUsrCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
return DB_QueryCOUNT_free (Query,"can not get number of users you have banned");
DB_BuildQuery ("SELECT COUNT(*) FROM msg_banned WHERE ToUsrCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod);
return DB_QueryCOUNT_new ("can not get number of users you have banned");
}
/*****************************************************************************/
@ -2074,15 +2008,12 @@ static void Msg_ConstructQueryToSelectSentOrReceivedMsgs (char Query[Msg_MAX_BYT
unsigned Msg_GetNumMsgsSentByTchsCrs (long CrsCod)
{
char *Query;
/***** Get the number of unique messages sent by any teacher from this course *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM msg_snt,crs_usr"
DB_BuildQuery ("SELECT COUNT(*) FROM msg_snt,crs_usr"
" WHERE msg_snt.CrsCod=%ld AND crs_usr.CrsCod=%ld AND crs_usr.Role=%u"
" AND msg_snt.UsrCod=crs_usr.UsrCod",
CrsCod,CrsCod,(unsigned) Rol_TCH) < 0)
Lay_NotEnoughMemoryExit ();
return (unsigned) DB_QueryCOUNT_free (Query,"can not get the number of messages sent by teachers");
CrsCod,CrsCod,(unsigned) Rol_TCH);
return (unsigned) DB_QueryCOUNT_new ("can not get the number of messages sent by teachers");
}
/*****************************************************************************/
@ -2091,17 +2022,14 @@ unsigned Msg_GetNumMsgsSentByTchsCrs (long CrsCod)
unsigned long Msg_GetNumMsgsSentByUsr (long UsrCod)
{
char *Query;
/***** Get the number of unique messages sent by any teacher from this course *****/
if (asprintf (&Query,"SELECT"
DB_BuildQuery ("SELECT"
" (SELECT COUNT(*) FROM msg_snt WHERE UsrCod=%ld)"
" +"
" (SELECT COUNT(*) FROM msg_snt_deleted WHERE UsrCod=%ld)",
UsrCod,
UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
return DB_QueryCOUNT_free (Query,"can not get the number of messages sent by a user");
UsrCod);
return DB_QueryCOUNT_new ("can not get the number of messages sent by a user");
}
/*****************************************************************************/
@ -2112,7 +2040,6 @@ unsigned long Msg_GetNumMsgsSentByUsr (long UsrCod)
unsigned Msg_GetNumMsgsSent (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
{
const char *Table = "msg_snt";
char *Query;
/***** Get the number of messages sent from this location
(all the platform, current degree or current course) from database *****/
@ -2129,12 +2056,11 @@ unsigned Msg_GetNumMsgsSent (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
switch (Scope)
{
case Sco_SCOPE_SYS:
if (asprintf (&Query,"SELECT COUNT(*) FROM %s",
Table) < 0)
Lay_NotEnoughMemoryExit ();
DB_BuildQuery ("SELECT COUNT(*) FROM %s",
Table);
break;
case Sco_SCOPE_CTY:
if (asprintf (&Query,"SELECT COUNT(*)"
DB_BuildQuery ("SELECT COUNT(*)"
" FROM institutions,centres,degrees,courses,%s"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
@ -2143,11 +2069,10 @@ unsigned Msg_GetNumMsgsSent (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
" AND courses.CrsCod=%s.CrsCod",
Table,
Gbl.CurrentCty.Cty.CtyCod,
Table) < 0)
Lay_NotEnoughMemoryExit ();
Table);
break;
case Sco_SCOPE_INS:
if (asprintf (&Query,"SELECT COUNT(*)"
DB_BuildQuery ("SELECT COUNT(*)"
" FROM centres,degrees,courses,%s"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
@ -2155,43 +2080,39 @@ unsigned Msg_GetNumMsgsSent (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
" AND courses.CrsCod=%s.CrsCod",
Table,
Gbl.CurrentIns.Ins.InsCod,
Table) < 0)
Lay_NotEnoughMemoryExit ();
Table);
break;
case Sco_SCOPE_CTR:
if (asprintf (&Query,"SELECT COUNT(*)"
DB_BuildQuery ("SELECT COUNT(*)"
" FROM degrees,courses,%s"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
" AND courses.CrsCod=%s.CrsCod",
Table,
Gbl.CurrentCtr.Ctr.CtrCod,
Table) < 0)
Lay_NotEnoughMemoryExit ();
Table);
break;
case Sco_SCOPE_DEG:
if (asprintf (&Query,"SELECT COUNT(*)"
DB_BuildQuery ("SELECT COUNT(*)"
" FROM courses,%s"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=%s.CrsCod",
Table,
Gbl.CurrentDeg.Deg.DegCod,
Table) < 0)
Lay_NotEnoughMemoryExit ();
Table);
break;
case Sco_SCOPE_CRS:
if (asprintf (&Query,"SELECT COUNT(*)"
DB_BuildQuery ("SELECT COUNT(*)"
" FROM %s"
" WHERE CrsCod=%ld",
Table,
Gbl.CurrentCrs.Crs.CrsCod) < 0)
Lay_NotEnoughMemoryExit ();
Gbl.CurrentCrs.Crs.CrsCod);
break;
default:
Lay_WrongScopeExit ();
break;
}
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of sent messages");
return (unsigned) DB_QueryCOUNT_new ("can not get number of sent messages");
}
/*****************************************************************************/
@ -2202,7 +2123,6 @@ unsigned Msg_GetNumMsgsSent (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
{
char *Table;
char *Query;
/***** Get the number of unique messages sent from this location
(all the platform, current degree or current course) from database *****/
@ -2215,12 +2135,11 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
switch (Scope)
{
case Sco_SCOPE_SYS:
if (asprintf (&Query,"SELECT COUNT(*) FROM %s",
Table) < 0)
Lay_NotEnoughMemoryExit ();
DB_BuildQuery ("SELECT COUNT(*) FROM %s",
Table);
break;
case Sco_SCOPE_CTY:
if (asprintf (&Query,"SELECT COUNT(*)"
DB_BuildQuery ("SELECT COUNT(*)"
" FROM institutions,centres,degrees,courses,%s,msg_snt"
" WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod"
@ -2230,11 +2149,10 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
" AND msg_snt.MsgCod=%s.MsgCod",
Table,
Gbl.CurrentCty.Cty.CtyCod,
Table) < 0)
Lay_NotEnoughMemoryExit ();
Table);
break;
case Sco_SCOPE_INS:
if (asprintf (&Query,"SELECT COUNT(*)"
DB_BuildQuery ("SELECT COUNT(*)"
" FROM centres,degrees,courses,%s,msg_snt"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=degrees.CtrCod"
@ -2243,11 +2161,10 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
" AND msg_snt.MsgCod=%s.MsgCod",
Table,
Gbl.CurrentIns.Ins.InsCod,
Table) < 0)
Lay_NotEnoughMemoryExit ();
Table);
break;
case Sco_SCOPE_CTR:
if (asprintf (&Query,"SELECT COUNT(*)"
DB_BuildQuery ("SELECT COUNT(*)"
" FROM degrees,courses,%s,msg_snt"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod"
@ -2255,29 +2172,26 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
" AND msg_snt.MsgCod=%s.MsgCod",
Table,
Gbl.CurrentCtr.Ctr.CtrCod,
Table) < 0)
Lay_NotEnoughMemoryExit ();
Table);
break;
case Sco_SCOPE_DEG:
if (asprintf (&Query,"SELECT COUNT(*)"
DB_BuildQuery ("SELECT COUNT(*)"
" FROM courses,%s,msg_snt"
" WHERE courses.DegCod=%ld"
" AND courses.CrsCod=msg_snt.CrsCod"
" AND msg_snt.MsgCod=%s.MsgCod",
Table,
Gbl.CurrentDeg.Deg.DegCod,
Table) < 0)
Lay_NotEnoughMemoryExit ();
Table);
break;
case Sco_SCOPE_CRS:
if (asprintf (&Query,"SELECT COUNT(*)"
DB_BuildQuery ("SELECT COUNT(*)"
" FROM msg_snt,%s"
" WHERE msg_snt.CrsCod=%ld"
" AND msg_snt.MsgCod=%s.MsgCod",
Table,
Gbl.CurrentCrs.Crs.CrsCod,
Table) < 0)
Lay_NotEnoughMemoryExit ();
Table);
break;
default:
Lay_WrongScopeExit ();
@ -2288,18 +2202,17 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
switch (Scope)
{
case Sco_SCOPE_SYS:
if (asprintf (&Query,"SELECT "
DB_BuildQuery ("SELECT "
"(SELECT COUNT(*)"
" FROM msg_rcv"
" WHERE Notified='Y')"
" + "
"(SELECT COUNT(*)"
" FROM msg_rcv_deleted"
" WHERE Notified='Y')") < 0)
Lay_NotEnoughMemoryExit ();
" WHERE Notified='Y')");
break;
case Sco_SCOPE_CTY:
if (asprintf (&Query,"SELECT "
DB_BuildQuery ("SELECT "
"(SELECT COUNT(*)"
" FROM institutions,centres,degrees,courses,msg_snt,msg_rcv"
" WHERE institutions.CtyCod=%ld"
@ -2320,11 +2233,10 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
" AND msg_rcv_deleted.Notified='Y')",
Gbl.CurrentCty.Cty.CtyCod,
Gbl.CurrentCty.Cty.CtyCod) < 0)
Lay_NotEnoughMemoryExit ();
Gbl.CurrentCty.Cty.CtyCod);
break;
case Sco_SCOPE_INS:
if (asprintf (&Query,"SELECT "
DB_BuildQuery ("SELECT "
"(SELECT COUNT(*)"
" FROM centres,degrees,courses,msg_snt,msg_rcv"
" WHERE centres.InsCod=%ld"
@ -2343,11 +2255,10 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
" AND msg_rcv_deleted.Notified='Y')",
Gbl.CurrentIns.Ins.InsCod,
Gbl.CurrentIns.Ins.InsCod) < 0)
Lay_NotEnoughMemoryExit ();
Gbl.CurrentIns.Ins.InsCod);
break;
case Sco_SCOPE_CTR:
if (asprintf (&Query,"SELECT "
DB_BuildQuery ("SELECT "
"(SELECT COUNT(*)"
" FROM degrees,courses,msg_snt,msg_rcv"
" WHERE degrees.CtrCod=%ld"
@ -2364,11 +2275,10 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
" AND msg_rcv_deleted.Notified='Y')",
Gbl.CurrentCtr.Ctr.CtrCod,
Gbl.CurrentCtr.Ctr.CtrCod) < 0)
Lay_NotEnoughMemoryExit ();
Gbl.CurrentCtr.Ctr.CtrCod);
break;
case Sco_SCOPE_DEG:
if (asprintf (&Query,"SELECT "
DB_BuildQuery ("SELECT "
"(SELECT COUNT(*)"
" FROM courses,msg_snt,msg_rcv"
" WHERE courses.DegCod=%ld"
@ -2383,11 +2293,10 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
" AND msg_rcv_deleted.Notified='Y')",
Gbl.CurrentDeg.Deg.DegCod,
Gbl.CurrentDeg.Deg.DegCod) < 0)
Lay_NotEnoughMemoryExit ();
Gbl.CurrentDeg.Deg.DegCod);
break;
case Sco_SCOPE_CRS:
if (asprintf (&Query,"SELECT "
DB_BuildQuery ("SELECT "
"(SELECT COUNT(*)"
" FROM msg_snt,msg_rcv"
" WHERE msg_snt.CrsCod=%ld"
@ -2400,8 +2309,7 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
" AND msg_snt.MsgCod=msg_rcv_deleted.MsgCod"
" AND msg_rcv_deleted.Notified='Y')",
Gbl.CurrentCrs.Crs.CrsCod,
Gbl.CurrentCrs.Crs.CrsCod) < 0)
Lay_NotEnoughMemoryExit ();
Gbl.CurrentCrs.Crs.CrsCod);
break;
default:
Lay_WrongScopeExit ();
@ -2409,7 +2317,7 @@ unsigned Msg_GetNumMsgsReceived (Sco_Scope_t Scope,Msg_Status_t MsgStatus)
}
break;
}
return (unsigned) DB_QueryCOUNT_free (Query,"can not get number of received messages");
return (unsigned) DB_QueryCOUNT_new ("can not get number of received messages");
}
/*****************************************************************************/
@ -3408,7 +3316,6 @@ static void Msg_WriteMsgTo (long MsgCod)
extern const char *Txt_and_X_other_recipients;
extern const char *Txt_unknown_recipient;
extern const char *Txt_unknown_recipients;
char *Query;
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumRcp;
@ -3430,13 +3337,12 @@ static void Msg_WriteMsgTo (long MsgCod)
};
/***** Get number of recipients of a message from database *****/
if (asprintf (&Query,"SELECT "
DB_BuildQuery ("SELECT "
"(SELECT COUNT(*) FROM msg_rcv WHERE MsgCod=%ld)"
" + "
"(SELECT COUNT(*) FROM msg_rcv_deleted WHERE MsgCod=%ld)",
MsgCod,MsgCod) < 0)
Lay_NotEnoughMemoryExit ();
NumRecipientsTotal = (unsigned) DB_QueryCOUNT_free (Query,"can not get number of recipients");
MsgCod,MsgCod);
NumRecipientsTotal = (unsigned) DB_QueryCOUNT_new ("can not get number of recipients");
/***** Get recipients of a message from database *****/
DB_BuildQuery ("(SELECT msg_rcv.UsrCod,'N',msg_rcv.Open,"
@ -3685,7 +3591,6 @@ static void Msg_PutFormToUnbanSender (struct UsrData *UsrDat)
void Msg_BanSenderWhenShowingMsgs (void)
{
extern const char *Txt_From_this_time_you_will_not_receive_messages_from_X;
char *Query;
/***** Get user's code from form *****/
Usr_GetParamOtherUsrCodEncryptedAndGetListIDs ();
@ -3695,13 +3600,12 @@ void Msg_BanSenderWhenShowingMsgs (void)
Lay_ShowErrorAndExit ("Sender does not exist.");
/***** Insert pair (sender's code - my code) in table of banned senders if not inserted *****/
if (asprintf (&Query,"REPLACE INTO msg_banned"
DB_BuildQuery ("REPLACE INTO msg_banned"
" (FromUsrCod,ToUsrCod)"
" VALUES"
" (%ld,%ld)",
Gbl.Usrs.Other.UsrDat.UsrCod,Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryREPLACE_free (Query,"can not ban sender");
Gbl.Usrs.Other.UsrDat.UsrCod,Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryREPLACE_new ("can not ban sender");
/***** Show alert with the change made *****/
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
@ -3746,7 +3650,6 @@ void Msg_UnbanSenderWhenListingUsrs (void)
static void Msg_UnbanSender (void)
{
extern const char *Txt_From_this_time_you_can_receive_messages_from_X;
char *Query;
/***** Get user's code from form *****/
Usr_GetParamOtherUsrCodEncryptedAndGetListIDs ();
@ -3756,11 +3659,10 @@ static void Msg_UnbanSender (void)
Lay_ShowErrorAndExit ("Sender does not exist.");
/***** Remove pair (sender's code - my code) from table of banned senders *****/
if (asprintf (&Query,"DELETE FROM msg_banned"
DB_BuildQuery ("DELETE FROM msg_banned"
" WHERE FromUsrCod=%ld AND ToUsrCod=%ld",
Gbl.Usrs.Other.UsrDat.UsrCod,Gbl.Usrs.Me.UsrDat.UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not ban sender");
Gbl.Usrs.Other.UsrDat.UsrCod,Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryDELETE_new ("can not ban sender");
/***** Show alert with the change made *****/
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
@ -3775,14 +3677,11 @@ static void Msg_UnbanSender (void)
static bool Msg_CheckIfUsrIsBanned (long FromUsrCod,long ToUsrCod)
{
char *Query;
/***** Get if FromUsrCod is banned by ToUsrCod *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM msg_banned"
DB_BuildQuery ("SELECT COUNT(*) FROM msg_banned"
" WHERE FromUsrCod=%ld AND ToUsrCod=%ld",
FromUsrCod,ToUsrCod) < 0)
Lay_NotEnoughMemoryExit ();
return (DB_QueryCOUNT_free (Query,"can not check if a user is banned") != 0);
FromUsrCod,ToUsrCod);
return (DB_QueryCOUNT_new ("can not check if a user is banned") != 0);
}
/*****************************************************************************/
@ -3791,15 +3690,12 @@ static bool Msg_CheckIfUsrIsBanned (long FromUsrCod,long ToUsrCod)
void Msg_RemoveUsrFromBanned (long UsrCod)
{
char *Query;
/***** Remove pair (sender's code - my code)
from table of banned senders *****/
if (asprintf (&Query,"DELETE FROM msg_banned"
DB_BuildQuery ("DELETE FROM msg_banned"
" WHERE FromUsrCod=%ld OR ToUsrCod=%ld",
UsrCod,UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
DB_QueryDELETE_free (Query,"can not remove user from table of banned users");
UsrCod,UsrCod);
DB_QueryDELETE_new ("can not remove user from table of banned users");
}
/*****************************************************************************/

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_has_been_registered_successfully;
extern const char *Txt_The_nickname_entered_X_is_not_valid_;
char *Query;
char NewNicknameWithArroba[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
{
/***** 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'",
UsrDat->UsrCod,NewNicknameWithoutArroba) < 0)
Lay_NotEnoughMemoryExit ();
if (!DB_QueryCOUNT_free (Query,"can not check if nickname already existed")) // No matches
UsrDat->UsrCod,NewNicknameWithoutArroba);
if (!DB_QueryCOUNT_new ("can not check if nickname already existed")) // No matches
{
/***** 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",
NewNicknameWithoutArroba,UsrDat->UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
if (DB_QueryCOUNT_free (Query,"can not check if nickname already existed")) // A nickname of another user is the same that user's nickname
NewNicknameWithoutArroba,UsrDat->UsrCod);
if (DB_QueryCOUNT_new ("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.Section = Nck_NICKNAME_SECTION_ID;

View File

@ -2120,15 +2120,12 @@ void Ntf_WriteNumberOfNewNtfs (void)
static unsigned Ntf_GetNumberOfAllMyUnseenNtfs (void)
{
char *Query;
/***** 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",
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED)) < 0)
Lay_NotEnoughMemoryExit ();
return DB_QueryCOUNT_free (Query,"can not get number of unseen notifications");
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED));
return DB_QueryCOUNT_new ("can not get number of unseen notifications");
}
/*****************************************************************************/
@ -2137,17 +2134,14 @@ static unsigned Ntf_GetNumberOfAllMyUnseenNtfs (void)
static unsigned Ntf_GetNumberOfMyNewUnseenNtfs (void)
{
char *Query;
/***** 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"
" AND TimeNotif>FROM_UNIXTIME(%ld)",
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) (Ntf_STATUS_BIT_READ | Ntf_STATUS_BIT_REMOVED),
Gbl.Usrs.Me.UsrLast.LastAccNotif) < 0)
Lay_NotEnoughMemoryExit ();
return DB_QueryCOUNT_free (Query,"can not get number of unseen notifications");
Gbl.Usrs.Me.UsrLast.LastAccNotif);
return DB_QueryCOUNT_new ("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)
{
char *Query;
bool Found;
/***** Get if password is found in user's ID from database *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_IDs WHERE UsrID='%s'",
PlainPassword) < 0)
Lay_NotEnoughMemoryExit ();
Found = (DB_QueryCOUNT_free (Query,"can not check if a password matches a user's ID") != 0);
DB_BuildQuery ("SELECT COUNT(*) FROM usr_IDs WHERE UsrID='%s'",
PlainPassword);
Found = (DB_QueryCOUNT_new ("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 *****/
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'",
PlainPassword,PlainPassword,PlainPassword) < 0)
Lay_NotEnoughMemoryExit ();
Found = (DB_QueryCOUNT_free (Query,"can not check if a password matches a first name or a surname") != 0);
PlainPassword,PlainPassword,PlainPassword);
Found = (DB_QueryCOUNT_new ("can not check if a password matches a first name or a surname") != 0);
}
return Found;
@ -606,25 +603,17 @@ static bool Pwd_CheckIfPasswdIsUsrIDorName (const char *PlainPassword)
static unsigned Pwd_GetNumOtherUsrsWhoUseThisPassword (const char *EncryptedPassword,long UsrCod)
{
char *Query;
/***** Get number of other users who use a password from database *****/
/* Query database */
if (UsrCod > 0)
{
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_data"
DB_BuildQuery ("SELECT COUNT(*) FROM usr_data"
" WHERE Password='%s' AND UsrCod<>%ld",
EncryptedPassword,UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
}
EncryptedPassword,UsrCod);
else
{
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_data"
DB_BuildQuery ("SELECT COUNT(*) FROM usr_data"
" WHERE Password='%s'",
EncryptedPassword) < 0)
Lay_NotEnoughMemoryExit ();
}
return (unsigned) DB_QueryCOUNT_free (Query,"can not check if a password is trivial");
EncryptedPassword);
return (unsigned) DB_QueryCOUNT_new ("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)
{
char *Query;
/***** 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",
Gbl.CurrentIns.Ins.InsCod,FieldName,Name,PlcCod) < 0)
Lay_NotEnoughMemoryExit ();
return (DB_QueryCOUNT_free (Query,"can not check if the name of a place already existed") != 0);
Gbl.CurrentIns.Ins.InsCod,FieldName,Name,PlcCod);
return (DB_QueryCOUNT_new ("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)
{
char *Query;
/***** 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",
Name,PlgCod) < 0)
Lay_NotEnoughMemoryExit ();
return (DB_QueryCOUNT_free (Query,"can not check if the name of a plugin already existed") != 0);
Name,PlgCod);
return (DB_QueryCOUNT_new ("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)
{
char *Query;
/***** Select number of rows with figure
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
" AND %s>"
"(SELECT %s FROM usr_figures WHERE UsrCod=%ld)",
UsrCod,FieldName,FieldName,UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
return DB_QueryCOUNT_free (Query,"can not get ranking using a figure");
UsrCod,FieldName,FieldName,UsrCod);
return DB_QueryCOUNT_new ("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)
{
char *Query;
/***** Select number of rows with values already calculated *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM usr_figures WHERE %s>=0",
FieldName) < 0)
Lay_NotEnoughMemoryExit ();
return DB_QueryCOUNT_free (Query,"can not get number of users with a figure");
DB_BuildQuery ("SELECT COUNT(*) FROM usr_figures WHERE %s>=0",FieldName);
return DB_QueryCOUNT_new ("can not get number of users with a figure");
}
/*****************************************************************************/
@ -713,11 +706,9 @@ static unsigned long Prf_GetNumUsrsWithFigure (const char *FieldName)
static unsigned long Prf_GetRankingNumClicksPerDay (long UsrCod)
{
char *Query;
/***** Select number of rows with number of clicks per day
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)"
" AS NumClicksPerDay"
" FROM usr_figures"
@ -731,9 +722,8 @@ static unsigned long Prf_GetRankingNumClicksPerDay (long UsrCod)
" WHERE UsrCod=%ld"
" AND NumClicks>0"
" AND UNIX_TIMESTAMP(FirstClickTime)>0)",
UsrCod,UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
return DB_QueryCOUNT_free (Query,"can not get ranking using number of clicks per day");
UsrCod,UsrCod);
return DB_QueryCOUNT_new ("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)
{
char *Query;
/***** 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"
" AND UNIX_TIMESTAMP(FirstClickTime)>0") < 0)
Lay_NotEnoughMemoryExit ();
return DB_QueryCOUNT_free (Query,"can not get number of users with number of clicks per day");
" AND UNIX_TIMESTAMP(FirstClickTime)>0");
return DB_QueryCOUNT_new ("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);
/***** Get number of clicks from database *****/
if (asprintf (&Query,"SELECT COUNT(*) FROM log_full WHERE UsrCod=%ld",
UsrCod) < 0)
Lay_NotEnoughMemoryExit ();
UsrFigures.NumClicks = (long) DB_QueryCOUNT_free (Query,"can not get number of clicks");
DB_BuildQuery ("SELECT COUNT(*) FROM log_full WHERE UsrCod=%ld",UsrCod);
UsrFigures.NumClicks = (long) DB_QueryCOUNT_new ("can not get number of clicks");
/***** Update number of clicks in user's figures *****/
if (Prf_CheckIfUsrFiguresExists (UsrCod))
@ -1101,12 +1086,8 @@ void Prf_RemoveUsrFigures (long UsrCod)
static bool Prf_CheckIfUsrFiguresExists (long UsrCod)
{
char *Query;
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);
DB_BuildQuery ("SELECT COUNT(*) FROM usr_figures WHERE UsrCod=%ld",UsrCod);
return (DB_QueryCOUNT_new ("can not get user's first click") != 0);
}
/*****************************************************************************/

View File

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