Version 18.11.26

This commit is contained in:
Antonio Cañas Vargas 2018-11-03 15:33:20 +01:00
parent 8c11d2551e
commit 408fc80f28
6 changed files with 146 additions and 114 deletions

View File

@ -355,10 +355,11 @@ En OpenSWAD:
ps2pdf source.ps destination.pdf
*/
#define Log_PLATFORM_VERSION "SWAD 18.11.25 (2018-11-03)"
#define Log_PLATFORM_VERSION "SWAD 18.11.26 (2018-11-03)"
#define CSS_FILE "swad18.4.css"
#define JS_FILE "swad17.17.1.js"
/*
Version 18.11.26: Nov 03, 2018 Joining building and performing query into one function. (236738 lines)
Version 18.11.25: Nov 03, 2018 Joining building and performing query into one function. (236705 lines)
Version 18.11.24: Nov 03, 2018 Joining building and performing query into one function. (236636 lines)
Version 18.11.23: Nov 03, 2018 Joining building and performing query into one function. (236630 lines)

View File

@ -444,9 +444,12 @@ void Dpt_FreeListDepartments (void)
unsigned Dpt_GetNumDepartmentsInInstitution (long InsCod)
{
/***** Get number of departments in an institution from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM departments WHERE InsCod=%ld",InsCod);
return (unsigned) DB_QueryCOUNT_new ("can not get number of departments"
" in an institution");
return
(unsigned) DB_QueryCOUNT ("can not get number of departments"
" in an institution",
"SELECT COUNT(*) FROM departments"
" WHERE InsCod=%ld",
InsCod);
}
/*****************************************************************************/
@ -780,11 +783,11 @@ static void Dpt_RenameDepartment (Cns_ShrtOrFullName_t ShrtOrFullName)
static bool Dpt_CheckIfDepartmentNameExists (const char *FieldName,const char *Name,long DptCod)
{
/***** Get number of departments with a name from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM departments"
" WHERE %s='%s' AND DptCod<>%ld",
FieldName,Name,DptCod);
return (DB_QueryCOUNT_new ("can not check if the name"
" of a department already existed") != 0);
return (DB_QueryCOUNT ("can not check if the name"
" of a department already existed",
"SELECT COUNT(*) FROM departments"
" WHERE %s='%s' AND DptCod<>%ld",
FieldName,Name,DptCod) != 0);
}
/*****************************************************************************/
@ -1073,8 +1076,9 @@ static void Dpt_CreateDepartment (struct Department *Dpt)
unsigned Dpt_GetTotalNumberOfDepartments (void)
{
/***** Get number of departments from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM departments");
return (unsigned) DB_QueryCOUNT_new ("can not get number of departments");
return
(unsigned) DB_QueryCOUNT ("can not get number of departments",
"SELECT COUNT(*) FROM departments");
}
/*****************************************************************************/
@ -1084,8 +1088,12 @@ unsigned Dpt_GetTotalNumberOfDepartments (void)
unsigned Dpt_GetNumDptsInIns (long InsCod)
{
/***** Get departments in an institution from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM departments WHERE InsCod=%ld",InsCod);
return (unsigned) DB_QueryCOUNT_new ("can not get number of departments in an institution");
return
(unsigned) DB_QueryCOUNT ("can not get number of departments"
" in an institution",
"SELECT COUNT(*) FROM departments"
" WHERE InsCod=%ld",
InsCod);
}
/*****************************************************************************/

View File

@ -388,9 +388,11 @@ static void Dup_ListSimilarUsrs (void)
static bool Dup_CheckIfUsrIsDup (long UsrCod)
{
DB_BuildQuery ("SELECT COUNT(*) FROM usr_duplicated WHERE UsrCod=%ld",
UsrCod);
return (DB_QueryCOUNT_new ("can not if user is in list of possible duplicate users") != 0);
return (DB_QueryCOUNT ("can not if user is in list"
" of possible duplicate users",
"SELECT COUNT(*) FROM usr_duplicated"
" WHERE UsrCod=%ld",
UsrCod) != 0);
}
/*****************************************************************************/

View File

@ -8165,6 +8165,7 @@ static void Brw_RenameAffectedExpandedFolders (Brw_FileBrowser_t FileBrowser,
static bool Brw_GetIfExpandedTree (const char Path[PATH_MAX + 1])
{
bool Expanded;
long Cod = Brw_GetCodForExpandedFolders ();
long WorksUsrCod = Brw_GetWorksUsrCodForExpandedFolders ();
Brw_FileBrowser_t FileBrowserForExpandedFolders = Brw_FileBrowserForDB_expanded_folders[Gbl.FileBrowser.Type];
@ -8173,32 +8174,35 @@ static bool Brw_GetIfExpandedTree (const char Path[PATH_MAX + 1])
if (Cod > 0)
{
if (WorksUsrCod > 0)
DB_BuildQuery ("SELECT COUNT(*) FROM expanded_folders"
" WHERE UsrCod=%ld AND FileBrowser=%u"
" AND Cod=%ld AND WorksUsrCod=%ld"
" AND Path='%s/'",
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) FileBrowserForExpandedFolders,
Cod,WorksUsrCod,
Path);
Expanded = (DB_QueryCOUNT ("can not get check if a folder is expanded",
"SELECT COUNT(*) FROM expanded_folders"
" WHERE UsrCod=%ld AND FileBrowser=%u"
" AND Cod=%ld AND WorksUsrCod=%ld"
" AND Path='%s/'",
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) FileBrowserForExpandedFolders,
Cod,WorksUsrCod,
Path) != 0);
else
DB_BuildQuery ("SELECT COUNT(*) FROM expanded_folders"
" WHERE UsrCod=%ld AND FileBrowser=%u"
" AND Cod=%ld"
" AND Path='%s/'",
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) FileBrowserForExpandedFolders,
Cod,
Path);
Expanded = (DB_QueryCOUNT ("can not get check if a folder is expanded",
"SELECT COUNT(*) FROM expanded_folders"
" WHERE UsrCod=%ld AND FileBrowser=%u"
" AND Cod=%ld"
" AND Path='%s/'",
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) FileBrowserForExpandedFolders,
Cod,
Path) != 0);
}
else // Briefcase
DB_BuildQuery ("SELECT COUNT(*) FROM expanded_folders"
" WHERE UsrCod=%ld AND FileBrowser=%u"
" AND Path='%s/'",
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) FileBrowserForExpandedFolders,
Path);
return (DB_QueryCOUNT_new ("can not get check if a folder is expanded") != 0);
Expanded = (DB_QueryCOUNT ("can not get check if a folder is expanded",
"SELECT COUNT(*) FROM expanded_folders"
" WHERE UsrCod=%ld AND FileBrowser=%u"
" AND Path='%s/'",
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) FileBrowserForExpandedFolders,
Path) != 0);
return Expanded;
}
/*****************************************************************************/
@ -10063,17 +10067,16 @@ bool Brw_CheckIfFileOrFolderIsHidden (struct FileMetadata *FileMetadata)
or
2) the argument Path begins by 'x/', where x is a path stored in database
*/
DB_BuildQuery ("SELECT COUNT(*) FROM files"
" WHERE FileBrowser=%u AND Cod=%ld AND ZoneUsrCod=%ld"
" AND Hidden='Y'"
" AND (Path='%s' OR LOCATE(CONCAT(Path,'/'),'%s')=1)",
FileMetadata->FileBrowser,
FileMetadata->Cod,
FileMetadata->ZoneUsrCod,
FileMetadata->FullPathInTree,
FileMetadata->FullPathInTree);
return (DB_QueryCOUNT_new ("can not check if a file or folder is hidden") != 0);
return (DB_QueryCOUNT ("can not check if a file or folder is hidden",
"SELECT COUNT(*) FROM files"
" WHERE FileBrowser=%u AND Cod=%ld AND ZoneUsrCod=%ld"
" AND Hidden='Y'"
" AND (Path='%s' OR LOCATE(CONCAT(Path,'/'),'%s')=1)",
FileMetadata->FileBrowser,
FileMetadata->Cod,
FileMetadata->ZoneUsrCod,
FileMetadata->FullPathInTree,
FileMetadata->FullPathInTree) != 0);
}
/*****************************************************************************/
@ -11583,13 +11586,13 @@ static bool Brw_GetIfFolderHasPublicFiles (const char Path[PATH_MAX + 1])
long ZoneUsrCod = Brw_GetZoneUsrCodForFiles ();
/***** Get if a file or folder is public from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM files"
" WHERE FileBrowser=%u AND Cod=%ld AND ZoneUsrCod=%ld"
" AND Path LIKE '%s/%%' AND Public='Y'",
(unsigned) Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type],
Cod,ZoneUsrCod,
Path);
return (DB_QueryCOUNT_new ("can not check if a folder contains public files") != 0);
return (DB_QueryCOUNT ("can not check if a folder contains public files",
"SELECT COUNT(*) FROM files"
" WHERE FileBrowser=%u AND Cod=%ld AND ZoneUsrCod=%ld"
" AND Path LIKE '%s/%%' AND Public='Y'",
(unsigned) Brw_FileBrowserForDB_files[Gbl.FileBrowser.Type],
Cod,ZoneUsrCod,
Path) != 0);
}
/*****************************************************************************/
@ -11599,12 +11602,14 @@ static bool Brw_GetIfFolderHasPublicFiles (const char Path[PATH_MAX + 1])
unsigned Brw_GetNumFilesUsr (long UsrCod)
{
/***** Get current number of files published by a user from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM files"
" WHERE PublisherUsrCod=%ld AND FileType IN (%u,%u)",
UsrCod,
(unsigned) Brw_IS_FILE,
(unsigned) Brw_IS_UNKNOWN); // Unknown entries are counted as files
return (unsigned) DB_QueryCOUNT_new ("can not get number of files from a user");
return
(unsigned) DB_QueryCOUNT ("can not get number of files from a user",
"SELECT COUNT(*) FROM files"
" WHERE PublisherUsrCod=%ld"
" AND FileType IN (%u,%u)",
UsrCod,
(unsigned) Brw_IS_FILE,
(unsigned) Brw_IS_UNKNOWN); // Unknown entries are counted as files
}
/*****************************************************************************/
@ -11614,13 +11619,15 @@ unsigned Brw_GetNumFilesUsr (long UsrCod)
unsigned Brw_GetNumPublicFilesUsr (long UsrCod)
{
/***** Get current number of public files published by a user from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM files"
" WHERE PublisherUsrCod=%ld AND FileType IN (%u,%u)"
" AND Public='Y'",
UsrCod,
(unsigned) Brw_IS_FILE,
(unsigned) Brw_IS_UNKNOWN); // Unknown entries are counted as files
return (unsigned) DB_QueryCOUNT_new ("can not get number of public files from a user");
return
(unsigned) DB_QueryCOUNT ("can not get number of public files from a user",
"SELECT COUNT(*) FROM files"
" WHERE PublisherUsrCod=%ld"
" AND FileType IN (%u,%u)"
" AND Public='Y'",
UsrCod,
(unsigned) Brw_IS_FILE,
(unsigned) Brw_IS_UNKNOWN); // Unknown entries are counted as files
}
/*****************************************************************************/

View File

@ -445,10 +445,10 @@ bool Fol_CheckUsrIsFollowerOf (long FollowerCod,long FollowedCod)
return false;
/***** Check if a user is a follower of another user *****/
DB_BuildQuery ("SELECT COUNT(*) FROM usr_follow"
" WHERE FollowerCod=%ld AND FollowedCod=%ld",
FollowerCod,FollowedCod);
return (DB_QueryCOUNT_new ("can not get if a user is a follower of another one") != 0);
return (DB_QueryCOUNT ("can not get if a user is a follower of another one",
"SELECT COUNT(*) FROM usr_follow"
" WHERE FollowerCod=%ld AND FollowedCod=%ld",
FollowerCod,FollowedCod) != 0);
}
/*****************************************************************************/
@ -458,9 +458,11 @@ bool Fol_CheckUsrIsFollowerOf (long FollowerCod,long FollowedCod)
unsigned Fol_GetNumFollowing (long UsrCod)
{
/***** Check if a user is a follower of another user *****/
DB_BuildQuery ("SELECT COUNT(*) FROM usr_follow WHERE FollowerCod=%ld",
UsrCod);
return DB_QueryCOUNT_new ("can not get number of followed");
return
(unsigned) DB_QueryCOUNT ("can not get number of followed",
"SELECT COUNT(*) FROM usr_follow"
" WHERE FollowerCod=%ld",
UsrCod);
}
/*****************************************************************************/
@ -470,9 +472,11 @@ unsigned Fol_GetNumFollowing (long UsrCod)
unsigned Fol_GetNumFollowers (long UsrCod)
{
/***** Check if a user is a follower of another user *****/
DB_BuildQuery ("SELECT COUNT(*) FROM usr_follow WHERE FollowedCod=%ld",
UsrCod);
return DB_QueryCOUNT_new ("can not get number of followers");
return
(unsigned) DB_QueryCOUNT ("can not get number of followers",
"SELECT COUNT(*) FROM usr_follow"
" WHERE FollowedCod=%ld",
UsrCod);
}
/*****************************************************************************/

View File

@ -441,8 +441,9 @@ void For_DisablePost (void)
static bool For_GetIfForumPstExists (long PstCod)
{
/***** Get if a forum post exists from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM forum_post WHERE PstCod=%ld",PstCod);
return (DB_QueryCOUNT_new ("can not check if a post of a forum already existed") != 0); // Post exists if it appears in table of forum posts
return (DB_QueryCOUNT ("can not check if a post of a forum already existed",
"SELECT COUNT(*) FROM forum_post WHERE PstCod=%ld",
PstCod) != 0); // Post exists if it appears in table of forum posts
}
/*****************************************************************************/
@ -452,13 +453,11 @@ static bool For_GetIfForumPstExists (long PstCod)
static bool For_GetIfPstIsEnabled (long PstCod)
{
if (PstCod > 0)
{
/***** Get if post is disabled from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM forum_disabled_post"
" WHERE PstCod=%ld",
PstCod);
return (DB_QueryCOUNT_new ("can not check if a post of a forum is disabled") == 0); // Post is enabled if it does not appear in table of disabled posts
}
return (DB_QueryCOUNT ("can not check if a post of a forum is disabled",
"SELECT COUNT(*) FROM forum_disabled_post"
" WHERE PstCod=%ld",
PstCod) == 0); // Post is enabled if it does not appear in table of disabled posts
else
return false;
}
@ -794,10 +793,12 @@ static void For_UpdateThrReadTime (long ThrCod,
static unsigned For_GetNumOfReadersOfThr (long ThrCod)
{
/***** Get number of distinct readers of a thread from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM forum_thr_read WHERE ThrCod=%ld",
ThrCod);
return (unsigned) DB_QueryCOUNT_new ("can not get the number of readers"
" of a thread of a forum");
return
(unsigned) DB_QueryCOUNT ("can not get the number of readers"
" of a thread of a forum",
"SELECT COUNT(*) FROM forum_thr_read"
" WHERE ThrCod=%ld",
ThrCod);
}
/*****************************************************************************/
@ -837,9 +838,12 @@ static unsigned For_GetNumOfWritersInThr (long ThrCod)
static unsigned For_GetNumPstsInThr (long ThrCod)
{
/***** Get number of posts in a thread from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM forum_post WHERE ThrCod=%ld",ThrCod);
return (unsigned) DB_QueryCOUNT_new ("can not get the number of posts"
" in a thread of a forum");
return
(unsigned) DB_QueryCOUNT ("can not get the number of posts"
" in a thread of a forum",
"SELECT COUNT(*) FROM forum_post"
" WHERE ThrCod=%ld",
ThrCod);
}
/*****************************************************************************/
@ -849,11 +853,12 @@ static unsigned For_GetNumPstsInThr (long ThrCod)
static unsigned For_GetNumMyPstInThr (long ThrCod)
{
/***** Get if I have write posts in a thread from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM forum_post"
" WHERE ThrCod=%ld AND UsrCod=%ld",
ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod);
return (unsigned) DB_QueryCOUNT_new ("can not check if you have written"
" posts in a thead of a forum");
return
(unsigned) DB_QueryCOUNT ("can not check if you have written"
" posts in a thead of a forum",
"SELECT COUNT(*) FROM forum_post"
" WHERE ThrCod=%ld AND UsrCod=%ld",
ThrCod,Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/
@ -863,8 +868,9 @@ static unsigned For_GetNumMyPstInThr (long ThrCod)
unsigned long For_GetNumPostsUsr (long UsrCod)
{
/***** Get number of posts from a user from database *****/
DB_BuildQuery ("SELECT COUNT(*) FROM forum_post WHERE UsrCod=%ld",UsrCod);
return DB_QueryCOUNT_new ("can not number of posts from a user");
return DB_QueryCOUNT ("can not number of posts from a user",
"SELECT COUNT(*) FROM forum_post WHERE UsrCod=%ld",
UsrCod);
}
/*****************************************************************************/
@ -1448,12 +1454,15 @@ static void For_WriteNumberOfPosts (long UsrCod)
Gbl.Forum.ForumSelected.Location);
else
SubQuery[0] = '\0';
DB_BuildQuery ("SELECT COUNT(*) FROM forum_post,forum_thread"
" WHERE forum_post.UsrCod=%ld"
" AND forum_post.ThrCod=forum_thread.ThrCod"
" AND forum_thread.ForumType=%u%s",
UsrCod,(unsigned) Gbl.Forum.ForumSelected.Type,SubQuery);
NumPsts = (unsigned) DB_QueryCOUNT_new ("can not get the number of posts of a user in a forum");
NumPsts =
(unsigned) DB_QueryCOUNT ("can not get the number of posts of a user"
" in a forum",
"SELECT COUNT(*) FROM forum_post,forum_thread"
" WHERE forum_post.UsrCod=%ld"
" AND forum_post.ThrCod=forum_thread.ThrCod"
" AND forum_thread.ForumType=%u%s",
UsrCod,
(unsigned) Gbl.Forum.ForumSelected.Type,SubQuery);
/***** Write number of threads and number of posts *****/
if (NumPsts == 1)
@ -2325,12 +2334,13 @@ static unsigned For_GetNumOfThreadsInForumNewerThan (struct Forum *Forum,
sprintf (SubQuery," AND forum_thread.Location=%ld",Forum->Location);
else
SubQuery[0] = '\0';
DB_BuildQuery ("SELECT COUNT(*) FROM forum_thread,forum_post"
" WHERE forum_thread.ForumType=%u%s"
" AND forum_thread.LastPstCod=forum_post.PstCod"
" AND forum_post.ModifTime>'%s'",
(unsigned) Forum->Type,SubQuery,Time);
return (unsigned) DB_QueryCOUNT_new ("can not check if there are new posts in a forum");
return
(unsigned) DB_QueryCOUNT ("can not check if there are new posts in a forum",
"SELECT COUNT(*) FROM forum_thread,forum_post"
" WHERE forum_thread.ForumType=%u%s"
" AND forum_thread.LastPstCod=forum_post.PstCod"
" AND forum_post.ModifTime>'%s'",
(unsigned) Forum->Type,SubQuery,Time);
}
/*****************************************************************************/