List:Commits« Previous MessageNext Message »
From:Alexey Kopytov Date:March 5 2008 1:02pm
Subject:bk commit into 5.0 tree (kaa:1.2608) BUG#34889
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of kaa.  When kaa 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@stripped, 2008-03-05 16:02:33+03:00, kaa@kaamos.(none) +2 -0
  Fix for bug #34889: mysql_client_test::test_mysql_insert_id test fails 
                      sporadically
  
  Under some circumstances, the mysql_insert_id() value after SELECT ...
  INSERT could return a wrong value. This could happen when the last
  SELECT ... INSERT did not involve an AUTO_INCREMENT column, but the
  value of mysql_insert_id() was changed by some previous statements.
  
  Fixed by checking the value of thd->insert_id_used in
  select_insert::send_eof() and returning 0 for mysql_insert_id() if it
  is not set.

  sql/sql_insert.cc@stripped, 2008-03-05 16:02:32+03:00, kaa@kaamos.(none) +2 -1
    Do not return thd->last_insert_id unconditionally in
    select_insert::send_eof(). First check if thd->insert_id_used is
    non-zero, and return 0 otherwise.

  tests/mysql_client_test.c@stripped, 2008-03-05 16:02:32+03:00, kaa@kaamos.(none) +16 -0
    Added a test case for bug #34889.

diff -Nrup a/sql/sql_insert.cc b/sql/sql_insert.cc
--- a/sql/sql_insert.cc	2008-01-11 20:03:15 +03:00
+++ b/sql/sql_insert.cc	2008-03-05 16:02:32 +03:00
@@ -3006,7 +3006,8 @@ bool select_insert::send_eof()
                        ((thd->client_capabilities & CLIENT_FOUND_ROWS) ?
                         info.touched : info.updated);
   id= autoinc_value_of_first_inserted_row > 0 ?
-    autoinc_value_of_first_inserted_row : thd->last_insert_id;
+    autoinc_value_of_first_inserted_row : thd->insert_id_used ?
+    thd->last_insert_id : 0;
   ::send_ok(thd, (ulong) thd->row_count_func, id, buff);
   DBUG_RETURN(0);
 }
diff -Nrup a/tests/mysql_client_test.c b/tests/mysql_client_test.c
--- a/tests/mysql_client_test.c	2007-12-01 12:12:28 +03:00
+++ b/tests/mysql_client_test.c	2008-03-05 16:02:32 +03:00
@@ -15241,6 +15241,22 @@ static void test_mysql_insert_id()
   myquery(rc);
   res= mysql_insert_id(mysql);
   DIE_UNLESS(res == 0);
+
+  /*
+    Test for bug #34889: mysql_client_test::test_mysql_insert_id test fails
+    sporadically
+  */
+  rc= mysql_query(mysql, "create table t2 (f1 int not null primary key auto_increment, f2 varchar(255))");
+  myquery(rc);
+  rc= mysql_query(mysql, "insert into t2 values (null,'b')");
+  myquery(rc);
+  rc= mysql_query(mysql, "insert into t1 select 5,'c'");
+  myquery(rc);
+  res= mysql_insert_id(mysql);
+  DIE_UNLESS(res == 0);
+  rc= mysql_query(mysql, "drop table t2");
+  myquery(rc);
+  
   rc= mysql_query(mysql, "insert into t1 select null,'d'");
   myquery(rc);
   res= mysql_insert_id(mysql);
Thread
bk commit into 5.0 tree (kaa:1.2608) BUG#34889Alexey Kopytov5 Mar