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

54 lines
1.2 KiB
MySQL
Raw Normal View History

2024-01-31 06:11:03 +00:00
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_doReserve`()
proc: BEGIN
/**
* Genera reservas de la tabla vn.itemShelvingSaleReserve
2024-01-31 06:11:03 +00:00
*/
DECLARE vDone BOOL;
DECLARE vSaleFk INT;
2024-07-17 14:09:09 +00:00
DECLARE vSectorFk INT;
2024-01-31 06:11:03 +00:00
DECLARE vSales CURSOR FOR
SELECT DISTINCT saleFk, sectorFk FROM tSale;
2024-01-31 06:11:03 +00:00
DECLARE CONTINUE HANDLER FOR NOT FOUND
SET vDone = TRUE;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
BEGIN
DO RELEASE_LOCK('vn.itemShelvingSale_doReserve');
ROLLBACK;
RESIGNAL;
END;
IF !GET_LOCK('vn.itemShelvingSale_doReserve', 0) THEN
LEAVE proc;
END IF;
CREATE OR REPLACE TEMPORARY TABLE tSale
ENGINE = MEMORY
2024-07-17 14:09:09 +00:00
SELECT id, saleFk, sectorFk FROM itemShelvingSaleReserve;
2024-01-31 06:11:03 +00:00
OPEN vSales;
myLoop: LOOP
SET vDone = FALSE;
2024-07-17 14:09:09 +00:00
FETCH vSales INTO vSaleFk, vSectorFk;
2024-01-31 06:11:03 +00:00
IF vDone THEN
LEAVE myLoop;
END IF;
2024-07-17 14:09:09 +00:00
CALL itemShelvingSale_addBySale (vSaleFk, vSectorFk);
2024-01-31 06:11:03 +00:00
END LOOP;
CLOSE vSales;
2024-07-17 14:09:09 +00:00
DELETE iss FROM itemShelvingSaleReserve iss
JOIN tSale s ON s.id = iss.id AND s.sectorFk = iss.sectorFk;
2024-01-31 06:11:03 +00:00
DROP TEMPORARY TABLE tSale;
DO RELEASE_LOCK('vn.itemShelvingSale_doReserve');
END$$
DELIMITER ;