Using MySQL mode in H2, found a situation that works for MySQL but not H2.
If inserting and specifying NULL value for an AUTO_INCREMENT column, if there is a duplicate key conflict, H2 silently fails to apply the ON DUPLICATE KEY UPDATE clause.
A simple example:
DROP TABLE IF EXISTS `example`;
CREATE TABLE `example` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`hostname` varchar(64) NOT NULL,
`exit_code` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `host` (`hostname`),
);
INSERT INTO example (id, hostname, exit_code)
VALUES (NULL, 'host', 0)
ON DUPLICATE KEY UPDATE exit_code = 0;
SELECT * FROM example;
INSERT INTO example (id, hostname, exit_code)
VALUES (NULL, 'host', 14)
ON DUPLICATE KEY UPDATE exit_code = 14;
SELECT * FROM example;
The result of that last select shows exit_code 0, when it should be 14.
There is a simple workaround, to change the last INSERT to:
INSERT INTO example (hostname, exit_code)
VALUES ('host', 14)
ON DUPLICATE KEY UPDATE exit_code = 14;
Then it works. Wanted to post here with the question: Do you agree this is a bug?