cau 10249 update structure
gitea/salix/dev This commit has test failures Details

This commit is contained in:
Bernat 2019-03-29 12:07:48 +01:00
parent 5ff6241e2d
commit 7e2f07aa83
1 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,46 @@
DROP procedure IF EXISTS `vn`.`worker_getHierarch`;
DELIMITER $$
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`worker_getHierarch`(vBoss INT)
BEGIN
DECLARE EXIT HANDLER FOR 1062 BEGIN
CALL util.throw('INFINITE_LOOP');
END;
DROP TEMPORARY TABLE IF EXISTS workerHierarch;
CREATE TEMPORARY TABLE workerHierarch
(PRIMARY KEY (workerFk))
ENGINE = MEMORY
SELECT vBoss AS workerFk;
DROP TEMPORARY TABLE IF EXISTS tmp.workerHierarchList;
CREATE TEMPORARY TABLE tmp.workerHierarchList
(PRIMARY KEY (workerFk))
ENGINE = MEMORY
SELECT vBoss AS workerFk, 0 AS isChecked;
WHILE (SELECT COUNT(*) FROM tmp.workerHierarchList WHERE NOT isChecked) > 0 DO
INSERT INTO tmp.workerHierarchList
SELECT w.id, 0
FROM worker w
JOIN workerHierarch wh ON wh.workerFk = w.bossFk;
UPDATE tmp.workerHierarchList whl
JOIN workerHierarch wh ON wh.workerFk = whl.workerFk
SET whl.isChecked = 1;
TRUNCATE workerHierarch;
INSERT INTO workerHierarch
SELECT workerFk
FROM tmp.workerHierarchList
WHERE NOT isChecked;
END WHILE;
DROP TEMPORARY TABLE IF EXISTS workerHierarch;
END$$
DELIMITER ;