List:Commits« Previous MessageNext Message »
From:msvensson Date:January 26 2006 10:21am
Subject:bk commit into 5.0 tree (msvensson:1.2019) BUG#15719
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of msvensson. When msvensson 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.2019 06/01/26 11:20:59 msvensson@neptunus.(none) +2 -0
  Bug #15719  MYSQL_OPT_RECONNECT option is modified by mysql_real_connect
   - Move init of "reconnect" variable to mysql_init 
   - Add test case to mysql_client_test.

  tests/mysql_client_test.c
    1.168 06/01/26 11:20:53 msvensson@neptunus.(none) +78 -2
    Add test to check that reconnect is not modified by a call to mysql_real_connect

  sql-common/client.c
    1.82 06/01/26 11:20:53 msvensson@neptunus.(none) +18 -17
    Move initialisation of reconnect variable to mysql_init instead of doing it in mysql_real_connect.

# 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:	msvensson
# Host:	neptunus.(none)
# Root:	/home/msvensson/mysql/bug15719/my50-bug15719

--- 1.81/sql-common/client.c	2005-12-07 00:49:58 +01:00
+++ 1.82/sql-common/client.c	2006-01-26 11:20:53 +01:00
@@ -1456,6 +1456,24 @@
 
   mysql->options.methods_to_use= MYSQL_OPT_GUESS_CONNECTION;
   mysql->options.report_data_truncation= TRUE;  /* default */
+
+  /*
+    By default we don't reconnect because it could silently corrupt data (after
+    reconnection you potentially lose table locks, user variables, session
+    variables (transactions but they are specifically dealt with in
+    mysql_reconnect()).
+    This is a change: < 5.0.3 mysql->reconnect was set to 1 by default.
+    How this change impacts existing apps:
+    - existing apps which relyed on the default will see a behaviour change;
+    they will have to set reconnect=1 after mysql_real_connect().
+    - existing apps which explicitely asked for reconnection (the only way they
+    could do it was by setting mysql.reconnect to 1 after mysql_real_connect())
+    will not see a behaviour change.
+    - existing apps which explicitely asked for no reconnection
+    (mysql.reconnect=0) will not see a behaviour change.
+  */
+  mysql->reconnect= 0;
+
   return mysql;
 }
 
@@ -1624,23 +1642,6 @@
     port=mysql->options.port;
   if (!unix_socket)
     unix_socket=mysql->options.unix_socket;
-  
-  /*
-    By default we don't reconnect because it could silently corrupt data (after
-    reconnection you potentially lose table locks, user variables, session
-    variables (transactions but they are specifically dealt with in
-    mysql_reconnect()).
-    This is a change: < 5.0.3 mysql->reconnect was set to 1 by default.
-    How this change impacts existing apps:
-    - existing apps which relyed on the default will see a behaviour change;
-    they will have to set reconnect=1 after mysql_real_connect().
-    - existing apps which explicitely asked for reconnection (the only way they
-    could do it was by setting mysql.reconnect to 1 after mysql_real_connect())
-    will not see a behaviour change.
-    - existing apps which explicitely asked for no reconnection
-    (mysql.reconnect=0) will not see a behaviour change.
-  */
-  mysql->reconnect= 0;
 
   mysql->server_status=SERVER_STATUS_AUTOCOMMIT;
 

--- 1.167/tests/mysql_client_test.c	2005-12-08 07:55:54 +01:00
+++ 1.168/tests/mysql_client_test.c	2006-01-26 11:20:53 +01:00
@@ -14598,7 +14598,6 @@
 static void test_bug15510()
 {
   MYSQL_STMT *stmt;
-  MYSQL_RES *res;
   int rc;
   const char *query= "select 1 from dual where 1/0";
 
@@ -14624,6 +14623,81 @@
   myquery(rc);
 }
 
+
+/* Test MYSQL_OPT_RECONNECT, Bug#15719 */
+
+static void test_opt_reconnect()
+{
+  MYSQL *lmysql;
+  my_bool my_true= TRUE;
+
+  myheader("test_opt_reconnect");
+
+  if (!(lmysql= mysql_init(NULL)))
+  {
+    myerror("mysql_init() failed");
+    exit(1);
+  }
+
+  if (!opt_silent)
+    fprintf(stdout, "reconnect before mysql_options: %d\n", lmysql->reconnect);
+  DIE_UNLESS(lmysql->reconnect == 0);
+
+  if (mysql_options(lmysql, MYSQL_OPT_RECONNECT, &my_true))
+  {
+    myerror("mysql_options failed: unknown option MYSQL_OPT_RECONNECT\n");
+    exit(1);
+  }
+
+  /* reconnect should be 1 */
+  if (!opt_silent)
+    fprintf(stdout, "reconnect after mysql_options: %d\n", lmysql->reconnect);
+  DIE_UNLESS(lmysql->reconnect == 1);
+
+  if (!(mysql_real_connect(lmysql, opt_host, opt_user,
+                           opt_password, current_db, opt_port,
+                           opt_unix_socket, 0)))
+  {
+    myerror("connection failed");
+    exit(1);
+  }
+
+  /* reconnect should still be 1 */
+  if (!opt_silent)
+    fprintf(stdout, "reconnect after mysql_real_connect: %d\n",
+	    lmysql->reconnect);
+  DIE_UNLESS(lmysql->reconnect == 1);
+
+  mysql_close(lmysql);
+
+  if (!(lmysql= mysql_init(NULL)))
+  {
+    myerror("mysql_init() failed");
+    exit(1);
+  }
+
+  if (!opt_silent)
+    fprintf(stdout, "reconnect before mysql_real_connect: %d\n", lmysql->reconnect);
+  DIE_UNLESS(lmysql->reconnect == 0);
+
+  if (!(mysql_real_connect(lmysql, opt_host, opt_user,
+                           opt_password, current_db, opt_port,
+                           opt_unix_socket, 0)))
+  {
+    myerror("connection failed");
+    exit(1);
+  }
+
+  /* reconnect should still be 0 */
+  if (!opt_silent)
+    fprintf(stdout, "reconnect after mysql_real_connect: %d\n",
+	    lmysql->reconnect);
+  DIE_UNLESS(lmysql->reconnect == 0);
+
+  mysql_close(lmysql);
+}
+
+
 /*
   Read and parse arguments and MySQL options from my.cnf
 */
@@ -14883,7 +14957,9 @@
   { "test_bug13488", test_bug13488 },
   { "test_bug13524", test_bug13524 },
   { "test_bug14845", test_bug14845 },
-  { "test_bug15510", test_bug15510},
+  { "test_bug15510", test_bug15510 },
+  { "test_opt_reconnect", test_opt_reconnect },
+
   { 0, 0 }
 };
 
Thread
bk commit into 5.0 tree (msvensson:1.2019) BUG#15719msvensson26 Jan