MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Jim Winstead Date:May 10 2010 3:02am
Subject:bzr commit into mysql-5.1-bugteam branch (jimw:3375) Bug#42373
View as plain text  
#At file:///Users/jimw/my/mysql-5.1-bugteam/ based on revid:alfranio.correia@stripped

 3375 Jim Winstead	2010-05-09
      Using an initial command with mysql_options(..., MYSQL_INIT_COMMAND, ...)
      that generated multiple result sets (such as a stored procedure or a
      multi-statement command) would leave the connection unusable. (Bug #42373)
      
      A side-effect of this bug fix is to make MYSQL_INIT_COMMAND settings ignored
      when connecting from within the server, but none of the existing mechanisms
      for connecting from within the server use or need to set the initial command.

    modified:
      sql-common/client.c
      tests/mysql_client_test.c
=== modified file 'sql-common/client.c'
--- a/sql-common/client.c	2009-11-02 22:19:58 +0000
+++ b/sql-common/client.c	2010-05-10 03:02:05 +0000
@@ -2455,6 +2455,11 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
     goto error;
   }
 
+  /*
+     Using init_commands is not supported when connecting from within the
+     server.
+  */
+#ifndef MYSQL_SERVER
   if (mysql->options.init_commands)
   {
     DYNAMIC_ARRAY *init_commands= mysql->options.init_commands;
@@ -2466,18 +2471,26 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
 
     for (; ptr < end_command; ptr++)
     {
-      MYSQL_RES *res;
+      int status;
+
       if (mysql_real_query(mysql,*ptr, (ulong) strlen(*ptr)))
 	goto error;
-      if (mysql->fields)
-      {
-	if (!(res= cli_use_result(mysql)))
-	  goto error;
-	mysql_free_result(res);
-      }
+
+      do {
+        if (mysql->fields)
+        {
+          MYSQL_RES *res;
+          if (!(res= cli_use_result(mysql)))
+            goto error;
+          mysql_free_result(res);
+        }
+        if ((status= mysql_next_result(mysql)) > 0)
+          goto error;
+      } while (status == 0);
     }
     mysql->reconnect=reconnect;
   }
+#endif
 
 #ifndef TO_BE_DELETED
   if (mysql->options.rpl_probe && mysql_rpl_probe(mysql))

=== modified file 'tests/mysql_client_test.c'
--- a/tests/mysql_client_test.c	2010-05-04 14:03:28 +0000
+++ b/tests/mysql_client_test.c	2010-05-10 03:02:05 +0000
@@ -18093,6 +18093,87 @@ static void test_bug53371()
 }
 
 
+
+/**
+  Bug#42373: libmysql can mess a connection at connect
+*/
+static void test_bug42373()
+{
+  int rc;
+  MYSQL con;
+  MYSQL_STMT *stmt;
+
+  DBUG_ENTER("test_bug42373");
+  myheader("test_42373");
+
+  rc= mysql_query(mysql, "DROP PROCEDURE IF EXISTS p1");
+  myquery(rc);
+
+  rc= mysql_query(mysql, "CREATE PROCEDURE p1()"
+                         "  BEGIN"
+                         "  SELECT 1;"
+                         "  INSERT INTO t1 VALUES (2);"
+                         "END;");
+  myquery(rc);
+
+  rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
+  myquery(rc);
+
+  rc= mysql_query(mysql, "CREATE TABLE t1 (a INT)");
+  myquery(rc);
+
+  /* Try with a stored procedure. */
+  DIE_UNLESS(mysql_client_init(&con));
+
+  mysql_options(&con, MYSQL_INIT_COMMAND, "CALL p1()");
+
+  DIE_UNLESS(mysql_real_connect(&con, opt_host, opt_user, opt_password,
+                                current_db, opt_port, opt_unix_socket,
+                                CLIENT_MULTI_STATEMENTS|CLIENT_MULTI_RESULTS));
+
+  stmt= mysql_simple_prepare(&con, "SELECT a FROM t1");
+  check_stmt(stmt);
+
+  rc= mysql_stmt_execute(stmt);
+  check_execute(stmt, rc);
+
+  rc= my_process_stmt_result(stmt);
+  DIE_UNLESS(rc == 1);
+
+  mysql_stmt_close(stmt);
+
+  /* Now try with a multi-statement. */
+  DIE_UNLESS(mysql_client_init(&con));
+
+  mysql_options(&con, MYSQL_INIT_COMMAND,
+                "SELECT 3; INSERT INTO t1 VALUES (4)");
+
+  DIE_UNLESS(mysql_real_connect(&con, opt_host, opt_user, opt_password,
+                                current_db, opt_port, opt_unix_socket,
+                                CLIENT_MULTI_STATEMENTS|CLIENT_MULTI_RESULTS));
+
+  stmt= mysql_simple_prepare(&con, "SELECT a FROM t1");
+  check_stmt(stmt);
+
+  rc= mysql_stmt_execute(stmt);
+  check_execute(stmt, rc);
+
+  rc= my_process_stmt_result(stmt);
+  DIE_UNLESS(rc == 2);
+
+  mysql_stmt_close(stmt);
+  mysql_close(&con);
+
+  rc= mysql_query(mysql, "DROP TABLE t1");
+  myquery(rc);
+
+  rc= mysql_query(mysql, "DROP PROCEDURE p1");
+  myquery(rc);
+
+  DBUG_VOID_RETURN;
+}
+
+
 /*
   Read and parse arguments and MySQL options from my.cnf
 */
@@ -18416,6 +18497,7 @@ static struct my_tests_st my_tests[]= {
 #endif
   { "test_bug41078", test_bug41078 },
   { "test_bug44495", test_bug44495 },
+  { "test_bug42373", test_bug42373 },
   { 0, 0 }
 };
 


Attachment: [text/bzr-bundle] bzr/jimw@mysql.com-20100510030205-pqc3o0uyjo964cun.bundle
Thread
bzr commit into mysql-5.1-bugteam branch (jimw:3375) Bug#42373Jim Winstead10 May