mirror of
https://github.com/MariaDB/server.git
synced 2026-01-06 05:22:24 +03:00
Bug#23233: 0 as LAST_INSERT_ID() after INSERT .. ON DUPLICATE in the
NO_AUTO_VALUE_ON_ZERO mode. In the NO_AUTO_VALUE_ON_ZERO mode the table->auto_increment_field_not_null variable is used to indicate that a non-NULL value was specified by the user for an auto_increment column. When an INSERT .. ON DUPLICATE updates the auto_increment field this variable is set to true and stays unchanged for the next insert operation. This makes the next inserted row sometimes wrongly have 0 as the value of the auto_increment field. Now the fill_record() function resets the table->auto_increment_field_not_null variable before filling the record. The table->auto_increment_field_not_null variable is also reset by the open_table() function for a case if we missed some auto_increment_field_not_null handling bug. Now the table->auto_increment_field_not_null is reset at the end of the mysql_load() function. Reset the table->auto_increment_field_not_null variable after each write_row() call in the copy_data_between_tables() function.
This commit is contained in:
@@ -258,3 +258,81 @@ SELECT LAST_INSERT_ID();
|
||||
LAST_INSERT_ID()
|
||||
1
|
||||
DROP TABLE t1;
|
||||
SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO';
|
||||
CREATE TABLE `t1` (
|
||||
`id` int(11) PRIMARY KEY auto_increment,
|
||||
`f1` varchar(10) NOT NULL UNIQUE
|
||||
);
|
||||
INSERT IGNORE INTO t1 (f1) VALUES ("test1")
|
||||
ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);
|
||||
INSERT IGNORE INTO t1 (f1) VALUES ("test1")
|
||||
ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);
|
||||
SELECT LAST_INSERT_ID();
|
||||
LAST_INSERT_ID()
|
||||
1
|
||||
SELECT * FROM t1;
|
||||
id f1
|
||||
1 test1
|
||||
INSERT IGNORE INTO t1 (f1) VALUES ("test2")
|
||||
ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);
|
||||
SELECT * FROM t1;
|
||||
id f1
|
||||
1 test1
|
||||
2 test2
|
||||
INSERT IGNORE INTO t1 (f1) VALUES ("test2")
|
||||
ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);
|
||||
SELECT LAST_INSERT_ID();
|
||||
LAST_INSERT_ID()
|
||||
2
|
||||
SELECT * FROM t1;
|
||||
id f1
|
||||
1 test1
|
||||
2 test2
|
||||
INSERT IGNORE INTO t1 (f1) VALUES ("test3")
|
||||
ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);
|
||||
SELECT LAST_INSERT_ID();
|
||||
LAST_INSERT_ID()
|
||||
3
|
||||
SELECT * FROM t1;
|
||||
id f1
|
||||
1 test1
|
||||
2 test2
|
||||
3 test3
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE `t1` (
|
||||
`id` int(11) PRIMARY KEY auto_increment,
|
||||
`f1` varchar(10) NOT NULL UNIQUE
|
||||
);
|
||||
INSERT IGNORE INTO t1 (f1) VALUES ("test1")
|
||||
ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);
|
||||
SELECT LAST_INSERT_ID();
|
||||
LAST_INSERT_ID()
|
||||
1
|
||||
SELECT * FROM t1;
|
||||
id f1
|
||||
1 test1
|
||||
INSERT IGNORE INTO t1 (f1) VALUES ("test1"),("test4")
|
||||
ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);
|
||||
SELECT LAST_INSERT_ID();
|
||||
LAST_INSERT_ID()
|
||||
1
|
||||
SELECT * FROM t1;
|
||||
id f1
|
||||
1 test1
|
||||
2 test4
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE `t1` (
|
||||
`id` int(11) PRIMARY KEY auto_increment,
|
||||
`f1` varchar(10) NOT NULL UNIQUE,
|
||||
tim1 timestamp default '2003-01-01 00:00:00' on update current_timestamp
|
||||
);
|
||||
INSERT INTO t1 (f1) VALUES ("test1");
|
||||
SELECT id, f1 FROM t1;
|
||||
id f1
|
||||
1 test1
|
||||
REPLACE INTO t1 VALUES (0,"test1",null);
|
||||
SELECT id, f1 FROM t1;
|
||||
id f1
|
||||
0 test1
|
||||
DROP TABLE t1;
|
||||
SET SQL_MODE='';
|
||||
|
||||
Reference in New Issue
Block a user