salix/db/routines/stock/procedures/stock_refreshAll.sql

33 lines
802 B
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `stock`.`stock_refreshAll`()
BEGIN
/**
* Recalculates the entire cache. It takes a considerable time,
* please avoid calls to this procedure from commonly used operations.
*/
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
DO RELEASE_LOCK('stock.stock_sync');
RESIGNAL;
END;
IF !GET_LOCK('stock.stock_sync', 30) THEN
CALL util.throw('Lock timeout exceeded');
END IF;
2025-02-18 14:58:38 +00:00
DELETE p FROM buyPick p JOIN buy b USING(buyFk);
TRUNCATE TABLE buyLot;
TRUNCATE TABLE buyOut;
2025-02-18 14:58:38 +00:00
CALL buyLot_refresh(NULL, NULL);
CALL buyOut_refreshSale(NULL, NULL);
CALL buyOut_refreshBuy(NULL, NULL);
CALL buyOut_refreshOrder(NULL, NULL);
2025-02-18 14:58:38 +00:00
UPDATE buyOut SET isSync = TRUE;
CALL stock_sync;
DO RELEASE_LOCK('stock.stock_sync');
END$$
DELIMITER ;