Below is the list of changes that have just been committed into a local
4.1 repository of ram. When ram does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet
1.2481 06/05/24 17:18:02 ramil@stripped +3 -0
Fix for bug #6880: LAST_INSERT_ID() value changes during multi-row INSERT.
sql/handler.cc
1.172 06/05/24 17:17:55 ramil@stripped +5 -1
Fix for bug #6880: LAST_INSERT_ID() value changes during multi-row INSERT.
- don't change the last_insert_id during multi-row inserts.
mysql-test/t/auto_increment.test
1.25 06/05/24 17:17:55 ramil@stripped +17 -0
Fix for bug #6880: LAST_INSERT_ID() value changes during multi-row INSERT.
- test case.
mysql-test/r/auto_increment.result
1.33 06/05/24 17:17:55 ramil@stripped +22 -0
Fix for bug #6880: LAST_INSERT_ID() value changes during multi-row INSERT.
- test result.
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: ramil
# Host: myoffice.izhnet.ru
# Root: /usr/home/ram/work/4.1.b6880
--- 1.171/sql/handler.cc 2005-11-21 15:27:55 +04:00
+++ 1.172/sql/handler.cc 2006-05-24 17:17:55 +05:00
@@ -1030,7 +1030,11 @@ void handler::update_auto_increment()
else
nr=get_auto_increment();
if (!table->next_number_field->store(nr))
- thd->insert_id((ulonglong) nr);
+ {
+ /* Don't change the last_insert_id during the same query */
+ if (!thd->last_insert_id_used)
+ thd->insert_id((ulonglong) nr);
+ }
else
thd->insert_id(table->next_number_field->val_int());
auto_increment_column_changed=1;
--- 1.32/mysql-test/r/auto_increment.result 2006-05-04 06:12:47 +05:00
+++ 1.33/mysql-test/r/auto_increment.result 2006-05-24 17:17:55 +05:00
@@ -378,4 +378,26 @@ t1 CREATE TABLE `t1` (
KEY `t1_name` (`t1_name`)
) ENGINE=MyISAM AUTO_INCREMENT=1003 DEFAULT CHARSET=latin1
DROP TABLE `t1`;
+create table t1(a int not null auto_increment primary key);
+create table t2(a int not null auto_increment primary key, t1a int);
+insert into t1 values(NULL);
+insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID());
+insert into t1 values (NULL);
+insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID()),
+(NULL, LAST_INSERT_ID());
+insert into t1 values (NULL);
+insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID()),
+(NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID());
+select * from t2;
+a t1a
+1 1
+2 1
+3 2
+4 2
+5 2
+6 3
+7 3
+8 3
+9 3
+drop table t1, t2;
End of 4.1 tests
--- 1.24/mysql-test/t/auto_increment.test 2006-05-04 06:12:47 +05:00
+++ 1.25/mysql-test/t/auto_increment.test 2006-05-24 17:17:55 +05:00
@@ -238,4 +238,21 @@ SHOW CREATE TABLE `t1`;
DROP TABLE `t1`;
+#
+# Bug #6880: LAST_INSERT_ID() within a statement
+#
+
+create table t1(a int not null auto_increment primary key);
+create table t2(a int not null auto_increment primary key, t1a int);
+insert into t1 values(NULL);
+insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID());
+insert into t1 values (NULL);
+insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID()),
+(NULL, LAST_INSERT_ID());
+insert into t1 values (NULL);
+insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID()),
+(NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID());
+select * from t2;
+drop table t1, t2;
+
--echo End of 4.1 tests
| Thread |
|---|
| • bk commit into 4.1 tree (ramil:1.2481) BUG#6880 | ramil | 24 May |