I am trying to set the event to on for the bus table but it does not work. The table as well as the event is being created but the event is not being triggered. I have already set this line event_scheduler = ON; in mysql- my.ini and restart the server.
// Create bus table
stt.execute("CREATE TABLE IF NOT EXISTS bus"
+ "(id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,"
+ "mac VARCHAR(30) NOT NULL UNIQUE,"
+ "route int(11) NOT NULL,"
+ "latitude FLOAT(10,6) NOT NULL,"
+ "longitude FLOAT(10,6) NOT NULL,"
+ "created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP)");
stt.execute("CREATE EVENT IF NOT EXISTS AutoDelete "
+ "ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 3 MINUTE "
+ "DO "
+ "DELETE FROM bus WHERE created_at < (NOW() - INTERVAL 3 MINUTE)");
stt.execute("SET GLOBAL event_scheduler = ON");
Aucun commentaire:
Enregistrer un commentaire