MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:eugene Date:June 6 2007 8:30pm
Subject:bk commit into 5.0 tree (evgen:1.2517) BUG#28505
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of evgen. When evgen 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, 2007-06-07 00:30:00+04:00, evgen@stripped +2 -0
  Bug#28505: mysql_affected_rows() may return wrong result if CLIENT_FOUND_ROWS
  flag is set.
  
  When the CLIENT_FOUND_ROWS flag is set then the server should return
  found number of rows independently whether they were updated or not.
  But this wasn't the case for the INSERT statement which always returned
  number of rows that were actually changed thus providing wrong info to
  the user.
  
  Now the select_insert::send_eof method and the mysql_insert function
  are sending the number of touched rows if the CLIENT_FOUND_ROWS flag is set.

  sql/sql_insert.cc@stripped, 2007-06-07 00:29:51+04:00, evgen@stripped +10 -4
    Bug#28505: mysql_affected_rows() may return wrong result if CLIENT_FOUND_ROWS
    flag is set.
    Now the select_insert::send_eof method and the mysql_insert function
    are sending the number of touched rows if the CLIENT_FOUND_ROWS flag is set.

  tests/mysql_client_test.c@stripped, 2007-06-07 00:29:48+04:00, evgen@stripped +64 -0
    Added a test case for the bug#28505: mysql_affected_rows() may return wrong result
    if CLIENT_FOUND_ROWS flag is set.

# 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:	evgen
# Host:	moonbone.local
# Root:	/mnt/gentoo64/work/28505-bug-5.0-opt-mysql

--- 1.239/sql/sql_insert.cc	2007-05-29 17:27:53 +04:00
+++ 1.240/sql/sql_insert.cc	2007-06-07 00:29:51 +04:00
@@ -947,20 +947,24 @@ bool mysql_insert(THD *thd,TABLE_LIST *t
   if (values_list.elements == 1 && (!(thd->options & OPTION_WARNINGS) ||
 				    !thd->cuted_fields))
   {
-    thd->row_count_func= info.copied+info.deleted+info.updated;
+    thd->row_count_func= info.copied + info.deleted +
+                         ((thd->client_capabilities & CLIENT_FOUND_ROWS) ?
+                          info.touched : info.updated);
     send_ok(thd, (ulong) thd->row_count_func, id);
   }
   else
   {
     char buff[160];
+    ha_rows updated=((thd->client_capabilities & CLIENT_FOUND_ROWS) ?
+                     info.touched : info.updated);
     if (ignore)
       sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
 	      (lock_type == TL_WRITE_DELAYED) ? (ulong) 0 :
 	      (ulong) (info.records - info.copied), (ulong) thd->cuted_fields);
     else
       sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
-	      (ulong) (info.deleted+info.updated), (ulong) thd->cuted_fields);
-    thd->row_count_func= info.copied+info.deleted+info.updated;
+	      (ulong) (info.deleted + updated), (ulong) thd->cuted_fields);
+    thd->row_count_func= info.copied + info.deleted + updated;
     ::send_ok(thd, (ulong) thd->row_count_func, id, buff);
   }
   thd->abort_on_warning= 0;
@@ -2973,7 +2977,9 @@ bool select_insert::send_eof()
   else
     sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
 	    (ulong) (info.deleted+info.updated), (ulong) thd->cuted_fields);
-  thd->row_count_func= info.copied+info.deleted+info.updated;
+  thd->row_count_func= info.copied + info.deleted +
+                       ((thd->client_capabilities & CLIENT_FOUND_ROWS) ?
+                        info.touched : info.updated);
   ::send_ok(thd, (ulong) thd->row_count_func, last_insert_id, buff);
   DBUG_RETURN(0);
 }

--- 1.227/tests/mysql_client_test.c	2007-05-26 00:35:58 +04:00
+++ 1.228/tests/mysql_client_test.c	2007-06-07 00:29:48 +04:00
@@ -15624,6 +15624,69 @@ static void test_bug27876()
 
 
 /*
+  Bug#28505: mysql_affected_rows() returns wrong value if CLIENT_FOUND_ROWS
+  flag is set.
+*/
+static void test_bug28505()
+{
+  MYSQL *l_mysql;
+  my_bool error= 0;
+  my_ulonglong res;
+
+  if (!(l_mysql= mysql_init(NULL)))
+  {
+    myerror("mysql_init() failed");
+    DIE_UNLESS(1);
+  }
+  if (!(mysql_real_connect(l_mysql, opt_host, opt_user,
+                           opt_password, current_db, opt_port,
+                           opt_unix_socket, CLIENT_FOUND_ROWS)))
+  {
+    myerror("connection failed");
+    error= 1;
+    goto end;
+  }
+  l_mysql->reconnect= 1;
+  if (mysql_query(l_mysql, "drop table if exists t1"))
+  {
+    myerror(NULL);
+    error= 1;
+    goto end;
+  }
+  if (mysql_query(l_mysql, "create table t1(f1 int primary key)"))
+  {
+    myerror(NULL);
+    error= 1;
+    goto end;
+  }
+  if (mysql_query(l_mysql, "insert into t1 values(1)"))
+  {
+    myerror(NULL);
+    error= 1;
+    goto end;
+  }
+  if (mysql_query(l_mysql,
+                  "insert into t1 values(1) on duplicate key update f1=1"))
+  {
+    myerror(NULL);
+    error= 1;
+    goto end;
+  }
+  res= mysql_affected_rows(l_mysql);
+  if (!res)
+    error= 1;
+  if (mysql_query(l_mysql, "drop table t1"))
+  {
+    myerror(NULL);
+    error= 1;
+  }
+end:
+  mysql_close(l_mysql);
+  DIE_UNLESS(error == 0);
+}
+
+
+/*
   Read and parse arguments and MySQL options from my.cnf
 */
 
@@ -15904,6 +15967,7 @@ static struct my_tests_st my_tests[]= {
   { "test_bug21635", test_bug21635 },
   { "test_bug24179", test_bug24179 },
   { "test_bug27876", test_bug27876 },
+  { "test_bug28505", test_bug28505 },
   { 0, 0 }
 };
 
Thread
bk commit into 5.0 tree (evgen:1.2517) BUG#28505eugene6 Jun