From 6b643a722be8daf9921c50f73890e65886cbc127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Sun, 12 Mar 2017 16:39:16 +0100 Subject: [PATCH] Version 16.155.13 --- sql/swad.sql | 2 +- swad_changelog.h | 6 +++++- swad_database.c | 54 ++++++++++++++++++++++++------------------------ swad_holiday.c | 18 +++++++++------- swad_session.c | 14 +++++++++++-- 5 files changed, 55 insertions(+), 39 deletions(-) diff --git a/sql/swad.sql b/sql/swad.sql index e83c8a627..67dccb709 100644 --- a/sql/swad.sql +++ b/sql/swad.sql @@ -584,7 +584,7 @@ CREATE TABLE IF NOT EXISTS holidays ( HldTyp TINYINT NOT NULL, StartDate DATE NOT NULL, EndDate DATE NOT NULL, - Name VARCHAR(127) NOT NULL, + Name VARCHAR(2047) NOT NULL, UNIQUE INDEX(HldCod), INDEX(InsCod), INDEX(PlcCod)); diff --git a/swad_changelog.h b/swad_changelog.h index 313610c4a..93532df4c 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -207,13 +207,17 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 16.155.12 (2017-03-12)" +#define Log_PLATFORM_VERSION "SWAD 16.155.13 (2017-03-12)" #define CSS_FILE "swad16.147.css" #define JS_FILE "swad16.144.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.155.13:Mar 11, 2017 Adjusting size of database fields. (216734 lines) + 1 change necessary in database: +ALTER TABLE holidays CHANGE COLUMN Name Name VARCHAR(2047) NOT NULL; + Version 16.155.12:Mar 12, 2017 Fixed bug while sending a message to several users, reported by Javier Fernández Baldomero. (216721 lines) Version 16.155.11:Mar 11, 2017 Adjusting size of database fields. (216711 lines) 1 change necessary in database: diff --git a/swad_database.c b/swad_database.c index e6cd75929..8c407b4ac 100644 --- a/swad_database.c +++ b/swad_database.c @@ -1246,39 +1246,39 @@ mysql> DESCRIBE hidden_params; 4 rows in set (0.00 sec) */ DB_CreateTable ("CREATE TABLE IF NOT EXISTS hidden_params (" - "SessionId CHAR(43) NOT NULL," - "Action INT NOT NULL," - "ParamName VARCHAR(255) NOT NULL," - "ParamValue TEXT NOT NULL," - "INDEX(SessionId,Action))"); + "SessionId CHAR(43) NOT NULL," + "Action INT NOT NULL," + "ParamName VARCHAR(255) NOT NULL," + "ParamValue TEXT NOT NULL," + "INDEX(SessionId,Action))"); /***** Table holidays *****/ /* mysql> DESCRIBE holidays; -+-----------+--------------+------+-----+---------+----------------+ -| Field | Type | Null | Key | Default | Extra | -+-----------+--------------+------+-----+---------+----------------+ -| HldCod | int(11) | NO | PRI | NULL | auto_increment | -| InsCod | int(11) | NO | MUL | NULL | | -| PlcCod | int(11) | NO | MUL | -1 | | -| HldTyp | tinyint(4) | NO | | NULL | | -| StartDate | date | NO | | NULL | | -| EndDate | date | NO | | NULL | | -| Name | varchar(127) | NO | | NULL | | -+-----------+--------------+------+-----+---------+----------------+ -7 rows in set (0.00 sec) ++-----------+---------------+------+-----+---------+----------------+ +| Field | Type | Null | Key | Default | Extra | ++-----------+---------------+------+-----+---------+----------------+ +| HldCod | int(11) | NO | PRI | NULL | auto_increment | +| InsCod | int(11) | NO | MUL | NULL | | +| PlcCod | int(11) | NO | MUL | -1 | | +| HldTyp | tinyint(4) | NO | | NULL | | +| StartDate | date | NO | | NULL | | +| EndDate | date | NO | | NULL | | +| Name | varchar(2047) | NO | | NULL | | ++-----------+---------------+------+-----+---------+----------------+ +7 rows in set (0,00 sec) */ DB_CreateTable ("CREATE TABLE IF NOT EXISTS holidays (" - "HldCod INT NOT NULL AUTO_INCREMENT," - "InsCod INT NOT NULL," - "PlcCod INT NOT NULL DEFAULT -1," - "HldTyp TINYINT NOT NULL," - "StartDate DATE NOT NULL," - "EndDate DATE NOT NULL," - "Name VARCHAR(127) NOT NULL," - "UNIQUE INDEX (HldCod)," - "INDEX(InsCod)," - "INDEX(PlcCod))"); + "HldCod INT NOT NULL AUTO_INCREMENT," + "InsCod INT NOT NULL," + "PlcCod INT NOT NULL DEFAULT -1," + "HldTyp TINYINT NOT NULL," + "StartDate DATE NOT NULL," + "EndDate DATE NOT NULL," + "Name VARCHAR(2047) NOT NULL," // Hld_MAX_BYTES_HOLIDAY_NAME + "UNIQUE INDEX (HldCod)," + "INDEX(InsCod)," + "INDEX(PlcCod))"); /***** Table institutions *****/ /* diff --git a/swad_holiday.c b/swad_holiday.c index ec225267a..b62b30c04 100644 --- a/swad_holiday.c +++ b/swad_holiday.c @@ -241,7 +241,7 @@ void Hld_EditHolidays (void) void Hld_GetListHolidays (void) { char OrderBySubQuery[256]; - char Query[1024]; + char Query[2048]; MYSQL_RES *mysql_res; MYSQL_ROW row; unsigned NumHld; @@ -352,7 +352,7 @@ void Hld_GetListHolidays (void) static void Hld_GetDataOfHolidayByCod (struct Holiday *Hld) { - char Query[1024]; + char Query[2048]; MYSQL_RES *mysql_res; MYSQL_ROW row; @@ -642,7 +642,8 @@ void Hld_RemoveHoliday (void) Hld_GetDataOfHolidayByCod (&Hld); /***** Remove holiday *****/ - sprintf (Query,"DELETE FROM holidays WHERE HldCod='%ld'",Hld.HldCod); + sprintf (Query,"DELETE FROM holidays WHERE HldCod='%ld'", + Hld.HldCod); DB_QueryDELETE (Query,"can not remove a holiday"); /***** Write message to show the change made *****/ @@ -661,7 +662,7 @@ void Hld_RemoveHoliday (void) void Hld_ChangeHolidayPlace (void) { extern const char *Txt_The_place_of_the_holiday_X_has_changed_to_Y; - char Query[512]; + char Query[128]; struct Holiday *Hld; struct Place NewPlace; @@ -761,7 +762,7 @@ void Hld_ChangeEndDate (void) static void Hld_ChangeDate (Hld_StartOrEndDate_t StartOrEndDate) { extern const char *Txt_The_date_of_the_holiday_X_has_changed_to_Y; - char Query[512]; + char Query[128]; struct Holiday *Hld; struct Date NewDate; struct Date *PtrDate = NULL; // Initialized to avoid warning @@ -840,7 +841,7 @@ void Hld_RenameHoliday (void) extern const char *Txt_You_can_not_leave_the_name_of_the_holiday_X_empty; extern const char *Txt_The_name_of_the_holiday_X_has_changed_to_Y; extern const char *Txt_The_name_of_the_holiday_X_has_not_changed; - char Query[512]; + char Query[128 + Hld_MAX_BYTES_HOLIDAY_NAME]; struct Holiday *Hld; char NewHldName[Hld_MAX_BYTES_HOLIDAY_NAME + 1]; @@ -1121,10 +1122,11 @@ void Hld_RecFormNewHoliday (void) static void Hld_CreateHoliday (struct Holiday *Hld) { extern const char *Txt_Created_new_holiday_X; - char Query[1024]; + char Query[256 + Hld_MAX_BYTES_HOLIDAY_NAME]; /***** Create a new holiday or no school period *****/ - sprintf (Query,"INSERT INTO holidays (InsCod,PlcCod,HldTyp,StartDate,EndDate,Name)" + sprintf (Query,"INSERT INTO holidays" + " (InsCod,PlcCod,HldTyp,StartDate,EndDate,Name)" " VALUES ('%ld','%ld','%u','%04u%02u%02u','%04u%02u%02u','%s')", Gbl.CurrentIns.Ins.InsCod,Hld->PlcCod,(unsigned) Hld->HldTyp, Hld->StartDate.Year, diff --git a/swad_session.c b/swad_session.c index dcda062da..1fcdbdb2b 100644 --- a/swad_session.c +++ b/swad_session.c @@ -340,7 +340,8 @@ bool Ses_GetSessionData (void) void Ses_InsertHiddenParInDB (Act_Action_t Action,const char *ParamName,const char *ParamValue) { - char Query[512 + Cns_MAX_BYTES_TEXT]; + char *Query; + size_t MaxLength; /***** Before of inserting the first hidden parameter passed to the next action, delete all the parameters coming from the previous action *****/ @@ -349,12 +350,21 @@ void Ses_InsertHiddenParInDB (Act_Action_t Action,const char *ParamName,const ch /***** For a unique session-action-parameter, don't insert a parameter more than one time *****/ if (!Ses_CheckIfHiddenParIsAlreadyInDB (Action,ParamName)) { + /***** Allocate space for query *****/ + MaxLength = 256 + Ses_LENGTH_SESSION_ID + strlen (ParamName) + strlen (ParamValue); + if ((Query = (char *) malloc (MaxLength + 1)) == NULL) + Lay_ShowErrorAndExit ("Not enough memory for query."); + /***** Insert parameter in the database *****/ - sprintf (Query,"INSERT INTO hidden_params (SessionId,Action,ParamName,ParamValue)" + sprintf (Query,"INSERT INTO hidden_params" + " (SessionId,Action,ParamName,ParamValue)" " VALUES ('%s','%d','%s','%s')", Gbl.Session.Id,(int) Action,ParamName,ParamValue); DB_QueryINSERT (Query,"can not create hidden parameter"); Gbl.HiddenParamsInsertedIntoDB = true; + + /***** Free query *****/ + free ((void *) Query); } }