List:Commits« Previous MessageNext Message »
From:msvensson Date:December 20 2005 4:06pm
Subject:bk commit into 5.0 tree (msvensson:1.1976)
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.1976 05/12/20 17:06:20 msvensson@neptunus.(none) +1 -0
  Avoid implicit commits by using a different connection when creating/dropping sp's and views.

  client/mysqltest.c
    1.189 05/12/20 17:06:12 msvensson@neptunus.(none) +57 -17
    Use a different mysql connection when creating/dropping views and sp's.

# 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/wl2930/my50-wl2930-integration

--- 1.188/client/mysqltest.c	2005-12-20 15:34:40 +01:00
+++ 1.189/client/mysqltest.c	2005-12-20 17:06:12 +01:00
@@ -247,6 +247,8 @@
 struct connection
 {
   MYSQL mysql;
+  /* Used when creating views and sp, to avoid implicit commit */
+  MYSQL* util_mysql;
   char *name;
   MYSQL_STMT* stmt;
 };
@@ -551,6 +553,8 @@
       mysql_stmt_close(next_con->stmt);
     next_con->stmt= 0;
     mysql_close(&next_con->mysql);
+    if (next_con->util_mysql)
+      mysql_close(next_con->util_mysql);
     my_free(next_con->name, MYF(MY_ALLOW_ZERO_PTR));
   }
   DBUG_VOID_RETURN;
@@ -1948,6 +1952,9 @@
       }
 #endif
       mysql_close(&con->mysql);
+      if (con->util_mysql)
+	mysql_close(con->util_mysql);
+      con->util_mysql= 0;
       my_free(con->name, MYF(0));
       /*
          When the connection is closed set name to "closed_connection"
@@ -2040,16 +2047,15 @@
     0 - success, non-0 - failure
 */
 
-int safe_connect(MYSQL* con, const char *host, const char *user,
-		 const char *pass,
-		 const char *db, int port, const char *sock)
+int safe_connect(MYSQL* mysql, const char *host, const char *user,
+		 const char *pass, const char *db, int port, const char *sock)
 {
   int con_error= 1;
   my_bool reconnect= 1;
   int i;
   for (i= 0; i < MAX_CON_TRIES; ++i)
   {
-    if (mysql_real_connect(con, host,user, pass, db, port, sock,
+    if (mysql_real_connect(mysql, host,user, pass, db, port, sock,
 			   CLIENT_MULTI_STATEMENTS | CLIENT_REMEMBER_OPTIONS))
     {
       con_error= 0;
@@ -2061,7 +2067,7 @@
    TODO: change this to 0 in future versions, but the 'kill' test relies on
    existing behavior
   */
-  mysql_options(con, MYSQL_OPT_RECONNECT, (char *)&reconnect);
+  mysql_options(mysql, MYSQL_OPT_RECONNECT, (char *)&reconnect);
   return con_error;
 }
 
@@ -2305,10 +2311,10 @@
     con_db= 0;
   if (q->abort_on_error)
   {
-    if ((safe_connect(&next_con->mysql, con_host, con_user, con_pass,
-		      con_db, con_port, con_sock ? con_sock: 0)))
-      die("Could not open connection '%s': %s", con_name,
-          mysql_error(&next_con->mysql));
+    if (safe_connect(&next_con->mysql, con_host, con_user, con_pass,
+		     con_db, con_port, con_sock ? con_sock: 0))
+      die("Could not open connection '%s': %d %s", con_name,
+          mysql_errno(&next_con->mysql), mysql_error(&next_con->mysql));
   }
   else
     error= connect_n_handle_errors(q, &next_con->mysql, con_host, con_user,
@@ -3785,6 +3791,39 @@
 }
 
 
+
+/*
+  Create a util connection if one does not already exists
+  and use that to run the query
+  This is done to avoid implict commit when creating/dropping objects such
+  as view, sp etc.
+*/
+
+static int util_query(MYSQL* org_mysql, const char* query){
+
+  MYSQL* mysql;
+  DBUG_ENTER("util_query");
+
+  if(!(mysql= cur_con->util_mysql))
+  {
+    DBUG_PRINT("info", ("Creating util_mysql"));
+    if (!(mysql= mysql_init(mysql)))
+      die("Failed in mysql_init()");
+
+    if (safe_connect(mysql, org_mysql->host, org_mysql->user,
+		     org_mysql->passwd, org_mysql->db, org_mysql->port,
+		     org_mysql->unix_socket))
+      die("Could not open util connection: %d %s",
+	  mysql_errno(mysql), mysql_error(mysql));
+
+    cur_con->util_mysql= mysql;
+  }
+
+  return mysql_query(mysql, query);
+}
+
+
+
 /*
   Run query
 
@@ -3865,7 +3904,7 @@
 			"CREATE OR REPLACE VIEW mysqltest_tmp_v AS ",
 			query_len+64, 256);
     dynstr_append_mem(&query_str, query, query_len);
-    if (mysql_query(mysql, query_str.str))
+    if (util_query(mysql, query_str.str))
     {
       /*
 	Failed to create the view, this is not fatal
@@ -3892,7 +3931,7 @@
 	 Collect warnings from create of the view that should otherwise
          have been produced when the SELECT was executed
       */
-      append_warnings(&ds_warnings, mysql);
+      append_warnings(&ds_warnings, cur_con->util_mysql);
     }
 
     dynstr_free(&query_str);
@@ -3909,12 +3948,12 @@
     */
     DYNAMIC_STRING query_str;
     init_dynamic_string(&query_str,
-			"DROP PROCEDURE IF EXISTS mysqltest_tmp_sp;\n",
+			"DROP PROCEDURE IF EXISTS mysqltest_tmp_sp;",
 			query_len+64, 256);
-    mysql_query(mysql, query_str.str);
+    util_query(mysql, query_str.str);
     dynstr_set(&query_str, "CREATE PROCEDURE mysqltest_tmp_sp()\n");
     dynstr_append_mem(&query_str, query, query_len);
-    if (mysql_query(mysql, query_str.str))
+    if (util_query(mysql, query_str.str))
     {
       /*
 	Failed to create the stored procedure for this query,
@@ -3958,13 +3997,13 @@
 
   if (sp_created)
   {
-    if (mysql_query(mysql, "DROP PROCEDURE mysqltest_tmp_sp "))
+    if (util_query(mysql, "DROP PROCEDURE mysqltest_tmp_sp "))
       die("Failed to drop sp: %d: %s", mysql_errno(mysql), mysql_error(mysql));
   }
 
   if (view_created)
   {
-    if (mysql_query(mysql, "DROP VIEW mysqltest_tmp_v "))
+    if (util_query(mysql, "DROP VIEW mysqltest_tmp_v "))
       die("Failed to drop view: %d: %s",
 	  mysql_errno(mysql), mysql_error(mysql));
   }
@@ -4299,7 +4338,8 @@
     die("Out of memory");
 
   if (safe_connect(&cur_con->mysql, host, user, pass, db, port, unix_sock))
-    die("Failed in mysql_real_connect(): %s", mysql_error(&cur_con->mysql));
+    die("Could not open connection '%s': %d %s", cur_con->name,
+	mysql_errno(&cur_con->mysql), mysql_error(&cur_con->mysql));
 
   init_var_hash(&cur_con->mysql);
 
Thread
bk commit into 5.0 tree (msvensson:1.1976)msvensson20 Dec