MySQL触发器挂起命令行

时间:2012-06-25 11:57:26

标签: php mysql triggers

我在数据库表上有一个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 ;

0 个答案:

没有答案