2024-04-16 15:01:14 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblem`(
|
|
|
|
vProblemCode VARCHAR(25)
|
|
|
|
)
|
|
|
|
BEGIN
|
|
|
|
/**
|
2024-06-27 11:01:42 +00:00
|
|
|
* Update column ticket.problem with a problem code and SET NULL when
|
|
|
|
* the problem is not requiered
|
2024-05-13 11:31:58 +00:00
|
|
|
*
|
|
|
|
* @param vProblemCode Code to set or unset
|
2024-06-27 11:01:42 +00:00
|
|
|
* @table tmp.ticket(ticketFk, hasProblem, isProblemCalcNeeded)
|
2024-04-16 15:01:14 +00:00
|
|
|
*/
|
2024-07-12 06:15:09 +00:00
|
|
|
DECLARE vTicketFk INT;
|
|
|
|
DECLARE vHasProblem INT;
|
|
|
|
DECLARE vDone BOOL;
|
|
|
|
DECLARE vTicketList CURSOR FOR SELECT ticketFk, hasProblem FROM tmp.ticket;
|
|
|
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
2024-06-27 11:01:42 +00:00
|
|
|
|
2024-07-12 06:15:09 +00:00
|
|
|
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),
|
|
|
|
REPLACE(problem, vProblemCode , '')))
|
|
|
|
WHERE id = vTicketFk;
|
|
|
|
END LOOP;
|
|
|
|
CLOSE vTicketList;
|
2024-04-16 15:01:14 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|