36 lines
843 B
SQL
36 lines
843 B
SQL
DELIMITER $$
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblem`(
|
|
vProblemCode VARCHAR(25)
|
|
)
|
|
BEGIN
|
|
/**
|
|
* Update column ticket.problem with a problem code
|
|
*
|
|
* @param vProblemCode Code to set or unset
|
|
* @table tmp.ticket(ticketFk, hasProblem)
|
|
*/
|
|
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;
|
|
|
|
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;
|
|
END$$
|
|
DELIMITER ; |