diff --git a/client/mysqldump.c b/client/mysqldump.c index fbd8ae351b2..53cb06be6f3 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -1585,6 +1585,9 @@ static uint get_table_structure(char *table, char *db, char *table_type, } mysql_free_result(result); + if (path) + my_fclose(sql_file, MYF(MY_WME)); + seen_views= 1; DBUG_RETURN(0); } diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index acb9b9af276..f9714e067e6 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -2743,6 +2743,25 @@ end AFTER # root@localhost drop trigger tr1; drop trigger tr2; drop table t1, t2; +create table t (qty int, price int); +insert into t values(3, 50); +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 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v1` AS select `t`.`qty` AS `qty`,`t`.`price` AS `price`,(`t`.`qty` * `t`.`price`) AS `value` from `t` */; + +} mysqldump { +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v2` AS select `v1`.`qty` AS `qty` from `v1` */; + +} mysqldump +drop view v1; +drop view v2; +drop table t; /*!50003 CREATE FUNCTION `f`() RETURNS bigint(20) return 42 */| /*!50003 CREATE PROCEDURE `p`() diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index 4749141f7fe..b6a552adbde 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -1145,6 +1145,27 @@ drop trigger tr2; drop table t1, t2; +# +# Bug#18462 mysqldump does not dump view structures correctly +# +# +create table t (qty int, price int); +insert into t values(3, 50); +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; +--echo mysqldump { +--exec $MYSQL_DUMP --compact -F --tab . test +--exec cat v1.sql +--echo } mysqldump { +--exec cat v2.sql +--echo } mysqldump +--rm v.sql t.sql t.txt +drop view v1; +drop view v2; +drop table t; + + # # Bug#14857 Reading dump files with single statement stored routines fails. # fixed by patch for bug#16878