summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Winstead <jimw@mysql.com>2009-05-18 12:52:51 -0700
committerJim Winstead <jimw@mysql.com>2009-05-18 12:52:51 -0700
commit64678b3d44fc1d133b2e7a557752b792402337c8 (patch)
treedfa5c820c3bad66d57bf8e8d0d571c2e9ac1700f
parent9e1bd1c22e34be2a21d3df16010921112fced523 (diff)
downloadmariadb-git-64678b3d44fc1d133b2e7a557752b792402337c8.tar.gz
The output of mysqldump --tab for views included a DROP TABLE statement
without the IF EXISTS qualifier even though no temporary table is created as for all-in-one dumps including views. (Bug #37377)
-rw-r--r--client/mysqldump.c3
-rw-r--r--mysql-test/r/mysqldump.result39
-rw-r--r--mysql-test/t/mysqldump.test23
3 files changed, 49 insertions, 16 deletions
diff --git a/client/mysqldump.c b/client/mysqldump.c
index efcb1820be4..87b78cb41e1 100644
--- a/client/mysqldump.c
+++ b/client/mysqldump.c
@@ -4802,7 +4802,8 @@ static my_bool get_view_structure(char *table, char* db)
result_table);
check_io(sql_file);
}
- fprintf(sql_file, "/*!50001 DROP TABLE %s*/;\n", opt_quoted_table);
+ /* Table might not exist if this view was dumped with --tab. */
+ fprintf(sql_file, "/*!50001 DROP TABLE IF EXISTS %s*/;\n", opt_quoted_table);
if (opt_drop)
{
fprintf(sql_file, "/*!50001 DROP VIEW IF EXISTS %s*/;\n",
diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result
index 7e987df8166..b48b6c9d87f 100644
--- a/mysql-test/r/mysqldump.result
+++ b/mysql-test/r/mysqldump.result
@@ -1991,7 +1991,7 @@ SET character_set_client = utf8;
`a` varchar(30)
) ENGINE=MyISAM */;
SET character_set_client = @saved_cs_client;
-/*!50001 DROP TABLE `v2`*/;
+/*!50001 DROP TABLE IF EXISTS `v2`*/;
/*!50001 DROP VIEW IF EXISTS `v2`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
@@ -2085,7 +2085,7 @@ SET character_set_client = utf8;
`a` int(11)
) ENGINE=MyISAM */;
SET character_set_client = @saved_cs_client;
-/*!50001 DROP TABLE `v1`*/;
+/*!50001 DROP TABLE IF EXISTS `v1`*/;
/*!50001 DROP VIEW IF EXISTS `v1`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
@@ -2159,7 +2159,7 @@ SET character_set_client = utf8;
`a` varchar(30)
) ENGINE=MyISAM */;
SET character_set_client = @saved_cs_client;
-/*!50001 DROP TABLE `v2`*/;
+/*!50001 DROP TABLE IF EXISTS `v2`*/;
/*!50001 DROP VIEW IF EXISTS `v2`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
@@ -2293,7 +2293,7 @@ SET character_set_client = utf8;
`c` varchar(30)
) ENGINE=MyISAM */;
SET character_set_client = @saved_cs_client;
-/*!50001 DROP TABLE `v1`*/;
+/*!50001 DROP TABLE IF EXISTS `v1`*/;
/*!50001 DROP VIEW IF EXISTS `v1`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
@@ -2307,7 +2307,7 @@ SET character_set_client = @saved_cs_client;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
-/*!50001 DROP TABLE `v2`*/;
+/*!50001 DROP TABLE IF EXISTS `v2`*/;
/*!50001 DROP VIEW IF EXISTS `v2`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
@@ -2321,7 +2321,7 @@ SET character_set_client = @saved_cs_client;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
-/*!50001 DROP TABLE `v3`*/;
+/*!50001 DROP TABLE IF EXISTS `v3`*/;
/*!50001 DROP VIEW IF EXISTS `v3`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
@@ -3054,7 +3054,7 @@ SET character_set_client = utf8;
SET character_set_client = @saved_cs_client;
USE `test`;
-/*!50001 DROP TABLE `v0`*/;
+/*!50001 DROP TABLE IF EXISTS `v0`*/;
/*!50001 DROP VIEW IF EXISTS `v0`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
@@ -3068,7 +3068,7 @@ USE `test`;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
-/*!50001 DROP TABLE `v1`*/;
+/*!50001 DROP TABLE IF EXISTS `v1`*/;
/*!50001 DROP VIEW IF EXISTS `v1`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
@@ -3082,7 +3082,7 @@ USE `test`;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
-/*!50001 DROP TABLE `v2`*/;
+/*!50001 DROP TABLE IF EXISTS `v2`*/;
/*!50001 DROP VIEW IF EXISTS `v2`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
@@ -3320,7 +3320,7 @@ insert into t values(5, 51);
create view v1 as select qty, price, qty*price as value from t;
create view v2 as select qty from v1;
mysqldump {
-/*!50001 DROP TABLE `v1`*/;
+/*!50001 DROP TABLE IF EXISTS `v1`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
@@ -3335,7 +3335,7 @@ mysqldump {
/*!50001 SET collation_connection = @saved_col_connection */;
} mysqldump {
-/*!50001 DROP TABLE `v2`*/;
+/*!50001 DROP TABLE IF EXISTS `v2`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
@@ -3434,7 +3434,7 @@ SET character_set_client = utf8;
SET character_set_client = @saved_cs_client;
USE `mysqldump_test_db`;
-/*!50001 DROP TABLE `v1`*/;
+/*!50001 DROP TABLE IF EXISTS `v1`*/;
/*!50001 DROP VIEW IF EXISTS `v1`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
@@ -3496,7 +3496,7 @@ SET character_set_client = @saved_cs_client;
USE `mysqldump_tables`;
USE `mysqldump_views`;
-/*!50001 DROP TABLE `nasishnasifu`*/;
+/*!50001 DROP TABLE IF EXISTS `nasishnasifu`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
@@ -3885,7 +3885,7 @@ SET character_set_client = utf8;
`c` int(11)
) ENGINE=MyISAM */;
SET character_set_client = @saved_cs_client;
-/*!50001 DROP TABLE `v2`*/;
+/*!50001 DROP TABLE IF EXISTS `v2`*/;
/*!50001 DROP VIEW IF EXISTS `v2`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
@@ -4304,7 +4304,7 @@ SET character_set_client = utf8;
SET character_set_client = @saved_cs_client;
USE `mysqldump_test_db`;
-/*!50001 DROP TABLE `v1`*/;
+/*!50001 DROP TABLE IF EXISTS `v1`*/;
/*!50001 DROP VIEW IF EXISTS `v1`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
@@ -4430,6 +4430,15 @@ DROP DATABASE mysqldump_test_db;
# -- End of test case for Bug#32538.
+#
+# Bug#37377 Incorrect DROP TABLE statement in dump of a VIEW using --tab
+#
+create table t1 (a int);
+create view v1 as select a from t1;
+drop view v1;
+drop table t1;
+drop view v1;
+drop table t1;
SET @@GLOBAL.CONCURRENT_INSERT = @OLD_CONCURRENT_INSERT;
#
# End of 5.1 tests
diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test
index 64d1036e264..6fc8d7bdfea 100644
--- a/mysql-test/t/mysqldump.test
+++ b/mysql-test/t/mysqldump.test
@@ -1948,6 +1948,29 @@ DROP DATABASE mysqldump_test_db;
--echo # -- End of test case for Bug#32538.
--echo
+--echo #
+--echo # Bug#37377 Incorrect DROP TABLE statement in dump of a VIEW using --tab
+--echo #
+
+create table t1 (a int);
+create view v1 as select a from t1;
+
+--exec $MYSQL_DUMP --skip-comments --tab=$MYSQLTEST_VARDIR/tmp/ test t1 v1
+
+drop view v1;
+drop table t1;
+
+--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/t1.sql
+--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/v1.sql
+
+drop view v1;
+drop table t1;
+
+--remove_file $MYSQLTEST_VARDIR/tmp/t1.sql
+--remove_file $MYSQLTEST_VARDIR/tmp/t1.txt
+--remove_file $MYSQLTEST_VARDIR/tmp/v1.sql
+
+
# We reset concurrent_inserts value to whatever it was at the start of the test
# This line must be executed _after_ all test cases.
SET @@GLOBAL.CONCURRENT_INSERT = @OLD_CONCURRENT_INSERT;