mysql
DROP TRIGGER IF EXISTS t_afterinsert_invitation_trigger ;
DELIMITER $$
CREATE TRIGGER t_afterinsert_invitation_trigger
AFTER INSERT ON invitation_trigger
FOR EACH ROW
BEGIN
declare _mid int;
declare _parent_level int;
declare _mids int;
declare _l int;
declare _r varchar(50);
set _mid = New.mid;
set _parent_level = New.midlevel;
set _mids = New.mids;
<code>INSERT INTO `test`.`invitation` (`id`, `mid`, `midlevel`, `mids`, `midslevel`) VALUES (New.id, _mid, _parent_level, _mids, New.midslevel);UPDATE invitation _up INNER JOIN (SELECT T2.midFROM ( SELECT _r AS _mids, (SELECT _r = mid FROM invitation WHERE mids = _mids) AS mid, _l = _l + 1 AS lvl FROM (SELECT _r = New.mid, _l = 0) vars, invitation h WHERE _r 0) T1 JOIN invitation T2 ON T1._mids = T2.mids AND T2.midlevel > New.midlevelORDER BY T1.lvl ASC) BON _up.mid = B.midSET _up.midlevel = New.midlevel;INSERT INTO `test`.`invitation` (`id`, `mid`, `midlevel`, `mids`, `midslevel`) VALUES ('42', '14', '2', '43', '3');</code>
END$$
DELIMITER ;