salix/db/routines/vn/triggers/sharingCart_beforeInsert.sql

16 lines
502 B
SQL

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`sharingCart_beforeInsert`
BEFORE INSERT ON `sharingCart`
FOR EACH ROW
BEGIN
IF NEW.workerFk = NEW.workerSubstitute THEN
CALL util.throw ('worker and workerSubstitute must be different');
ELSE
INSERT IGNORE INTO sharingCartDaily (ownerFk, substituteFk, dated)
SELECT NEW.workerFk, NEW.workerSubstitute, dated
FROM time
WHERE dated BETWEEN NEW.started AND NEW.ended;
END IF;
END$$
DELIMITER ;