I have prepared an before update trigger in which I have encoded hierarchical relation:
CREATE DEFINER=`%`@`%` TRIGGER setToClosed
BEFORE UPDATE ON issues
FOR EACH ROW
BEGIN
declare project_id1 int;
set @project_id1 = (select id from projects where name = 'XXX');
IF (new.done_ratio=100) THEN
IF (new.project_id = @project_id1) THEN
SET new.status_id=4;
ELSEIF new.project_id in (
select id
from (select * from projects) projects_sorted,
(select @pv := @project_id1) initialisation
where find_in_set(parent_id, @pv) > 0
and @pv := concat(@pv, ',', id)) THEN
SET new.status_id=4;
ELSE
SET new.status_id=5;
END IF;
END IF;
END
I would like to ask why ELSEIF is not reached? I have tested a standalone query from ELSEIF ant it returns list of ids.
After changes in row which status_id is present in ELSEIF query a trigger enters to ELSE.
How should I proceed ?