Commit 675c4bb4 authored by unknown's avatar unknown

Added sql_mode saving to mysql_dump (BUG#5891, part 2)


client/client_priv.h:
  add OPT_ for --trigger parameter
client/mysqldump.c:
  fixed short simbol for trigger
  fixed lines break for more compiler compatibility
  added sql_mode output
  added comments
  made protection of trigger and view restoring commands from execution by old versions of mysql
mysql-test/r/mysqldump.result:
  changed test, to test sql_mode
mysql-test/r/sp.result:
  now sql_mode preserved in SP
mysql-test/t/mysqldump.test:
  changed test, to test sql_mode
mysql-test/t/sp.test:
  now sql_mode preserved in SP
sql/set_var.cc:
  fixed comment
parent 21189de3
...@@ -49,5 +49,6 @@ enum options_client ...@@ -49,5 +49,6 @@ enum options_client
#ifdef HAVE_NDBCLUSTER_DB #ifdef HAVE_NDBCLUSTER_DB
OPT_NDBCLUSTER, OPT_NDB_CONNECTSTRING, OPT_NDBCLUSTER, OPT_NDB_CONNECTSTRING,
#endif #endif
OPT_IGNORE_TABLE,OPT_INSERT_IGNORE,OPT_SHOW_WARNINGS,OPT_DROP_DATABASE OPT_IGNORE_TABLE, OPT_INSERT_IGNORE, OPT_SHOW_WARNINGS, OPT_DROP_DATABASE,
OPT_TRIGGER
}; };
...@@ -372,7 +372,7 @@ static struct my_option my_long_options[] = ...@@ -372,7 +372,7 @@ static struct my_option my_long_options[] =
(gptr*) &path, (gptr*) &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, (gptr*) &path, (gptr*) &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"tables", OPT_TABLES, "Overrides option --databases (-B).", {"tables", OPT_TABLES, "Overrides option --databases (-B).",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"triggers", '/0', "Dump triggers for each dumped table", {"triggers", OPT_TRIGGER, "Dump triggers for each dumped table",
(gptr*) &opt_dump_triggers, (gptr*) &opt_dump_triggers, 0, GET_BOOL, (gptr*) &opt_dump_triggers, (gptr*) &opt_dump_triggers, 0, GET_BOOL,
NO_ARG, 1, 0, 0, 0, 0, 0}, NO_ARG, 1, 0, 0, 0, 0, 0},
#ifndef DONT_ALLOW_USER_CHANGE #ifndef DONT_ALLOW_USER_CHANGE
...@@ -1296,10 +1296,11 @@ static uint get_table_structure(char *table, char *db) ...@@ -1296,10 +1296,11 @@ static uint get_table_structure(char *table, char *db)
row= mysql_fetch_row(tableRes); row= mysql_fetch_row(tableRes);
if (opt_drop) if (opt_drop)
fprintf(sql_file, "DROP VIEW IF EXISTS %s;\n",opt_quoted_table); fprintf(sql_file, "/*!50001 DROP VIEW IF EXISTS %s*/;\n",
opt_quoted_table);
/* Print CREATE statement but remove TEMPORARY */ /* Print CREATE statement but remove TEMPORARY */
fprintf(sql_file, "CREATE %s;\n", row[1]+17); fprintf(sql_file, "/*!50001 CREATE %s*/;\n", row[1]+17);
check_io(sql_file); check_io(sql_file);
mysql_free_result(tableRes); mysql_free_result(tableRes);
...@@ -1335,19 +1336,23 @@ static uint get_table_structure(char *table, char *db) ...@@ -1335,19 +1336,23 @@ static uint get_table_structure(char *table, char *db)
DBUG_RETURN(0); DBUG_RETURN(0);
} }
if (mysql_num_rows(tableRes)) if (mysql_num_rows(tableRes))
fprintf(sql_file, "\nDELIMITER //;\n"); fprintf(sql_file, "\n/*!50003 SET @OLD_SQL_MODE=@@SQL_MODE*/;\n\
DELIMITER //;\n");
while ((row=mysql_fetch_row(tableRes))) while ((row=mysql_fetch_row(tableRes)))
{ {
fprintf(sql_file, "CREATE TRIGGER %s %s %s ON %s\n" fprintf(sql_file, "/*!50003 SET SESSION SQL_MODE=\"%s\"*/ //\n\
"FOR EACH ROW%s//\n\n", /*!50003 CREATE TRIGGER %s %s %s ON %s FOR EACH ROW%s*/ //\n\n",
quote_name(row[0], name_buff, 0), row[6], /* sql_mode */
row[4], quote_name(row[0], name_buff, 0), /* Trigger */
row[1], row[4], /* Timing */
row[1], /* Event */
result_table, result_table,
row[3]); row[3] /* Statement */);
} }
if (mysql_num_rows(tableRes)) if (mysql_num_rows(tableRes))
fprintf(sql_file, "DELIMITER ;//"); fprintf(sql_file,
"DELIMITER ;//\n\
/*!50003 SET SESSION SQL_MODE=@OLD_SQL_MODE*/;");
mysql_free_result(tableRes); mysql_free_result(tableRes);
} }
} }
...@@ -2957,13 +2962,15 @@ static my_bool get_view_structure(char *table, char* db) ...@@ -2957,13 +2962,15 @@ static my_bool get_view_structure(char *table, char* db)
} }
if (opt_drop) if (opt_drop)
{ {
fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", opt_quoted_table); fprintf(sql_file, "/*!50001 DROP TABLE IF EXISTS %s*/;\n",
fprintf(sql_file, "DROP VIEW IF EXISTS %s;\n", opt_quoted_table); opt_quoted_table);
fprintf(sql_file, "/*!50001 DROP VIEW IF EXISTS %s*/;\n",
opt_quoted_table);
check_io(sql_file); check_io(sql_file);
} }
row= mysql_fetch_row(table_res); row= mysql_fetch_row(table_res);
fprintf(sql_file, "%s;\n", row[1]); fprintf(sql_file, "/*!50001 %s*/;\n", row[1]);
check_io(sql_file); check_io(sql_file);
mysql_free_result(table_res); mysql_free_result(table_res);
......
...@@ -379,13 +379,13 @@ LOCK TABLES `t1` WRITE; ...@@ -379,13 +379,13 @@ LOCK TABLES `t1` WRITE;
UNLOCK TABLES; UNLOCK TABLES;
/*!40000 ALTER TABLE `t1` ENABLE KEYS */; /*!40000 ALTER TABLE `t1` ENABLE KEYS */;
DROP TABLE IF EXISTS `v1`; DROP TABLE IF EXISTS `v1`;
DROP VIEW IF EXISTS `v1`; /*!50001 DROP VIEW IF EXISTS `v1`*/;
CREATE TABLE `v1` ( /*!50001 CREATE TABLE `v1` (
`a` int(11) default NULL `a` int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1; ) ENGINE=MyISAM DEFAULT CHARSET=latin1*/;
DROP TABLE IF EXISTS `v1`; /*!50001 DROP TABLE IF EXISTS `v1`*/;
DROP VIEW IF EXISTS `v1`; /*!50001 DROP VIEW IF EXISTS `v1`*/;
CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select `test`.`t1`.`a` AS `a` from `test`.`t1`; /*!50001 CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select `test`.`t1`.`a` AS `a` from `test`.`t1`*/;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
...@@ -1462,13 +1462,13 @@ INSERT INTO `t2` VALUES ('alfred'),('angie'),('bingo'),('waffle'),('lemon'); ...@@ -1462,13 +1462,13 @@ INSERT INTO `t2` VALUES ('alfred'),('angie'),('bingo'),('waffle'),('lemon');
UNLOCK TABLES; UNLOCK TABLES;
/*!40000 ALTER TABLE `t2` ENABLE KEYS */; /*!40000 ALTER TABLE `t2` ENABLE KEYS */;
DROP TABLE IF EXISTS `v2`; DROP TABLE IF EXISTS `v2`;
DROP VIEW IF EXISTS `v2`; /*!50001 DROP VIEW IF EXISTS `v2`*/;
CREATE TABLE `v2` ( /*!50001 CREATE TABLE `v2` (
`a` varchar(30) default NULL `a` varchar(30) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1; ) ENGINE=MyISAM DEFAULT CHARSET=latin1*/;
DROP TABLE IF EXISTS `v2`; /*!50001 DROP TABLE IF EXISTS `v2`*/;
DROP VIEW IF EXISTS `v2`; /*!50001 DROP VIEW IF EXISTS `v2`*/;
CREATE ALGORITHM=UNDEFINED VIEW `db1`.`v2` AS select `db1`.`t2`.`a` AS `a` from `db1`.`t2` where (`db1`.`t2`.`a` like _latin1'a%') WITH CASCADED CHECK OPTION; /*!50001 CREATE ALGORITHM=UNDEFINED VIEW `db1`.`v2` AS select `db1`.`t2`.`a` AS `a` from `db1`.`t2` where (`db1`.`t2`.`a` like _latin1'a%') WITH CASCADED CHECK OPTION*/;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
...@@ -1685,6 +1685,7 @@ end| ...@@ -1685,6 +1685,7 @@ end|
create trigger trg2 before update on t1 for each row begin create trigger trg2 before update on t1 for each row begin
if old.a % 2 = 0 then set new.b := 12; end if; if old.a % 2 = 0 then set new.b := 12; end if;
end| end|
set sql_mode="traditional"|
create trigger trg3 after update on t1 for each row create trigger trg3 after update on t1 for each row
begin begin
if new.a = -1 then if new.a = -1 then
...@@ -1697,8 +1698,9 @@ if new.a > 10 then ...@@ -1697,8 +1698,9 @@ if new.a > 10 then
set @fired:= "No"; set @fired:= "No";
end if; end if;
end| end|
set sql_mode=default|
show triggers like "t1"; show triggers like "t1";
Trigger Event Table Statement Timing Created Trigger Event Table Statement Timing Created sql_mode
trg1 INSERT t1 trg1 INSERT t1
begin begin
if new.a > 10 then if new.a > 10 then
...@@ -1714,7 +1716,7 @@ begin ...@@ -1714,7 +1716,7 @@ begin
if new.a = -1 then if new.a = -1 then
set @fired:= "Yes"; set @fired:= "Yes";
end if; end if;
end AFTER 0000-00-00 00:00:00 end AFTER 0000-00-00 00:00:00 STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER
INSERT INTO t1 (a) VALUES (1),(2),(3),(22); INSERT INTO t1 (a) VALUES (1),(2),(3),(22);
update t1 set a = 4 where a=3; update t1 set a = 4 where a=3;
...@@ -1736,30 +1738,32 @@ CREATE TABLE `t1` ( ...@@ -1736,30 +1738,32 @@ CREATE TABLE `t1` (
`b` bigint(20) default NULL `b` bigint(20) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1; ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!50003 SET @OLD_SQL_MODE=@@SQL_MODE*/;
DELIMITER //; DELIMITER //;
CREATE TRIGGER `trg1` BEFORE INSERT ON `t1` /*!50003 SET SESSION SQL_MODE=""*/ //
FOR EACH ROW /*!50003 CREATE TRIGGER `trg1` BEFORE INSERT ON `t1` FOR EACH ROW
begin begin
if new.a > 10 then if new.a > 10 then
set new.a := 10; set new.a := 10;
set new.a := 11; set new.a := 11;
end if; end if;
end// end*/ //
CREATE TRIGGER `trg2` BEFORE UPDATE ON `t1` /*!50003 SET SESSION SQL_MODE=""*/ //
FOR EACH ROW begin /*!50003 CREATE TRIGGER `trg2` BEFORE UPDATE ON `t1` FOR EACH ROW begin
if old.a % 2 = 0 then set new.b := 12; end if; if old.a % 2 = 0 then set new.b := 12; end if;
end// end*/ //
CREATE TRIGGER `trg3` AFTER UPDATE ON `t1` /*!50003 SET SESSION SQL_MODE="STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER"*/ //
FOR EACH ROW /*!50003 CREATE TRIGGER `trg3` AFTER UPDATE ON `t1` FOR EACH ROW
begin begin
if new.a = -1 then if new.a = -1 then
set @fired:= "Yes"; set @fired:= "Yes";
end if; end if;
end// end*/ //
DELIMITER ;// DELIMITER ;//
/*!50003 SET SESSION SQL_MODE=@OLD_SQL_MODE*/;
/*!40000 ALTER TABLE `t1` DISABLE KEYS */; /*!40000 ALTER TABLE `t1` DISABLE KEYS */;
LOCK TABLES `t1` WRITE; LOCK TABLES `t1` WRITE;
...@@ -1771,16 +1775,18 @@ CREATE TABLE `t2` ( ...@@ -1771,16 +1775,18 @@ CREATE TABLE `t2` (
`a` int(11) default NULL `a` int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1; ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!50003 SET @OLD_SQL_MODE=@@SQL_MODE*/;
DELIMITER //; DELIMITER //;
CREATE TRIGGER `trg4` BEFORE INSERT ON `t2` /*!50003 SET SESSION SQL_MODE="STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER"*/ //
FOR EACH ROW /*!50003 CREATE TRIGGER `trg4` BEFORE INSERT ON `t2` FOR EACH ROW
begin begin
if new.a > 10 then if new.a > 10 then
set @fired:= "No"; set @fired:= "No";
end if; end if;
end// end*/ //
DELIMITER ;// DELIMITER ;//
/*!50003 SET SESSION SQL_MODE=@OLD_SQL_MODE*/;
/*!40000 ALTER TABLE `t2` DISABLE KEYS */; /*!40000 ALTER TABLE `t2` DISABLE KEYS */;
LOCK TABLES `t2` WRITE; LOCK TABLES `t2` WRITE;
...@@ -1844,4 +1850,28 @@ show tables; ...@@ -1844,4 +1850,28 @@ show tables;
Tables_in_test Tables_in_test
t1 t1
t2 t2
show triggers;
Trigger Event Table Statement Timing Created sql_mode
trg1 INSERT t1
begin
if new.a > 10 then
set new.a := 10;
set new.a := 11;
end if;
end BEFORE #
trg2 UPDATE t1 begin
if old.a % 2 = 0 then set new.b := 12; end if;
end BEFORE #
trg3 UPDATE t1
begin
if new.a = -1 then
set @fired:= "Yes";
end if;
end AFTER # STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER
trg4 INSERT t2
begin
if new.a > 10 then
set @fired:= "No";
end if;
end BEFORE # STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER
DROP TABLE t1, t2; DROP TABLE t1, t2;
...@@ -2658,20 +2658,20 @@ call avg ()| ...@@ -2658,20 +2658,20 @@ call avg ()|
drop procedure avg| drop procedure avg|
drop procedure if exists bug6129| drop procedure if exists bug6129|
set @old_mode= @@sql_mode; set @old_mode= @@sql_mode;
set @@sql_mode= ""; set @@sql_mode= "ERROR_FOR_DIVISION_BY_ZERO";
create procedure bug6129() create procedure bug6129()
select @@sql_mode| select @@sql_mode|
call bug6129()| call bug6129()|
@@sql_mode @@sql_mode
ERROR_FOR_DIVISION_BY_ZERO
set @@sql_mode= "NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO"| set @@sql_mode= "NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO"|
call bug6129()| call bug6129()|
@@sql_mode @@sql_mode
NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO ERROR_FOR_DIVISION_BY_ZERO
set @@sql_mode= "NO_ZERO_IN_DATE"| set @@sql_mode= "NO_ZERO_IN_DATE"|
call bug6129()| call bug6129()|
@@sql_mode @@sql_mode
NO_ZERO_IN_DATE ERROR_FOR_DIVISION_BY_ZERO
set @@sql_mode=@old_mode; set @@sql_mode=@old_mode;
drop procedure bug6129| drop procedure bug6129|
drop procedure if exists bug9856| drop procedure if exists bug9856|
......
...@@ -726,6 +726,7 @@ end| ...@@ -726,6 +726,7 @@ end|
create trigger trg2 before update on t1 for each row begin create trigger trg2 before update on t1 for each row begin
if old.a % 2 = 0 then set new.b := 12; end if; if old.a % 2 = 0 then set new.b := 12; end if;
end| end|
set sql_mode="traditional"|
create trigger trg3 after update on t1 for each row create trigger trg3 after update on t1 for each row
begin begin
if new.a = -1 then if new.a = -1 then
...@@ -738,6 +739,7 @@ begin ...@@ -738,6 +739,7 @@ begin
set @fired:= "No"; set @fired:= "No";
end if; end if;
end| end|
set sql_mode=default|
delimiter ;| delimiter ;|
--replace_column 6 '0000-00-00 00:00:00' --replace_column 6 '0000-00-00 00:00:00'
show triggers like "t1"; show triggers like "t1";
...@@ -753,4 +755,6 @@ drop table t1; ...@@ -753,4 +755,6 @@ drop table t1;
--exec $MYSQL test < var/tmp/mysqldump.sql --exec $MYSQL test < var/tmp/mysqldump.sql
# Check that tables have been reloaded # Check that tables have been reloaded
show tables; show tables;
--replace_column 6 #
show triggers;
DROP TABLE t1, t2; DROP TABLE t1, t2;
...@@ -3378,7 +3378,7 @@ drop procedure avg| ...@@ -3378,7 +3378,7 @@ drop procedure avg|
drop procedure if exists bug6129| drop procedure if exists bug6129|
--enable_warnings --enable_warnings
set @old_mode= @@sql_mode; set @old_mode= @@sql_mode;
set @@sql_mode= ""; set @@sql_mode= "ERROR_FOR_DIVISION_BY_ZERO";
create procedure bug6129() create procedure bug6129()
select @@sql_mode| select @@sql_mode|
call bug6129()| call bug6129()|
......
...@@ -3199,10 +3199,13 @@ bool sys_var_thd_table_type::update(THD *thd, set_var *var) ...@@ -3199,10 +3199,13 @@ bool sys_var_thd_table_type::update(THD *thd, set_var *var)
/* /*
Make string representation of mode Make string representation of mode
SINOPSYS SYNOPSIS
thd thread handler thd in thread handler
val sql_mode value val in sql_mode value
len pointer on length of string len out pointer on length of string
RETURN
pointer to string with sql_mode representation
*/ */
byte *sys_var_thd_sql_mode::symbolic_mode_representation(THD *thd, ulong val, byte *sys_var_thd_sql_mode::symbolic_mode_representation(THD *thd, ulong val,
......
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