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

52 lines
1.1 KiB
MySQL
Raw Normal View History

2024-01-31 06:11:03 +00:00
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` PROCEDURE `vn`.`itemShelvingSale_doReserve`()
2024-01-31 06:11:03 +00:00
proc: BEGIN
/**
* Genera reservas de la tabla vn.itemShelvingSaleReserve
2024-01-31 06:11:03 +00:00
*/
DECLARE vDone BOOL;
DECLARE vSaleFk INT;
DECLARE vSales CURSOR FOR
SELECT DISTINCT saleFk FROM tSale;
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
SELECT id, saleFk FROM itemShelvingSaleReserve;
2024-01-31 06:11:03 +00:00
OPEN vSales;
myLoop: LOOP
SET vDone = FALSE;
FETCH vSales INTO vSaleFk;
IF vDone THEN
LEAVE myLoop;
END IF;
CALL itemShelvingSale_addBySale (vSaleFk);
END LOOP;
CLOSE vSales;
DELETE iss FROM itemShelvingSaleReserve iss JOIN tSale s ON s.id = iss.id;
2024-01-31 06:11:03 +00:00
DROP TEMPORARY TABLE tSale;
DO RELEASE_LOCK('vn.itemShelvingSale_doReserve');
END$$
DELIMITER ;