delimiter |
DROP PROCEDURE IF EXISTS `Active_Notify`|
CREATE PROCEDURE Active_Notify( IN ST datetime, IN SP datetime)
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE USR VARCHAR(11);
DECLARE cur CURSOR FOR select distinct(username) from location2_history where count=1 and start>ST and stop<SP group by username,domain having count(distinct(port))=count(username) and count(username)>1 and count(distinct(ipaddr))=1;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
DROP TABLE IF EXISTS tempo;
CREATE TEMPORARY TABLE tempo (
`username` VARCHAR(11),
PRIMARY KEY (`username`)
);
OPEN cur;
read_loop: LOOP
FETCH cur INTO USR;
IF done THEN
LEAVE read_loop;
END IF;
IF (select username from location2_history where username=USR and start>ST and stop<SP group by username,count having count(distinct(ipaddr))=1 and count(distinct(port))=SUM(count) and count(*)=SUM(count)) THEN
INSERT INTO tempo values (USR);
END IF;
END LOOP;
CLOSE cur;
SELECT * FROM tempo;
DELETE FROM tempo;
END|
delimiter ;
|