Commit 1d43f71c authored by Rutuja Surve's avatar Rutuja Surve Committed by Vicențiu Ciorbaru

MDEV-15021: mysqldump --tables --routines generates non importable dump file

The order of outputting stored procedures is important. Stored
procedures must be available on view creation, for views which make use
of them. Make sure to print them before outputting tables.
parent 953d70f9
......@@ -4701,6 +4701,12 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
if (opt_xml)
print_xml_tag(md_result_file, "", "\n", "database", "name=", db, NullS);
/* obtain dump of routines (procs/functions) */
if (opt_routines && mysql_get_server_version(mysql) >= 50009)
{
DBUG_PRINT("info", ("Dumping routines for database %s", db));
dump_routines_for_db(db);
}
/* Dump each selected table */
for (pos= dump_tables; pos < end; pos++)
{
......@@ -4729,12 +4735,6 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
DBUG_PRINT("info", ("Dumping events for database %s", db));
dump_events_for_db(db);
}
/* obtain dump of routines (procs/functions) */
if (opt_routines && mysql_get_server_version(mysql) >= 50009)
{
DBUG_PRINT("info", ("Dumping routines for database %s", db));
dump_routines_for_db(db);
}
free_root(&root, MYF(0));
my_free(order_by);
order_by= 0;
......
......@@ -5401,3 +5401,18 @@ DELIMITER ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
ALTER DATABASE `a\"'``b` CHARACTER SET utf8 COLLATE utf8_general_ci ;
DROP DATABASE `a\"'``b`;
#
# MDEV-15021: Fix the order in which routines are called
#
use test;
CREATE FUNCTION f() RETURNS INT RETURN 1;
CREATE VIEW v1 AS SELECT f();
# Running mysqldump -uroot test --routines --tables v1 > **vardir**/test.dmp
DROP VIEW v1;
DROP FUNCTION f;
# Running mysql -uroot test < **vardir**/test.dmp
#
# Cleanup after succesful import.
#
DROP VIEW v1;
DROP FUNCTION f;
......@@ -2567,3 +2567,25 @@ let SEARCH_FILE=$MYSQLTEST_VARDIR/tmp/bug11505.sql;
let SEARCH_PATTERN=Database: mysql;
exec $MYSQL_DUMP mysql func > $SEARCH_FILE;
source include/search_pattern_in_file.inc;
--echo #
--echo # MDEV-15021: Fix the order in which routines are called
--echo #
use test;
CREATE FUNCTION f() RETURNS INT RETURN 1;
CREATE VIEW v1 AS SELECT f();
--echo # Running mysqldump -uroot test --routines --tables v1 > **vardir**/test.dmp
--exec $MYSQL_DUMP -uroot test --routines --tables v1 > $MYSQLTEST_VARDIR/test.dmp
DROP VIEW v1;
DROP FUNCTION f;
--echo # Running mysql -uroot test < **vardir**/test.dmp
--exec $MYSQL -uroot test < $MYSQLTEST_VARDIR/test.dmp
--echo #
--echo # Cleanup after succesful import.
--echo #
DROP VIEW v1;
DROP FUNCTION f;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment