List:Commits« Previous MessageNext Message »
From:kroki Date:November 17 2006 9:21am
Subject:bk commit into 4.1 tree (kroki:1.2551) BUG#23383
View as plain text  
Below is the list of changes that have just been committed into a local
4.1 repository of tomash. When tomash 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, 2006-11-17 12:21:32+03:00, kroki@stripped +3 -0
  BUG#23383: mysql_affected_rows() returns different values than
  mysql_stmt_affected_rows()
  
  The problem was that affected_rows for prepared statement wasn't updated
  in the client library on the error.  The solution is to always update
  affected_rows, which will be equal to -1 on the error.

  libmysql/libmysql.c@stripped, 2006-11-17 12:21:30+03:00, kroki@stripped +9 -5
    Update status variables even in the case of an error.  Some variables
    have a defined value on the error (like affected_rows is -1), others are
    undefined, so updating them won't harm.

  libmysqld/lib_sql.cc@stripped, 2006-11-17 12:21:30+03:00, kroki@stripped +9 -5
    Update status variables even in the case of an error.  Some variables
    have a defined value on the error (like affected_rows is -1), others are
    undefined, so updating them won't harm.

  tests/mysql_client_test.c@stripped, 2006-11-17 12:21:30+03:00, kroki@stripped +78 -0
    Add test for bug#23383: mysql_affected_rows() returns different values
    than mysql_stmt_affected_rows().

# 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:	kroki
# Host:	moonlight.intranet
# Root:	/home/tomash/src/mysql_ab/mysql-4.1-bug23383

--- 1.304/libmysql/libmysql.c	2006-11-17 12:21:37 +03:00
+++ 1.305/libmysql/libmysql.c	2006-11-17 12:21:37 +03:00
@@ -2496,6 +2496,8 @@ static my_bool execute(MYSQL_STMT *stmt,
   NET	*net= &mysql->net;
   char buff[4 /* size of stmt id */ +
             5 /* execution flags */];
+  my_bool res;
+
   DBUG_ENTER("execute");
   DBUG_PRINT("enter",("packet: %s, length :%d",packet ? packet :" ", length));
 
@@ -2503,15 +2505,17 @@ static my_bool execute(MYSQL_STMT *stmt,
   int4store(buff, stmt->stmt_id);		/* Send stmt id to server */
   buff[4]= (char) 0;                            /* no flags */
   int4store(buff+5, 1);                         /* iteration count */
-  if (cli_advanced_command(mysql, COM_EXECUTE, buff, sizeof(buff),
-                           packet, length, 1, NULL) ||
-      (*mysql->methods->read_query_result)(mysql))
+
+  res= test(cli_advanced_command(mysql, COM_EXECUTE, buff, sizeof(buff),
+                                 packet, length, 1, NULL) ||
+            (*mysql->methods->read_query_result)(mysql));
+  stmt->affected_rows= mysql->affected_rows;
+  stmt->insert_id= mysql->insert_id;
+  if (res)
   {
     set_stmt_errmsg(stmt, net->last_error, net->last_errno, net->sqlstate);
     DBUG_RETURN(1);
   }
-  stmt->affected_rows= mysql->affected_rows;
-  stmt->insert_id= mysql->insert_id;
   DBUG_RETURN(0);
 }
 

--- 1.128/libmysqld/lib_sql.cc	2006-11-17 12:21:37 +03:00
+++ 1.129/libmysqld/lib_sql.cc	2006-11-17 12:21:37 +03:00
@@ -224,20 +224,24 @@ static int emb_stmt_execute(MYSQL_STMT *
 {
   DBUG_ENTER("emb_stmt_execute");
   char header[4];
+  my_bool res;
+
   int4store(header, stmt->stmt_id);
   THD *thd= (THD*)stmt->mysql->thd;
   thd->client_param_count= stmt->param_count;
   thd->client_params= stmt->params;
-  if (emb_advanced_command(stmt->mysql, COM_EXECUTE,0,0,
-                           header, sizeof(header), 1, stmt) ||
-      emb_mysql_read_query_result(stmt->mysql))
+
+  res= test(emb_advanced_command(stmt->mysql, COM_EXECUTE,0,0,
+                                 header, sizeof(header), 1, stmt) ||
+            emb_mysql_read_query_result(stmt->mysql));
+  stmt->affected_rows= stmt->mysql->affected_rows;
+  stmt->insert_id= stmt->mysql->insert_id;
+  if (res)
   {
     NET *net= &stmt->mysql->net;
     set_stmt_errmsg(stmt, net->last_error, net->last_errno, net->sqlstate);
     DBUG_RETURN(1);
   }
-  stmt->affected_rows= stmt->mysql->affected_rows;
-  stmt->insert_id= stmt->mysql->insert_id;
   DBUG_RETURN(0);
 }
 

--- 1.172/tests/mysql_client_test.c	2006-11-17 12:21:37 +03:00
+++ 1.173/tests/mysql_client_test.c	2006-11-17 12:21:37 +03:00
@@ -11950,6 +11950,83 @@ static void test_bug21726()
 
 
 /*
+  BUG#23383: mysql_affected_rows() returns different values than
+  mysql_stmt_affected_rows()
+
+  Test that both mysql_affected_rows() and mysql_stmt_affected_rows()
+  return -1 on error, 0 when no rows were affected, and (positive) row
+  count when some rows were affected.
+*/
+static void test_bug23383()
+{
+  const char *insert_query= "INSERT INTO t1 VALUES (1), (2)";
+  const char *update_query= "UPDATE t1 SET i= 4 WHERE i = 3";
+  MYSQL_STMT *stmt;
+  my_ulonglong row_count;
+  int rc;
+
+  DBUG_ENTER("test_bug23383");
+  myheader("test_bug23383");
+
+  rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
+  myquery(rc);
+
+  rc= mysql_query(mysql, "CREATE TABLE t1 (i INT UNIQUE)");
+  myquery(rc);
+
+  rc= mysql_query(mysql, insert_query);
+  myquery(rc);
+  row_count= mysql_affected_rows(mysql);
+  DIE_UNLESS(row_count == 2);
+
+  rc= mysql_query(mysql, insert_query);
+  DIE_UNLESS(rc != 0);
+  row_count= mysql_affected_rows(mysql);
+  DIE_UNLESS(row_count == (my_ulonglong)-1);
+
+  rc= mysql_query(mysql, update_query);
+  myquery(rc);
+  row_count= mysql_affected_rows(mysql);
+  DIE_UNLESS(row_count == 0);
+
+  rc= mysql_query(mysql, "DELETE FROM t1");
+  myquery(rc);
+
+  stmt= mysql_stmt_init(mysql);
+  DIE_UNLESS(stmt != 0);
+
+  rc= mysql_stmt_prepare(stmt, insert_query, strlen(insert_query));
+  check_execute(stmt, rc);
+
+  rc= mysql_stmt_execute(stmt);
+  check_execute(stmt, rc);
+  row_count= mysql_stmt_affected_rows(stmt);
+  DIE_UNLESS(row_count == 2);
+
+  rc= mysql_stmt_execute(stmt);
+  DIE_UNLESS(rc != 0);
+  row_count= mysql_stmt_affected_rows(stmt);
+  DIE_UNLESS(row_count == (my_ulonglong)-1);
+
+  rc= mysql_stmt_prepare(stmt, update_query, strlen(update_query));
+  check_execute(stmt, rc);
+
+  rc= mysql_stmt_execute(stmt);
+  check_execute(stmt, rc);
+  row_count= mysql_stmt_affected_rows(stmt);
+  DIE_UNLESS(row_count == 0);
+
+  rc= mysql_stmt_close(stmt);
+  check_execute(stmt, rc);
+
+  rc= mysql_query(mysql, "DROP TABLE t1");
+  myquery(rc);
+
+  DBUG_VOID_RETURN;
+}
+
+
+/*
   Read and parse arguments and MySQL options from my.cnf
 */
 
@@ -12176,6 +12253,7 @@ static struct my_tests_st my_tests[]= {
   { "test_bug15613", test_bug15613 },
   { "test_bug20152", test_bug20152 },
   { "test_bug21726", test_bug21726 },
+  { "test_bug23383", test_bug23383 },
   { 0, 0 }
 };
 
Thread
bk commit into 4.1 tree (kroki:1.2551) BUG#23383kroki17 Nov