diff options
author | unknown <guilhem@gbichot3.local> | 2006-09-06 12:52:59 +0200 |
---|---|---|
committer | unknown <guilhem@gbichot3.local> | 2006-09-06 12:52:59 +0200 |
commit | 325c699eff9677ad6d42bad7275dead40c11ad29 (patch) | |
tree | a9b754dd9ec02dd2aa7dc2fff56830a1c3e2397f /mysql-test | |
parent | 716b3e5435b3b58130628729f173d90c5462fab6 (diff) | |
parent | c3cef377feda5fd32e18376b4176a928ba50354b (diff) | |
download | mariadb-git-325c699eff9677ad6d42bad7275dead40c11ad29.tar.gz |
Merge gbichot@bk-internal.mysql.com:/home/bk/mysql-5.1-maint
into gbichot3.local:/home/mysql_src/mysql-5.1-2
Diffstat (limited to 'mysql-test')
-rw-r--r-- | mysql-test/r/innodb_mysql.result | 30 | ||||
-rw-r--r-- | mysql-test/t/innodb_mysql.test | 21 |
2 files changed, 44 insertions, 7 deletions
diff --git a/mysql-test/r/innodb_mysql.result b/mysql-test/r/innodb_mysql.result index a5b263b759d..98e03239567 100644 --- a/mysql-test/r/innodb_mysql.result +++ b/mysql-test/r/innodb_mysql.result @@ -432,22 +432,44 @@ ifnull( c, 0 ) + 1; select last_insert_id(); last_insert_id() -1 +2 +select last_insert_id(0); +last_insert_id(0) +0 +insert into t2 ( a ) values ( 6 ) on duplicate key update c = +ifnull( c, +0 ) + 1; +select last_insert_id(); +last_insert_id() +0 select * from t2; k a c -1 6 1 +1 6 2 2 7 NULL insert ignore into t2 values (null,6,1),(10,8,1); select last_insert_id(); last_insert_id() -1 +0 insert ignore into t2 values (null,6,1),(null,8,1),(null,15,1),(null,20,1); select last_insert_id(); last_insert_id() 11 select * from t2; k a c -1 6 1 +1 6 2 +2 7 NULL +10 8 1 +11 15 1 +12 20 1 +insert into t2 ( a ) values ( 6 ) on duplicate key update c = +ifnull( c, +0 ) + 1, k=last_insert_id(k); +select last_insert_id(); +last_insert_id() +1 +select * from t2; +k a c +1 6 3 2 7 NULL 10 8 1 11 15 1 diff --git a/mysql-test/t/innodb_mysql.test b/mysql-test/t/innodb_mysql.test index d61509317ca..73c642cd334 100644 --- a/mysql-test/t/innodb_mysql.test +++ b/mysql-test/t/innodb_mysql.test @@ -369,8 +369,8 @@ insert into t1 values('aaa'); drop table t1; # Fix for BUG#19243 "wrong LAST_INSERT_ID() after ON DUPLICATE KEY -# UPDATE": now LAST_INSERT_ID() will return the id of the updated -# row. +# UPDATE": if the row is updated, it's like a regular UPDATE: +# LAST_INSERT_ID() is not affected. CREATE TABLE `t2` ( `k` int(11) NOT NULL auto_increment, `a` int(11) default NULL, @@ -390,6 +390,12 @@ insert into t2 ( a ) values ( 6 ) on duplicate key update c = ifnull( c, 0 ) + 1; select last_insert_id(); +# test again when last_insert_id() is 0 initially +select last_insert_id(0); +insert into t2 ( a ) values ( 6 ) on duplicate key update c = +ifnull( c, +0 ) + 1; +select last_insert_id(); select * from t2; # Test of LAST_INSERT_ID() when autogenerated will fail: @@ -402,5 +408,14 @@ insert ignore into t2 values (null,6,1),(null,8,1),(null,15,1),(null,20,1); select last_insert_id(); select * from t2; -drop table t2; +# Test of the workaround which enables people to know the id of the +# updated row in INSERT ON DUPLICATE KEY UPDATE, by using +# LAST_INSERT_ID(autoinc_col) in the UPDATE clause. +insert into t2 ( a ) values ( 6 ) on duplicate key update c = +ifnull( c, +0 ) + 1, k=last_insert_id(k); +select last_insert_id(); +select * from t2; + +drop table t2; |