打破循环引用将需要另一台例如:
CREATE TABLE `trigger_semaphore` (
`id` INTEGER(11) NOT NULL,
`semaphore` INTEGER(11) DEFAULT NULL,
`actions` VARCHAR(20) COLLATE utf8_general_ci DEFAULT NULL,
`random` INTEGER(11) DEFAULT NULL,
PRIMARY KEY (`id`)
)ENGINE=MyISAM
CHARACTER SET 'latin1' COLLATE 'latin1_swedish_ci';
CREATE DEFINER = 'root'@'localhost' TRIGGER `trigger_semaphore_before_upd_tr`
BEFORE UPDATE ON `trigger_semaphore`
FOR EACH ROW
BEGIN
DECLARE semaphore int;
set New.random=RAND()*1000;
if New.actions='++' then
set New.semaphore=COALESCE(New.semaphore,0)+1;
elseif New.actions='--' then
set semaphore= COALESCE(New.semaphore,0);
if semaphore<=0 then
set New.semaphore=semaphore;
else
set New.semaphore=semaphore-1;
end if;
end if;
END;
在其触发器的更新表彼此使用trigger_semaphore表 以这种方式:
update trigger_semaphore set actions='++' where id=1;
select semaphore into _semaphore from trigger_semaphore where id=1;
if _semaphore=1 then
# ...... Here goes the code without circular reference..........
end if;
版本现在触发结束的信号
update trigger_semaphore set actions='--' where id=1;
总之,首先设置信号量的表(1)只能执行某些 语句。一旦你得到这个想法,你可以使用一个简单的方法;)
当我使用相同的表的所有触发操作我得到这个错误。 – maxy 2009-09-30 06:09:05
@maxy,对,我意识到这一点。这是我在我的回答中试图解释的;你不能有一个直接的循环引用,并且,你需要打破递归... – mjv 2009-09-30 06:28:21
我怎么能打破这..有任何其他的解决方案.. – maxy 2009-09-30 06:58:07