List:Commits« Previous MessageNext Message »
From:Nirbhay Choubey Date:October 11 2010 6:31am
Subject:bzr commit into mysql-5.1-bugteam branch (nirbhay.choubey:3523)
View as plain text  
#At file:///home/nirbhay/Project/mysql/repo/wl/mysql-5.1-bugteam-54899/ based on revid:georgi.kodinov@stripped

 3523 Nirbhay Choubey	2010-10-11
      Bug#54899 : --one-database option cannot handle DROP/CREATE DATABASE commands
      After dropping and recreating the database specified along with --one-database
      option at command line, mysql client keeps filtering the statements even after
      the execution of a 'USE' command on the same database.
      --one-database option enables the filtering of statements when the current
      database is not the one specified at the command line. However, when the same
      database is dropped and recreated the variable (current_db) that holds the
      inital database name gets altered. This bug exploits the fact that current_db
      initially gets set to null value (0) when a 'use db_name' follows the recreation
      of same database db_name (speficied at the command line) and hence skip_updates
      gets set to 1, which inturn triggers the further filtering of statements.
      Fixed by introducing a new variable 'opt_db', which persistently stores the
      database name specified at mysql client's command line and fixing the if
      statement that governed the filtering flag by adding a check on whether the
      database name in the USE command is similar to one specified at command line.
     @ client/
        Bug#54899 : --one-database option cannot handle DROP/CREATE DATABASE commands
        During mysql client start-up, 'opt_db' gets initialized in get_options function
        with the database name specified at the command line.
        Now, when a 'USE' command is run after the recreation of database ( i.e. drop
        followed by create database), the function com_use is called which in-turn calls
        get_current_db(), which sets current_db. Now as the current database was dropped
        and recreated, get_current_db() sets current_db to a null value (0), and hence
        skip_updates gets set to 1 for --one_database.
        The bug was resolved by checking if the database name used in the 'USE'
        command is same database that was entered at the command line.
     @ mysql-test/r/mysql.result
        Added test case for bug#54899.
     @ mysql-test/t/mysql.test
        Added test case for bug#54899.

=== modified file 'client/'
--- a/client/	2010-07-20 18:07:36 +0000
+++ b/client/	2010-10-11 06:31:31 +0000
@@ -160,7 +160,7 @@ static uint verbose=0,opt_silent=0,opt_m
 static uint my_end_arg;
 static char * opt_mysql_unix_port=0;
 static int connect_flag=CLIENT_INTERACTIVE;
-static char *current_host,*current_db,*current_user=0,*opt_password=0,
+static char *current_host,*current_db,*opt_db,*current_user=0,*opt_password=0,
             *current_prompt=0, *delimiter_str= 0,
             *default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME;
 static char *histfile;
@@ -1258,6 +1258,7 @@ sig_handler mysql_end(int sig)
+  my_free(opt_db, MYF(MY_ALLOW_ZERO_PTR));
@@ -1841,7 +1842,13 @@ static int get_options(int argc, char **
     skip_updates= 0;
     my_free(current_db, MYF(MY_ALLOW_ZERO_PTR));
-    current_db= my_strdup(*argv, MYF(MY_WME));
+    my_free(opt_db, MYF(MY_ALLOW_ZERO_PTR));
+    /*
+      Store initial database name specified at
+      command line in opt_db.
+    */
+    opt_db= my_strdup(*argv, MYF(MY_WME));
+    current_db= my_strdup(opt_db, MYF(MY_WME));
   if (tty_password)
     opt_password= get_tty_password(NullS);
@@ -4108,7 +4115,12 @@ com_use(String *buffer __attribute__((un
   if (!current_db || cmp_database(charset_info, current_db,tmp))
-    if (one_database)
+    /*
+      Skip the following if statement in case opt_db (i.e. database
+      specified at command line) is similar to the database name
+      provided in the 'USE' command.
+    */
+    if (one_database && cmp_database(charset_info, opt_db, tmp))
       skip_updates= 1;
       select_db= 0;    // don't do mysql_select_db()

=== modified file 'mysql-test/r/mysql.result'
--- a/mysql-test/r/mysql.result	2009-12-17 20:06:36 +0000
+++ b/mysql-test/r/mysql.result	2010-10-11 06:31:31 +0000
@@ -235,4 +235,13 @@ Bug #47147: mysql client option --skip-c
 *************************** 1. row ***************************
+Bug #54899: --one-database option cannot handle DROP/CREATE DATABASE commands
+CREATE DATABASE connected_db;
+USE connected_db;
+DROP DATABASE connected_db;
 End of tests

=== modified file 'mysql-test/t/mysql.test'
--- a/mysql-test/t/mysql.test	2009-12-17 20:06:36 +0000
+++ b/mysql-test/t/mysql.test	2010-10-11 06:31:31 +0000
@@ -413,4 +413,21 @@ drop table t1;
 --exec $MYSQL --skip-column-names --vertical test -e "select 1 as a"
+--echo Bug #54899: --one-database option cannot handle DROP/CREATE DATABASE commands
+--write_file $MYSQLTEST_VARDIR/tmp/bug54899.sql
+DROP DATABASE connected_db;
+CREATE DATABASE connected_db;
+USE connected_db;
+CREATE DATABASE connected_db;
+--exec $MYSQL --one-database connected_db < $MYSQLTEST_VARDIR/tmp/bug54899.sql
+USE connected_db;
+DROP DATABASE connected_db;
+--remove_file $MYSQLTEST_VARDIR/tmp/bug54899.sql
 --echo End of tests

Attachment: [text/bzr-bundle]
bzr commit into mysql-5.1-bugteam branch (nirbhay.choubey:3523)Bug#54899Nirbhay Choubey11 Oct
  • Re: bzr commit into mysql-5.1-bugteam branch(nirbhay.choubey:3523) Bug#54899Sergey Vojtovich12 Oct