Skip to content

Commit

Permalink
MDEV-31092 mysqldump --force doesn't ignore error as it should
Browse files Browse the repository at this point in the history
failed SHOW CREATE FUNCTION means we don't dump this function,
but should still try to dump all other functions
  • Loading branch information
vuvova committed Jul 31, 2023
1 parent 4dd38f9 commit ab10a67
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 5 deletions.
6 changes: 1 addition & 5 deletions client/mysqldump.c
Expand Up @@ -2723,11 +2723,7 @@ static uint dump_routines_for_db(char *db)
routine_type[i], routine_name);

if (mysql_query_with_error_report(mysql, &routine_res, query_buff))
{
mysql_free_result(routine_list_res);
routine_list_res= 0;
DBUG_RETURN(1);
}
continue;

while ((row= mysql_fetch_row(routine_res)))
{
Expand Down
64 changes: 64 additions & 0 deletions mysql-test/main/mysqldump.result
Expand Up @@ -6342,6 +6342,7 @@ END utf8 utf8_general_ci latin1_swedish_ci
DROP DATABASE test1;
DROP DATABASE test2;
SET sql_mode=@save_sql_mode;
use test;
#
# MDEV-4875 Can't restore a mysqldump if --add-drop-database meets general_log
#
Expand Down Expand Up @@ -6435,4 +6436,67 @@ TABLE 1
SET GLOBAL LOG_OUTPUT=DEFAULT, GLOBAL GENERAL_LOG=@save_general_log;
TRUNCATE TABLE mysql.general_log;
DROP DATABASE test1;
#
# End of 10.3 tests
#
#
# MDEV-31092 mysqldump --force doesn't ignore error as it should
#
create function f1() returns int return 1;
create function f2() returns int return 2;
update mysql.proc set body='return no_such_var' where db='test' and name='f1';
create event e1 on schedule every 1 year starts '2030-01-01' do select 1;
Warnings:
Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it.
update mysql.event set body ='select not_a_value' where db='test' and name='e1';
create table t1 (i int);
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t1` (
`i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
mysqldump: Couldn't execute 'SHOW CREATE FUNCTION `f1`': Undeclared variable: no_such_var (1327)
/*!50106 SET @save_time_zone= @@TIME_ZONE */ ;
DELIMITER ;;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;;
/*!50003 SET character_set_client = utf8 */ ;;
/*!50003 SET character_set_results = utf8 */ ;;
/*!50003 SET collation_connection = utf8_general_ci */ ;;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;;
/*!50003 SET sql_mode = '' */ ;;
/*!50003 SET @saved_time_zone = @@time_zone */ ;;
/*!50003 SET time_zone = 'SYSTEM' */ ;;
/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `e1` ON SCHEDULE EVERY 1 YEAR STARTS '2030-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO select not_a_value */ ;;
/*!50003 SET time_zone = @saved_time_zone */ ;;
/*!50003 SET sql_mode = @saved_sql_mode */ ;;
/*!50003 SET character_set_client = @saved_cs_client */ ;;
/*!50003 SET character_set_results = @saved_cs_results */ ;;
/*!50003 SET collation_connection = @saved_col_connection */ ;;
DELIMITER ;
/*!50106 SET TIME_ZONE= @save_time_zone */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = '' */ ;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8 */ ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `f2`() RETURNS int(11)
return 2 ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
drop function f1;
drop function f2;
drop event e1;
drop table t1;
#
# End of 10.4 tests
#
24 changes: 24 additions & 0 deletions mysql-test/main/mysqldump.test
Expand Up @@ -2921,6 +2921,7 @@ DROP DATABASE test1;
DROP DATABASE test2;
SET sql_mode=@save_sql_mode;
--remove_file $MYSQLTEST_VARDIR/tmp/dumptest1.sql
use test;

--echo #
--echo # MDEV-4875 Can't restore a mysqldump if --add-drop-database meets general_log
Expand Down Expand Up @@ -2981,4 +2982,27 @@ TRUNCATE TABLE mysql.general_log;
DROP DATABASE test1;
--remove_file $MYSQLTEST_VARDIR/tmp/dumptest1.sql

--echo #
--echo # End of 10.3 tests
--echo #

--echo #
--echo # MDEV-31092 mysqldump --force doesn't ignore error as it should
--echo #
create function f1() returns int return 1;
create function f2() returns int return 2;
update mysql.proc set body='return no_such_var' where db='test' and name='f1';
create event e1 on schedule every 1 year starts '2030-01-01' do select 1;
update mysql.event set body ='select not_a_value' where db='test' and name='e1';
create table t1 (i int);
--replace_result mysqldump.exe mysqldump
--error 2
--exec $MYSQL_DUMP --compact --events --routines --force test 2>&1
drop function f1;
drop function f2;
drop event e1;
drop table t1;

--echo #
--echo # End of 10.4 tests
--echo #

0 comments on commit ab10a67

Please sign in to comment.