salix/db/routines/vn/procedures/mysqlConnectionsSorter_kill...

38 lines
634 B
SQL

DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`mysqlConnectionsSorter_kill`()
BEGIN
/**
* Elimina conexiones del usuario sorter con tiempo >= 30seg. Asociado al evento con el mismo nombre
*/
DECLARE vDone INT DEFAULT 0;
DECLARE vProcesId INT;
DECLARE vCursor CURSOR FOR
SELECT p.id
FROM information_schema.processlist p
WHERE USER = 'sorter'
AND TIME >= 30;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
OPEN vCursor;
l: LOOP
FETCH vCursor INTO vProcesId;
IF vDone THEN
LEAVE l;
END IF;
KILL vProcesId;
END LOOP;
CLOSE vCursor;
END$$
DELIMITER ;