salix/db/routines/vn/procedures/route_doRecalc.sql

49 lines
850 B
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`route_doRecalc`()
proc: BEGIN
/**
* Recalculates modified route.
*/
DECLARE vDone BOOL;
DECLARE vRouteFk INT;
DECLARE cCur CURSOR FOR
SELECT routeFk FROM routeRecalc;
DECLARE CONTINUE HANDLER FOR NOT FOUND
SET vDone = TRUE;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
BEGIN
DO RELEASE_LOCK('vn.route_doRecalc');
ROLLBACK;
RESIGNAL;
END;
IF !GET_LOCK('vn.route_doRecalc', 0) THEN
LEAVE proc;
END IF;
OPEN cCur;
myLoop: LOOP
SET vDone = FALSE;
FETCH cCur INTO vRouteFk;
IF vDone THEN
LEAVE myLoop;
END IF;
START TRANSACTION;
CALL route_updateM3(vRouteFk);
COMMIT;
DELETE FROM routeRecalc WHERE routeFk = vRouteFk;
END LOOP;
CLOSE cCur;
DO RELEASE_LOCK('vn.route_doRecalc');
END$$
DELIMITER ;