Commit 96247be1 authored by Oleksandr Byelkin's avatar Oleksandr Byelkin

MDEV-10431: Please implement mysqldump --add-drop-trigger from MySQL 5.6

Port of mysql changeset by Georgi Kodinov <Georgi.Kodinov@Oracle.com>:

    Bug #34325 : --add-drop-trigger option for mysqldump

    Implemented the --add-drop-trigger option to prepend each
    CREATE TRIGGER in the dump file with DROP TRIGGER.
    The option is off by default. Added a test case.
parent ba824b66
...@@ -114,7 +114,8 @@ static my_bool verbose= 0, opt_no_create_info= 0, opt_no_data= 0, opt_no_data_m ...@@ -114,7 +114,8 @@ static my_bool verbose= 0, opt_no_create_info= 0, opt_no_data= 0, opt_no_data_m
opt_slave_apply= 0, opt_slave_apply= 0,
opt_include_master_host_port= 0, opt_include_master_host_port= 0,
opt_events= 0, opt_comments_used= 0, opt_events= 0, opt_comments_used= 0,
opt_alltspcs=0, opt_notspcs= 0, opt_logging; opt_alltspcs=0, opt_notspcs= 0, opt_logging,
opt_drop_trigger= 0 ;
static my_bool insert_pat_inited= 0, debug_info_flag= 0, debug_check_flag= 0; static my_bool insert_pat_inited= 0, debug_info_flag= 0, debug_check_flag= 0;
static ulong opt_max_allowed_packet, opt_net_buffer_length; static ulong opt_max_allowed_packet, opt_net_buffer_length;
static MYSQL mysql_connection,*mysql=0; static MYSQL mysql_connection,*mysql=0;
...@@ -233,6 +234,9 @@ static struct my_option my_long_options[] = ...@@ -233,6 +234,9 @@ static struct my_option my_long_options[] =
{"add-drop-table", OPT_DROP, "Add a DROP TABLE before each create.", {"add-drop-table", OPT_DROP, "Add a DROP TABLE before each create.",
&opt_drop, &opt_drop, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, &opt_drop, &opt_drop, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
0}, 0},
{"add-drop-trigger", 0, "Add a DROP TRIGGER before each create.",
&opt_drop_trigger, &opt_drop_trigger, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
0},
{"add-locks", OPT_LOCKS, "Add locks around INSERT statements.", {"add-locks", OPT_LOCKS, "Add locks around INSERT statements.",
&opt_lock, &opt_lock, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, &opt_lock, &opt_lock, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
0}, 0},
...@@ -3281,6 +3285,10 @@ static void dump_trigger_old(FILE *sql_file, MYSQL_RES *show_triggers_rs, ...@@ -3281,6 +3285,10 @@ static void dump_trigger_old(FILE *sql_file, MYSQL_RES *show_triggers_rs,
if (opt_compact) if (opt_compact)
fprintf(sql_file, "/*!50003 SET @OLD_SQL_MODE=@@SQL_MODE*/;\n"); fprintf(sql_file, "/*!50003 SET @OLD_SQL_MODE=@@SQL_MODE*/;\n");
if (opt_drop_trigger)
fprintf(sql_file, "/*!50032 DROP TRIGGER IF EXISTS %s */;\n",
(*show_trigger_row)[0]);
fprintf(sql_file, fprintf(sql_file,
"DELIMITER ;;\n" "DELIMITER ;;\n"
"/*!50003 SET SESSION SQL_MODE=\"%s\" */;;\n" "/*!50003 SET SESSION SQL_MODE=\"%s\" */;;\n"
...@@ -3361,6 +3369,10 @@ static int dump_trigger(FILE *sql_file, MYSQL_RES *show_create_trigger_rs, ...@@ -3361,6 +3369,10 @@ static int dump_trigger(FILE *sql_file, MYSQL_RES *show_create_trigger_rs,
switch_sql_mode(sql_file, ";", row[1]); switch_sql_mode(sql_file, ";", row[1]);
if (opt_drop_trigger)
fprintf(sql_file, "/*!50032 DROP TRIGGER IF EXISTS %s */;\n",
row[0]);
query_str= cover_definer_clause(row[2], strlen(row[2]), query_str= cover_definer_clause(row[2], strlen(row[2]),
C_STRING_WITH_LEN("50017"), C_STRING_WITH_LEN("50017"),
C_STRING_WITH_LEN("50003"), C_STRING_WITH_LEN("50003"),
......
...@@ -5534,3 +5534,52 @@ USE `db1`; ...@@ -5534,3 +5534,52 @@ USE `db1`;
DROP DATABASE db1; DROP DATABASE db1;
DROP DATABASE db2; DROP DATABASE db2;
FOUND 1 /Database: mysql/ in bug11505.sql FOUND 1 /Database: mysql/ in bug11505.sql
#
# Test for --add-drop-trigger
#
use test;
CREATE TABLE t1 (a int, b int);
CREATE TRIGGER tt1_t1 BEFORE INSERT ON t1 FOR EACH ROW
SET NEW.b=NEW.a + 10;
INSERT INTO t1 (a) VALUES (1),(2),(3);
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `test` /*!40100 DEFAULT CHARACTER SET latin1 */;
USE `test`;
/*!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 = '' */ ;
/*!50032 DROP TRIGGER IF EXISTS tt1_t1 */;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER tt1_t1 BEFORE INSERT ON t1 FOR EACH ROW
SET NEW.b=NEW.a + 10 */;;
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 */ ;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
DROP TABLE t1;
...@@ -2582,3 +2582,15 @@ let SEARCH_FILE=$MYSQLTEST_VARDIR/tmp/bug11505.sql; ...@@ -2582,3 +2582,15 @@ let SEARCH_FILE=$MYSQLTEST_VARDIR/tmp/bug11505.sql;
let SEARCH_PATTERN=Database: mysql; let SEARCH_PATTERN=Database: mysql;
exec $MYSQL_DUMP mysql func > $SEARCH_FILE; exec $MYSQL_DUMP mysql func > $SEARCH_FILE;
source include/search_pattern_in_file.inc; source include/search_pattern_in_file.inc;
--echo #
--echo # Test for --add-drop-trigger
--echo #
use test;
CREATE TABLE t1 (a int, b int);
CREATE TRIGGER tt1_t1 BEFORE INSERT ON t1 FOR EACH ROW
SET NEW.b=NEW.a + 10;
INSERT INTO t1 (a) VALUES (1),(2),(3);
--exec $MYSQL_DUMP --triggers --no-data --no-create-info --add-drop-trigger --skip-comments --databases test
DROP TABLE t1;
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