开发者

MySQL INSERT BEFORE TRIGGER Fails?

I'm running MySQL 5.1.48 on Windows XP and the following trigger test doesn't work:

-- Drop the old table
DROP TABLE IF EXISTS `ikasan01`.`ikasanwiretap`;

-- Create
CREATE TABLE  `ikasan01`.`ikasanwiretap` (
 `Id` bigint(20) NOT NULL AUTO_INCREMENT,
 `ModuleName` varchar(255) NOT NULL,
 `FlowName` varchar(255) NOT NULL,
 `ComponentName` varchar(255) NOT NULL,
 `EventId` varchar(255) NOT NULL,
 `PayloadId` varchar(255) NOT NULL,
 `PayloadContent` varc开发者_运维技巧har(255) NOT NULL,
 `CreatedDateTime` datetime NOT NULL,
 `UpdatedDateTime` datetime NOT NULL,
 `Expiry` datetime NOT NULL,
 PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- In order to use now() as a DEFAULT value on a datetime column we
have to do it via a BEFORE INSERT TRIGGER
CREATE TRIGGER defaultUpdateDateTime
BEFORE INSERT ON ikasanwiretap FOR EACH ROW
SET NEW.UpdatedDateTime = now();

-- Test the trigger
insert into IkasanWiretap (ModuleName, FlowName, ComponentName,
EventId, PayloadId, PayloadContent, CreatedDateTime, Expiry) values
('3', '3', '3', '3', '3', '3', now(), now());

On my trigger test I still get the MySQL server stating that the UpdateDateTime has no default value.

I've tried just about everything at my disposal so I thought I'd ask you helpful lot ;) Any ideas?

Cheers, Martijn

PS: X-posted on the London Java User Group and the Ikasan EIP Mailing list.


I guess the trigger is started after the "not null" constraints are verified.

Remove the "not null" on UpdatedDateTime.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜