我在数据库表上有一个 mySQL 触发器。当从通过 PHP 连接到数据库的应用程序更新表时,触发器会完美触发并更新。但是,如果我尝试使用 phpMyAdmin 中的 mySQL 命令行更新该表中的一行,那么数据库似乎只是挂起?我一生都无法弄清楚是什么原因造成的,或者如何调试它。如果有人能看到任何明显的东西,那就是触发器(或者甚至如何使它更有效,因为触发器对我来说是新的!)!
提前致谢!
DROP TRIGGER IF EXISTS `t_crewstatusupdate`;
DELIMITER //
CREATE TRIGGER `t_crewstatusupdate` AFTER UPDATE ON `crewcallouts`
FOR EACH ROW
BEGIN
DECLARE taxmultiplier INT;
SET taxmultiplier = ( SELECT t1.taxmultiplier
FROM entities t1, callouts t2
WHERE t1.entityid=t2.entityid
AND t2.calloutid=NEW.calloutid
);
IF NEW.status != OLD.status THEN
UPDATE callouts
SET status = CASE ( SELECT MIN(status)
FROM crewcallouts
WHERE calloutid=NEW.calloutid
) WHEN 1 THEN 1
WHEN 2 THEN 2
WHEN 3 THEN 4
WHEN 4 THEN 4
WHEN 5 THEN 4
WHEN 6 THEN 4
WHEN 7 THEN 7
END
WHERE calloutid=new.calloutid;
END IF;
UPDATE calloutstats
SET netcrewcost = ( SELECT SUM(get_gross_amount(
( SELECT calloutdate
from callouts
WHERE calloutid=NEW.calloutid
),
( SELECT starttime
from callouts
WHERE calloutid=NEW.calloutid
),
(workhours + extrahrs),
crewrate,
1,
IFNULL(travelhours,0) )
)
FROM crewcallouts
WHERE calloutid=NEW.calloutid
),
grosscrewcost = ( SELECT SUM(get_gross_amount((SELECT calloutdate from callouts WHERE calloutid=NEW.calloutid),(SELECT starttime from callouts WHERE calloutid=NEW.calloutid),(workhours + extrahrs),crewrate,1, IFNULL(travelhours,0))
* taxmultiplier)
FROM crewcallouts
WHERE calloutid=NEW.calloutid
)
WHERE calloutid=NEW.calloutid;
END
//
DELIMITER ;