views:

38

answers:

1

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` varchar(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.

A: 

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

Remove the "not null" on UpdatedDateTime.

pascal
Hi pascal, that certainly does solve it yes although I'm a little surprised that the constraint is checked first. If anyone else has further thoughts on this then please do share!
karianna
Yes, it's strange. I would have assumed that the `before` trigger occurs before the constraints validation...
pascal