2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-02-28 07:23:58 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`balanceNestTree_delete`(
|
|
|
|
vSelf INT
|
2024-01-15 11:31:03 +00:00
|
|
|
)
|
|
|
|
BEGIN
|
2024-02-28 07:23:58 +00:00
|
|
|
DECLARE vTable VARCHAR(45) DEFAULT util.quoteIdentifier('balanceNestTree');
|
|
|
|
DECLARE vRight INT;
|
|
|
|
DECLARE vLeft INT;
|
|
|
|
DECLARE vWidth INT;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
2024-02-28 07:23:58 +00:00
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tAux
|
2024-01-15 11:31:03 +00:00
|
|
|
SELECT 0 rgt, 0 lft, 0 wdt;
|
|
|
|
|
|
|
|
EXECUTE IMMEDIATE CONCAT(
|
2024-02-28 07:23:58 +00:00
|
|
|
'UPDATE tAux a
|
2024-01-15 11:31:03 +00:00
|
|
|
JOIN ', vTable, ' t
|
|
|
|
SET a.rgt = t.rgt,
|
|
|
|
a.lft = t.lft,
|
|
|
|
a.wdt = t.rgt - t.lft + 1
|
|
|
|
WHERE t.id = ?')
|
2024-02-28 07:23:58 +00:00
|
|
|
USING vSelf;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
SELECT rgt, lft, wdt
|
2024-02-28 07:23:58 +00:00
|
|
|
INTO vRight, vLeft, vWidth
|
|
|
|
FROM tAux;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
EXECUTE IMMEDIATE CONCAT(
|
|
|
|
'DELETE FROM ', vTable,
|
|
|
|
' WHERE lft BETWEEN ? AND ?')
|
2024-02-28 07:23:58 +00:00
|
|
|
USING vLeft, vRight;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
EXECUTE IMMEDIATE CONCAT(
|
|
|
|
'UPDATE ', vTable,
|
|
|
|
' SET rgt = rgt - ?
|
|
|
|
WHERE rgt > ?
|
|
|
|
ORDER BY rgt')
|
2024-02-28 07:23:58 +00:00
|
|
|
USING vWidth,vRight;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
EXECUTE IMMEDIATE CONCAT(
|
|
|
|
'UPDATE ', vTable,
|
|
|
|
' SET lft = lft - ?
|
|
|
|
WHERE lft > ?
|
|
|
|
ORDER BY lft')
|
2024-02-28 07:23:58 +00:00
|
|
|
USING vWidth, vRight;
|
|
|
|
|
|
|
|
DROP TEMPORARY TABLE tAux;
|
2024-01-15 11:31:03 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|