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

41 lines
1.0 KiB
MySQL
Raw Normal View History

DELIMITER $$
2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_setProblem`(
vProblemCode VARCHAR(25)
)
BEGIN
/**
* Update column ticket.problem with a problem code and SET NULL when
* the problem is not requiered
*
* @param vProblemCode Code to set or unset
* @table tmp.ticket(ticketFk, hasProblem, isProblemCalcNeeded)
*/
2024-07-12 06:15:09 +00:00
DECLARE vTicketFk INT;
DECLARE vHasProblem INT;
DECLARE vIsProblemCalcNeeded BOOL;
2024-07-12 06:15:09 +00:00
DECLARE vDone BOOL;
DECLARE vTicketList CURSOR FOR
SELECT ticketFk, hasProblem, isProblemCalcNeeded
FROM tmp.ticket;
2024-07-12 06:15:09 +00:00
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
2024-07-12 06:15:09 +00:00
OPEN vTicketList;
l: LOOP
SET vDone = FALSE;
FETCH vTicketList INTO vTicketFk, vHasProblem, vIsProblemCalcNeeded;
2024-07-12 06:15:09 +00:00
IF vDone THEN
LEAVE l;
END IF;
UPDATE ticket
SET problem = IF(vIsProblemCalcNeeded,
CONCAT(IF(vHasProblem,
2024-07-12 06:15:09 +00:00
CONCAT(problem, ',', vProblemCode),
REPLACE(problem, vProblemCode , ''))),
NULL)
2024-07-12 06:15:09 +00:00
WHERE id = vTicketFk;
END LOOP;
CLOSE vTicketList;
END$$
DELIMITER ;