From e1b773cb53bd82f3947704224bee229264c2d120 Mon Sep 17 00:00:00 2001 From: Nirbhay Choubey Date: Fri, 26 Nov 2010 19:27:59 +0530 Subject: 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 making get_current_db() a no-op function when one_database is set, and hence, under that condition current_db will not get altered. Note, however the value of current_db can change when we execute 'connect' command with a differnet database to reconnect to the server, in which case, the behavior of --one-database will be formulated using this new database. client/mysql.cc: Bug #54899 : --one-database option cannot handle DROP/CREATE DATABASE commands Added an if statement at the beginnning of get_current_db() , which makes it a no-op function if one-database option is specified, and hence current_db remains unchanged. Changed the help message for one-database option to a more appropriate message as specified in mysql documentation. mysql-test/r/mysql.result: Added a test case for bug#54899 and some more test cases to check other one-database option related behaviors. mysql-test/t/mysql.test: Added a test case for bug#54899 and some more test cases to check other one-database option related behaviors. --- mysql-test/t/mysql.test | 144 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) (limited to 'mysql-test/t/mysql.test') diff --git a/mysql-test/t/mysql.test b/mysql-test/t/mysql.test index d32d0996490..5e26e0b7ef5 100644 --- a/mysql-test/t/mysql.test +++ b/mysql-test/t/mysql.test @@ -412,5 +412,149 @@ drop table t1; --echo --exec $MYSQL --skip-column-names --vertical test -e "select 1 as a" +--echo + +--echo # +--echo # Bug #54899: --one-database option cannot handle DROP/CREATE DATABASE +--echo # commands. +--echo # +--write_file $MYSQLTEST_VARDIR/tmp/bug54899.sql +DROP DATABASE connected_db; +CREATE DATABASE connected_db; +USE connected_db; +CREATE TABLE `table_in_connected_db`(a INT); +EOF + +CREATE DATABASE connected_db; +--exec $MYSQL --one-database connected_db < $MYSQLTEST_VARDIR/tmp/bug54899.sql +USE connected_db; +SHOW TABLES; +DROP DATABASE connected_db; +--remove_file $MYSQLTEST_VARDIR/tmp/bug54899.sql + +--echo + +--echo # +--echo # Testing --one-database option +--echo # +--write_file $MYSQLTEST_VARDIR/tmp/one_db.sql +CREATE TABLE t1 (i INT); +CREATE TABLE test.t1 (i INT); +USE test; +# Following statements should be filtered. +CREATE TABLE connected_db.t2 (i INT); +CREATE TABLE t2 (i INT); +EOF + +CREATE DATABASE connected_db; +--exec $MYSQL --one-database connected_db < $MYSQLTEST_VARDIR/tmp/one_db.sql +SHOW TABLES IN connected_db; +SHOW TABLES IN test; +USE test; +DROP TABLE t1; +DROP DATABASE connected_db; +--remove_file $MYSQLTEST_VARDIR/tmp/one_db.sql + +--echo +--write_file $MYSQLTEST_VARDIR/tmp/one_db.sql +CREATE DATABASE test1; +USE test1; +USE test1; +# Following statements should be filtered. +CREATE TABLE connected_db.t1 (i INT); +EOF + +--exec $MYSQL --one-database test < $MYSQLTEST_VARDIR/tmp/one_db.sql +SHOW TABLES IN test; +SHOW TABLES IN test1; +DROP DATABASE test1; +--remove_file $MYSQLTEST_VARDIR/tmp/one_db.sql + +--echo + +--echo # +--echo # Checking --one-database option followed by the execution of +--echo # connect command. +--echo # +--write_file $MYSQLTEST_VARDIR/tmp/one_db.sql +CREATE TABLE t1 (i INT); +CREATE TABLE test.t1 (i INT); +CONNECT test; +CREATE TABLE connected_db.t2 (i INT); +CREATE TABLE t2 (i INT); +USE connected_db; +# Following statements should be filtered. +CREATE TABLE connected_db.t3 (i INT); +CREATE TABLE t3 (i INT); +EOF + +CREATE DATABASE connected_db; +--exec $MYSQL --one-database connected_db < $MYSQLTEST_VARDIR/tmp/one_db.sql +SHOW TABLES IN connected_db; +SHOW TABLES IN test; +DROP TABLE test.t1; +DROP TABLE test.t2; +DROP DATABASE connected_db; +--remove_file $MYSQLTEST_VARDIR/tmp/one_db.sql + +--echo + +--echo # +--echo # Checking --one-database option with no database specified +--echo # at command-line. +--echo # +--write_file $MYSQLTEST_VARDIR/tmp/one_db.sql +# All following statements should be filtered. +CREATE TABLE t1 (i INT); +CREATE TABLE test.t1 (i INT); +USE test; +CREATE TABLE test.t2 (i INT); +CREATE TABLE t2 (i INT); +EOF + +--exec $MYSQL --one-database < $MYSQLTEST_VARDIR/tmp/one_db.sql +SHOW TABLES IN test; +--remove_file $MYSQLTEST_VARDIR/tmp/one_db.sql + +--echo + +--echo # +--echo # Checking --one-database option with non_existent_db +--echo # specified with USE command +--echo # + +# CASE 1 : When 'test' database exists and passed at commandline. +--write_file $MYSQLTEST_VARDIR/tmp/one_db_1.sql +CREATE TABLE `table_in_test`(i INT); +USE non_existent_db; +# Following statement should be filtered out. +CREATE TABLE `table_in_non_existent_db`(i INT); +EOF + +# CASE 2 : When 'test' database exists but dropped and recreated in load file. +--write_file $MYSQLTEST_VARDIR/tmp/one_db_2.sql +DROP DATABASE test; +CREATE DATABASE test; +USE non_existent_db; +# Following statements should be filtered out. +CREATE TABLE `table_in_non_existent_db`(i INT); +USE test; +# Following statements should not be filtered out. +CREATE TABLE `table_in_test`(i INT); +EOF + +--exec $MYSQL --one-database test < $MYSQLTEST_VARDIR/tmp/one_db_1.sql +SHOW TABLES IN test; +DROP DATABASE test; +--echo +CREATE DATABASE test; +--exec $MYSQL --one-database test < $MYSQLTEST_VARDIR/tmp/one_db_2.sql +SHOW TABLES IN test; +DROP DATABASE test; +CREATE DATABASE test; + +--remove_file $MYSQLTEST_VARDIR/tmp/one_db_1.sql +--remove_file $MYSQLTEST_VARDIR/tmp/one_db_2.sql + --echo --echo End of tests -- cgit v1.2.1 From 2d81ad5be51cb2ec6921e681a6f1020e1cfa8d60 Mon Sep 17 00:00:00 2001 From: Nirbhay Choubey Date: Wed, 1 Dec 2010 12:25:31 +0530 Subject: Additional fix for bug#54899 Fixing the testcase to use the database name as connected_db instead of 'test' database. mysql-test/r/mysql.result: Additional fix in the test for bug#54899. mysql-test/t/mysql.test: Additional fix in the test for bug#54899. --- mysql-test/t/mysql.test | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'mysql-test/t/mysql.test') diff --git a/mysql-test/t/mysql.test b/mysql-test/t/mysql.test index 5e26e0b7ef5..2dcc77a16c2 100644 --- a/mysql-test/t/mysql.test +++ b/mysql-test/t/mysql.test @@ -523,35 +523,34 @@ SHOW TABLES IN test; --echo # specified with USE command --echo # -# CASE 1 : When 'test' database exists and passed at commandline. +# CASE 1 : When 'connected_db' database exists and passed at commandline. --write_file $MYSQLTEST_VARDIR/tmp/one_db_1.sql -CREATE TABLE `table_in_test`(i INT); +CREATE TABLE `table_in_connected_db`(i INT); USE non_existent_db; # Following statement should be filtered out. CREATE TABLE `table_in_non_existent_db`(i INT); EOF -# CASE 2 : When 'test' database exists but dropped and recreated in load file. +# CASE 2 : When 'connected_db' database exists but dropped and recreated in +# load file. --write_file $MYSQLTEST_VARDIR/tmp/one_db_2.sql -DROP DATABASE test; -CREATE DATABASE test; +DROP DATABASE connected_db; +CREATE DATABASE connected_db; USE non_existent_db; # Following statements should be filtered out. CREATE TABLE `table_in_non_existent_db`(i INT); -USE test; +USE connected_db; # Following statements should not be filtered out. -CREATE TABLE `table_in_test`(i INT); +CREATE TABLE `table_in_connected_db`(i INT); EOF ---exec $MYSQL --one-database test < $MYSQLTEST_VARDIR/tmp/one_db_1.sql -SHOW TABLES IN test; -DROP DATABASE test; +CREATE DATABASE connected_db; +--exec $MYSQL --one-database connected_db < $MYSQLTEST_VARDIR/tmp/one_db_1.sql +SHOW TABLES IN connected_db; --echo -CREATE DATABASE test; ---exec $MYSQL --one-database test < $MYSQLTEST_VARDIR/tmp/one_db_2.sql -SHOW TABLES IN test; -DROP DATABASE test; -CREATE DATABASE test; +--exec $MYSQL --one-database connected_db < $MYSQLTEST_VARDIR/tmp/one_db_2.sql +SHOW TABLES IN connected_db; +DROP DATABASE connected_db; --remove_file $MYSQLTEST_VARDIR/tmp/one_db_1.sql --remove_file $MYSQLTEST_VARDIR/tmp/one_db_2.sql -- cgit v1.2.1 From 980868eb4e4db550497ba40674b5b64f2e062cd9 Mon Sep 17 00:00:00 2001 From: Dmitry Shulga Date: Sat, 5 Feb 2011 11:02:00 +0600 Subject: Fixed bug#57450 - mysql client enter in an infinite loop if the standard input is a directory. The problem is that mysql monitor try to read from stdin without checking input source type. The solution is to stop reading data from standard input if a call to read(2) failed. A new test case was added into mysql.test. client/my_readline.h: Data members error and truncated was added to LINE_BUFFER structure. These data members used instead of out parameters in functions batch_readline, intern_read_line. client/mysql.cc: read_and_execute() was modified: set status.exit_status to 1 when the error occured while reading the next command line in non-interactive mode. Also the value of the truncated attribute of structure LINE_BUFF is taken into account only for non-iteractive mode. client/readline.cc: intern_read_line() was modified: cancel reading from input if fill_buffer() returns -1, e.g. if call to read failed. batch_readline was modified: set the error data member of LINE_BUFFER structure to value of my_errno when system error happened during call to my_read/my_realloc. mysql-test/t/mysql.test: Test for bug#57450 was added. --- mysql-test/t/mysql.test | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'mysql-test/t/mysql.test') diff --git a/mysql-test/t/mysql.test b/mysql-test/t/mysql.test index 2dcc77a16c2..aa774036d10 100644 --- a/mysql-test/t/mysql.test +++ b/mysql-test/t/mysql.test @@ -412,6 +412,12 @@ drop table t1; --echo --exec $MYSQL --skip-column-names --vertical test -e "select 1 as a" +# +# Bug#57450: mysql client enter in an infinite loop if the standard input is a directory +# +--error 1 +--exec $MYSQL < . + --echo --echo # -- cgit v1.2.1