I created an event which automatically gets the system current date and matches it with the start and end date of a school year. If the system current date is within the start and end date of the school year, it updates the isCurrentSchoolYear
column with 1
.
It worked perfect the first time I did this. However, when I changed the date on my PC to test if it will work with year 2020, nothing happens anymore. The event
is set to run every 30 seconds.
schoolyear_mt table
(had to manually call the setCurrentSchoolYear()
stored procedure to update isCurrentSchoolYear
of 2020
to 1
which is supposed to be updated automatically)
======================================================================
enrollmentdb.setSchoolYear
event definition:
CREATE EVENT enrollmentdb.e_setCurrentSchoolYear
ON SCHEDULE EVERY 30 second
DO CALL setCurrentSchoolYear();
======================================================================
SELECT @@event_scheduler;
======================================================================
show processlist;
show events from enrollmentdb;
As you can see, Interval Value
column shows 30 but the Time
column shows 63163099 and continues to increment.
So the problem is it doesn't automatically update the isCurrentSchoolYear
column every after 30 seconds. I don't want to manually call the stored proc named setCurrentSchoolYear()
to make it work.
CREATE DEFINER=`root`@`localhost` PROCEDURE `setCurrentSchoolYear`()
BEGIN
DECLARE aSyId INT;
DECLARE EXIT HANDLER FOR sqlexception
BEGIN
ROLLBACK;
RESIGNAL;
END;
START TRANSACTION;
-- compare the currentdate
SELECT schoolyear_id INTO aSyId FROM schoolyear_mt
WHERE curdate() >= start_date AND curdate() <= end_date;
SELECT aSyId;
IF aSyId IS NOT NULL
THEN
UPDATE schoolyear_mt SET isCurrentSchoolYear = 0
WHERE schoolyear_id >= 0;
UPDATE schoolyear_mt SET isCurrentSchoolYear = 1
WHERE schoolyear_id = aSyId;
END IF;
COMMIT;
END
The problem with automatic update happened after I changed my machine's system date to Feb 02, 2020 and also tried Feb 02, 2015 to test if it's effective. What could possible be hindering it from executing manually every 30 seconds?
Any thoughts?
Thank you.