Merge pull request 'refactor: refs #7680 Added cursors' (!2723) from 7680-saleTicketSetProblem into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #2723
Reviewed-by: Carlos Andrés <carlosap@verdnatura.es>
This commit is contained in:
Guillermo Bonet 2024-07-12 07:04:52 +00:00
commit b1290a539b
2 changed files with 47 additions and 12 deletions

View File

@ -5,14 +5,32 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setProblem`(
BEGIN BEGIN
/** /**
* Update column sale.problem with a problem code * Update column sale.problem with a problem code
*
* @param vProblemCode Code to set or unset * @param vProblemCode Code to set or unset
* @table tmp.sale(saleFk, hasProblem) * @table tmp.sale(saleFk, hasProblem)
*/ */
UPDATE sale s DECLARE vSaleFk INT;
JOIN tmp.sale ts ON ts.saleFk = s.id DECLARE vHasProblem INT;
SET s.problem = CONCAT( DECLARE vDone BOOL;
IF(ts.hasProblem, DECLARE vSaleList CURSOR FOR SELECT saleFk, hasProblem FROM tmp.sale;
CONCAT(s.problem, ',', vProblemCode), DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
REPLACE(s.problem, vProblemCode , '')));
OPEN vSaleList;
l: LOOP
SET vDone = FALSE;
FETCH vSaleList INTO vSaleFk, vHasProblem;
IF vDone THEN
LEAVE l;
END IF;
UPDATE sale
SET problem = CONCAT(
IF(vHasProblem,
CONCAT(problem, ',', vProblemCode),
REPLACE(problem, vProblemCode , '')))
WHERE id = vSaleFk;
END LOOP;
CLOSE vSaleList;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -9,11 +9,28 @@ BEGIN
* @param vProblemCode Code to set or unset * @param vProblemCode Code to set or unset
* @table tmp.ticket(ticketFk, hasProblem) * @table tmp.ticket(ticketFk, hasProblem)
*/ */
UPDATE ticket t DECLARE vTicketFk INT;
JOIN tmp.ticket tt ON tt.ticketFk = t.id DECLARE vHasProblem INT;
SET t.problem = CONCAT( DECLARE vDone BOOL;
IF(tt.hasProblem, DECLARE vTicketList CURSOR FOR SELECT ticketFk, hasProblem FROM tmp.ticket;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
OPEN vTicketList;
l: LOOP
SET vDone = FALSE;
FETCH vTicketList INTO vTicketFk, vHasProblem;
IF vDone THEN
LEAVE l;
END IF;
UPDATE ticket
SET problem = CONCAT(
IF(vHasProblem,
CONCAT(problem, ',', vProblemCode), CONCAT(problem, ',', vProblemCode),
REPLACE(problem, vProblemCode , ''))); REPLACE(problem, vProblemCode , '')))
WHERE id = vTicketFk;
END LOOP;
CLOSE vTicketList;
END$$ END$$
DELIMITER ; DELIMITER ;