Version 18.13.3

This commit is contained in:
Antonio Cañas Vargas 2018-11-04 21:28:11 +01:00
parent e7ba3b873a
commit aa53ece0ce
4 changed files with 40 additions and 32 deletions

View File

@ -175,8 +175,8 @@ unsigned ID_GetListUsrCodsFromUsrID (struct UsrData *UsrDat,
struct ListUsrCods *ListUsrCods,
bool OnlyConfirmedIDs)
{
char *Query = NULL;
char SubQuery[256];
char *SubQueryAllUsrs = NULL;
char SubQueryOneUsr[1 + ID_MAX_BYTES_USR_ID + 1 + 1];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
size_t MaxLength;
@ -190,53 +190,54 @@ unsigned ID_GetListUsrCodsFromUsrID (struct UsrData *UsrDat,
if (EncryptedPassword[0])
CheckPassword = true;
/***** Allocate memory for query string *****/
/***** Allocate memory for subquery string *****/
MaxLength = 512 + UsrDat->IDs.Num * (1 + ID_MAX_BYTES_USR_ID + 1) - 1;
if ((Query = (char *) malloc (MaxLength + 1)) == NULL)
if ((SubQueryAllUsrs = (char *) malloc (MaxLength + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
SubQueryAllUsrs[0] = '\0';
/***** Get user's code(s) from database *****/
Str_Copy (Query,CheckPassword ? "SELECT DISTINCT(usr_IDs.UsrCod) FROM usr_IDs,usr_data"
" WHERE usr_IDs.UsrID IN (" :
"SELECT DISTINCT(UsrCod) FROM usr_IDs"
" WHERE UsrID IN (",
MaxLength);
for (NumID = 0;
NumID < UsrDat->IDs.Num;
NumID++)
{
if (NumID)
Str_Concat (Query,",",
Str_Concat (SubQueryAllUsrs,",",
MaxLength);
sprintf (SubQuery,"'%s'",UsrDat->IDs.List[NumID].ID);
sprintf (SubQueryOneUsr,"'%s'",UsrDat->IDs.List[NumID].ID);
Str_Concat (Query,SubQuery,
Str_Concat (SubQueryAllUsrs,SubQueryOneUsr,
MaxLength);
}
Str_Concat (Query,")",
MaxLength);
if (CheckPassword)
{
if (OnlyConfirmedIDs)
Str_Concat (Query," AND usr_IDs.Confirmed='Y'",
MaxLength);
{
// Get user's code if I have written the correct password
// or if password in database is empty (new user)
sprintf (SubQuery," AND usr_IDs.UsrCod=usr_data.UsrCod"
" AND (usr_data.Password='%s' OR usr_data.Password='')",
EncryptedPassword);
Str_Concat (Query,SubQuery,
MaxLength);
}
else if (OnlyConfirmedIDs)
Str_Concat (Query," AND Confirmed='Y'",
MaxLength);
ListUsrCods->NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get user's codes",
"SELECT DISTINCT(usr_IDs.UsrCod) FROM usr_IDs,usr_data"
" WHERE usr_IDs.UsrID IN (%s)"
"%s"
" AND usr_IDs.UsrCod=usr_data.UsrCod"
" AND (usr_data.Password='%s' OR usr_data.Password='')",
SubQueryAllUsrs,
OnlyConfirmedIDs ? " AND usr_IDs.Confirmed='Y'" :
"",
EncryptedPassword);
}
else
ListUsrCods->NumUsrs =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get user's codes",
"SELECT DISTINCT(UsrCod) FROM usr_IDs"
" WHERE UsrID IN (%s)"
"%s",
SubQueryAllUsrs,
OnlyConfirmedIDs ? " AND Confirmed='Y'" :
"");
ListUsrCods->NumUsrs =
(unsigned) DB_QuerySELECTusingQueryStr (&Query,&mysql_res,
"can not get user's codes");
/***** Free memory for subquery string *****/
free ((void *) SubQueryAllUsrs);
if (ListUsrCods->NumUsrs)
{

View File

@ -2487,6 +2487,9 @@ static unsigned Att_GetNumStdsFromAListWhoAreInAttEvent (long AttCod,long LstSel
" WHERE AttCod=%ld"
" AND UsrCod IN (%s) AND Present='Y'",
AttCod,SubQueryAllUsrs);
/***** Free memory for subquery string *****/
free ((void *) SubQueryAllUsrs);
}
return NumStdsInAttEvent;
}

View File

@ -355,10 +355,11 @@ En OpenSWAD:
ps2pdf source.ps destination.pdf
*/
#define Log_PLATFORM_VERSION "SWAD 18.13.2 (2018-11-04)"
#define Log_PLATFORM_VERSION "SWAD 18.13.3 (2018-11-04)"
#define CSS_FILE "swad18.4.css"
#define JS_FILE "swad17.17.1.js"
/*
Version 18.13.3: Nov 04, 2018 Code refactoring related to databse queries. (236562 lines)
Version 18.13.2: Nov 04, 2018 Code refactoring related to databse queries. (236555 lines)
Version 18.13.1: Nov 04, 2018 New database funtion to get number of rows in a table. (236572 lines)
Version 18.13: Nov 03, 2018 Joining building and performing query into one function. (236563 lines)

View File

@ -2845,6 +2845,9 @@ int swad__sendAttendanceUsers (struct soap *soap,
" WHERE AttCod=%ld%s",
Att.AttCod,SubQueryAllUsrs);
/* Free memory for subquery string */
free ((void *) SubQueryAllUsrs);
/* Clean table att_usr */
Att_RemoveUsrsAbsentWithoutCommentsFromAttEvent (Att.AttCod);
}