mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Bug#27033: 0 as LAST_INSERT_ID() after INSERT .. ON DUPLICATE if rows were
touched but not actually changed. The LAST_INSERT_ID() is reset to 0 if no rows were inserted or changed. This is the case when an INSERT ... ON DUPLICATE KEY UPDATE updates a row with the same values as the row contains. Now the LAST_INSERT_ID() values is reset to 0 only if there were no rows successfully inserted or touched. The new 'touched' field is added to the COPY_INFO structure. It holds the number of rows that were touched no matter whether they were actually changed or not.
This commit is contained in:
@ -236,3 +236,14 @@ INSERT INTO t2 VALUES (1), (3);
|
||||
INSERT INTO t1 SELECT 1, COUNT(*) FROM t2 ON DUPLICATE KEY UPDATE j= a;
|
||||
ERROR 42S22: Unknown column 'a' in 'field list'
|
||||
DROP TABLE t1,t2;
|
||||
CREATE TABLE t1 (f1 INT AUTO_INCREMENT PRIMARY KEY,
|
||||
f2 VARCHAR(5) NOT NULL UNIQUE);
|
||||
INSERT t1 (f2) VALUES ('test') ON DUPLICATE KEY UPDATE f1 = LAST_INSERT_ID(f1);
|
||||
SELECT LAST_INSERT_ID();
|
||||
LAST_INSERT_ID()
|
||||
1
|
||||
INSERT t1 (f2) VALUES ('test') ON DUPLICATE KEY UPDATE f1 = LAST_INSERT_ID(f1);
|
||||
SELECT LAST_INSERT_ID();
|
||||
LAST_INSERT_ID()
|
||||
1
|
||||
DROP TABLE t1;
|
||||
|
Reference in New Issue
Block a user