diff options
author | Oleksandr Byelkin <sanja@mariadb.com> | 2017-05-03 12:26:57 +0200 |
---|---|---|
committer | Oleksandr Byelkin <sanja@mariadb.com> | 2017-05-04 14:33:33 +0200 |
commit | 96247be1a0dfa3035580b53b1c27a7247a410713 (patch) | |
tree | f0f5401fcd53d615048d3091749e3252eec073ef | |
parent | ba824b66c1132f1360a317eeb8b590b705f04b69 (diff) | |
download | mariadb-git-96247be1a0dfa3035580b53b1c27a7247a410713.tar.gz |
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.
-rw-r--r-- | client/mysqldump.c | 14 | ||||
-rw-r--r-- | mysql-test/r/mysqldump.result | 49 | ||||
-rw-r--r-- | mysql-test/t/mysqldump.test | 12 |
3 files changed, 74 insertions, 1 deletions
diff --git a/client/mysqldump.c b/client/mysqldump.c index 281a7a6c7f2..99fcbdb4250 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -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_include_master_host_port= 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 ulong opt_max_allowed_packet, opt_net_buffer_length; static MYSQL mysql_connection,*mysql=0; @@ -233,6 +234,9 @@ static struct my_option my_long_options[] = {"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, 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.", &opt_lock, &opt_lock, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0}, @@ -3281,6 +3285,10 @@ static void dump_trigger_old(FILE *sql_file, MYSQL_RES *show_triggers_rs, if (opt_compact) 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, "DELIMITER ;;\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, 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]), C_STRING_WITH_LEN("50017"), C_STRING_WITH_LEN("50003"), diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index 1243c455e6c..66b501e8278 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -5534,3 +5534,52 @@ USE `db1`; DROP DATABASE db1; DROP DATABASE db2; 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; diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index ea08f540cf3..6d4e0e3f2b9 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -2582,3 +2582,15 @@ 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 # 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; |