2024-07-22 09:52:42 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` PROCEDURE `vn`.`zone_getPostalCode`(vSelf INT)
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Devuelve los códigos postales incluidos en una zona
|
|
|
|
*/
|
|
|
|
DECLARE vGeoFk INT DEFAULT NULL;
|
|
|
|
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tmp.zoneNodes (
|
|
|
|
geoFk INT,
|
|
|
|
name VARCHAR(100),
|
|
|
|
parentFk INT,
|
|
|
|
sons INT,
|
|
|
|
isChecked BOOL DEFAULT 0,
|
|
|
|
zoneFk INT,
|
|
|
|
PRIMARY KEY zoneNodesPk (zoneFk, geoFk),
|
|
|
|
INDEX(geoFk))
|
|
|
|
ENGINE = MEMORY;
|
|
|
|
|
|
|
|
CALL zone_getLeaves(vSelf, NULL , NULL, TRUE);
|
|
|
|
|
|
|
|
UPDATE tmp.zoneNodes
|
|
|
|
SET isChecked = 0
|
|
|
|
WHERE parentFk IS NULL;
|
|
|
|
|
|
|
|
myLoop: LOOP
|
|
|
|
SET vGeoFk = NULL;
|
|
|
|
SELECT geoFk INTO vGeoFk
|
|
|
|
FROM tmp.zoneNodes
|
|
|
|
WHERE NOT isChecked
|
|
|
|
LIMIT 1;
|
|
|
|
|
|
|
|
CALL zone_getLeaves(vSelf, vGeoFk, NULL, TRUE);
|
|
|
|
UPDATE tmp.zoneNodes
|
|
|
|
SET isChecked = TRUE
|
|
|
|
WHERE geoFk = vGeoFk;
|
|
|
|
|
|
|
|
IF vGeoFk IS NULL THEN
|
|
|
|
LEAVE myLoop;
|
|
|
|
END IF;
|
|
|
|
END LOOP;
|
|
|
|
|
|
|
|
DELETE FROM tmp.zoneNodes
|
|
|
|
WHERE sons > 0;
|
2024-07-22 09:52:42 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|