diff --git a/swad_changelog.h b/swad_changelog.h index af2822596..2d897462e 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -139,13 +139,14 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 16.0 (2016-09-22)" +#define Log_PLATFORM_VERSION "SWAD 16.1 (2016-09-22)" #define CSS_FILE "swad15.229.css" #define JS_FILE "swad15.238.1.js" // Number of lines (includes comments but not blank lines) has been got with the following command: // nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*.h sql/swad*.sql | tail -1 /* + Version 16.1: Sep 22, 2016 Temporary table with other user's courses. (204828 lines) Version 16.0: Sep 22, 2016 Temporary table with my courses. Added indexes to database. (204811 lines) 1 change necessary in database: diff --git a/swad_user.c b/swad_user.c index 8f5af9486..0ce1f7a9f 100644 --- a/swad_user.c +++ b/swad_user.c @@ -863,7 +863,7 @@ unsigned Usr_GetNumUsrsInCrssOfAUsr (long UsrCod,Rol_Role_t UsrRole, if (mysql_query (&Gbl.mysql,Query)) DB_ExitOnMySQLError ("can not remove temporary tables"); - /***** Create temporary table with all my courses for a role *****/ + /***** Create temporary table with all user's courses for a role *****/ sprintf (Query,"CREATE TEMPORARY TABLE IF NOT EXISTS usr_courses_tmp" " (CrsCod INT NOT NULL,UNIQUE INDEX (CrsCod))" " ENGINE=MEMORY" @@ -912,14 +912,34 @@ bool Usr_CheckIfUsrSharesAnyOfMyCrs (long UsrCod) bool Usr_CheckIfUsrSharesAnyOfMyCrsWithDifferentRole (long UsrCod) { char Query[512]; + bool UsrSharesAnyOfMyCrsWithDifferentRole; + + /***** Remove temporary table if exists *****/ + sprintf (Query,"DROP TEMPORARY TABLE IF EXISTS usr_courses_tmp"); + if (mysql_query (&Gbl.mysql,Query)) + DB_ExitOnMySQLError ("can not remove temporary tables"); + + /***** Create temporary table with all user's courses for a role *****/ + sprintf (Query,"CREATE TEMPORARY TABLE IF NOT EXISTS usr_courses_tmp " + "(CrsCod INT NOT NULL,Role TINYINT NOT NULL," + "UNIQUE INDEX(CrsCod),INDEX(Role)) ENGINE=MEMORY" + " SELECT CrsCod,Role FROM crs_usr WHERE UsrCod='%ld'", + UsrCod); + if (mysql_query (&Gbl.mysql,Query)) + DB_ExitOnMySQLError ("can not create temporary table"); /***** Get if a user shares any course with me from database *****/ - sprintf (Query,"SELECT COUNT(*) FROM my_courses_tmp," - "(SELECT CrsCod,Role FROM crs_usr WHERE UsrCod='%ld') AS usr_courses" - " WHERE my_courses_tmp.CrsCod=usr_courses.CrsCod" - " AND my_courses_tmp.Role<>usr_courses.Role", - UsrCod); - return (DB_QueryCOUNT (Query,"can not check if a user shares any course with you") != 0); + sprintf (Query,"SELECT COUNT(*) FROM my_courses_tmp,usr_courses_tmp" + " WHERE my_courses_tmp.CrsCod=usr_courses_tmp.CrsCod" + " AND my_courses_tmp.Role<>usr_courses_tmp.Role"); + UsrSharesAnyOfMyCrsWithDifferentRole = (DB_QueryCOUNT (Query,"can not check if a user shares any course with you") != 0); + + /***** Remove temporary table if exists *****/ + sprintf (Query,"DROP TEMPORARY TABLE IF EXISTS usr_courses_tmp"); + if (mysql_query (&Gbl.mysql,Query)) + DB_ExitOnMySQLError ("can not remove temporary tables"); + + return UsrSharesAnyOfMyCrsWithDifferentRole; } /*****************************************************************************/