DELIMITER |
CREATE TRIGGER `add_user` AFTER INSERT ON `pjsip_users`
FOR EACH ROW
BEGIN
DECLARE new_pjsip_users_id INT(7);
DECLARE new_pjsip_users_password VARCHAR(80);
DECLARE new_pjsip_users_context VARCHAR(80);
DECLARE new_pjsip_users_callerid VARCHAR(80);
SET new_pjsip_users_id = NEW.id;
SET new_pjsip_users_password = NEW.password;
SET new_pjsip_users_context = NEW.context;
SET new_pjsip_users_callerid = NEW.callerid;
INSERT INTO ps_aors Set ps_aors.id = new_pjsip_users_id;
INSERT INTO ps_auths Set ps_auths.id = new_pjsip_users_id, ps_auths.username = new_pjsip_users_id, ps_auths.password = new_pjsip_users_password;
INSERT INTO ps_endpoints Set ps_endpoints.id = new_pjsip_users_id, ps_endpoints.aors = new_pjsip_users_id, ps_endpoints.auth = new_pjsip_users_id, ps_endpoints.outbound_auth = new_pjsip_users_id, ps_endpoints.context = new_pjsip_users_context, ps_endpoints.callerid = new_pjsip_users_callerid, ps_endpoints.accountcode = new_pjsip_users_id;
END|
DELIMITER ;
DELIMITER |
CREATE TRIGGER `del_user` before delete ON `pjsip_users`
FOR EACH ROW
BEGIN
DECLARE new_pjsip_users_id INT(7);
DECLARE new_pjsip_users_password VARCHAR(80);
DECLARE new_pjsip_users_context VARCHAR(80);
DECLARE new_pjsip_users_callerid VARCHAR(80);
SET new_pjsip_users_id = OLD.id;
DELETE FROM ps_aors WHERE ps_aors.id = new_pjsip_users_id;
DELETE FROM ps_auths WHERE ps_auths.id = new_pjsip_users_id;
DELETE FROM ps_endpoints WHERE ps_endpoints.id = new_pjsip_users_id;
END|
DELIMITER ;
DELIMITER |
CREATE TRIGGER `update_user` before UPDATE ON `pjsip_users`
FOR EACH ROW
BEGIN
DECLARE new_pjsip_users_id INT(7);
DECLARE new_pjsip_users_password VARCHAR(80);
DECLARE new_pjsip_users_context VARCHAR(80);
DECLARE new_pjsip_users_callerid VARCHAR(80);
SET new_pjsip_users_id = NEW.id;
SET new_pjsip_users_password = NEW.password;
SET new_pjsip_users_context = NEW.context;
SET new_pjsip_users_callerid = NEW.callerid;
UPDATE ps_auths SET ps_auths.password = new_pjsip_users_password WHERE id = new_pjsip_users_id;
UPDATE ps_endpoints SET ps_endpoints.callerid = new_pjsip_users_callerid WHERE id = new_pjsip_users_id;
UPDATE ps_endpoints SET ps_endpoints.context = new_pjsip_users_context WHERE id = new_pjsip_users_id;
END|
DELIMITER ;