Commit cff531ff authored by unknown's avatar unknown

Fixed bug #29788.

After dumping triggers mysqldump copied 
the value of the OLD_SQL_MODE variable to the SQL_MODE
variable. If the --compact option of the mysqldump was
not set the OLD_SQL_MODE variable had the value
of the uninitialized SQL_MODE variable. So
usually the NO_AUTO_VALUE_ON_ZERO option of the
SQL_MODE variable was discarded.

This fix is for non-"--compact" mode of the mysqldump,
because mysqldump --compact never set SQL_MODE to the
value of NO_AUTO_VALUE_ON_ZERO.

The dump_triggers_for_table function has been modified
to restore previous value of the SQL_MODE variable after
dumping triggers using the SAVE_SQL_MODE temporary
variable.


client/mysqldump.c:
  Fixed bug #29788.
  The dump_triggers_for_table function has been modified
  to restore previous value of the SQL_MODE variable after
  dumping triggers using the SAVE_SQL_MODE temporary
  variable.
mysql-test/r/mysqldump.result:
  Updated test case for bug #29788.
mysql-test/t/mysqldump.test:
  Updated test case for bug #29788.
parent db31d3c9
...@@ -2122,8 +2122,7 @@ static void dump_triggers_for_table(char *table, ...@@ -2122,8 +2122,7 @@ static void dump_triggers_for_table(char *table,
} }
if (mysql_num_rows(result)) if (mysql_num_rows(result))
{ {
if (opt_compact) fprintf(sql_file, "\n/*!50003 SET @SAVE_SQL_MODE=@@SQL_MODE*/;\n");
fprintf(sql_file, "\n/*!50003 SET @OLD_SQL_MODE=@@SQL_MODE*/;\n");
fprintf(sql_file, "\nDELIMITER ;;\n"); fprintf(sql_file, "\nDELIMITER ;;\n");
} }
while ((row= mysql_fetch_row(result))) while ((row= mysql_fetch_row(result)))
...@@ -2167,9 +2166,11 @@ static void dump_triggers_for_table(char *table, ...@@ -2167,9 +2166,11 @@ static void dump_triggers_for_table(char *table,
row[3] /* Statement */); row[3] /* Statement */);
} }
if (mysql_num_rows(result)) if (mysql_num_rows(result))
{
fprintf(sql_file, fprintf(sql_file,
"DELIMITER ;\n" "DELIMITER ;\n"
"/*!50003 SET SESSION SQL_MODE=@OLD_SQL_MODE */;\n"); "/*!50003 SET SESSION SQL_MODE=@SAVE_SQL_MODE*/;\n");
}
mysql_free_result(result); mysql_free_result(result);
/* /*
make sure to set back opt_compatible mode to make sure to set back opt_compatible mode to
......
...@@ -2238,6 +2238,8 @@ INSERT INTO `t1` VALUES (1,NULL),(2,NULL),(4,NULL),(11,NULL); ...@@ -2238,6 +2238,8 @@ INSERT INTO `t1` VALUES (1,NULL),(2,NULL),(4,NULL),(11,NULL);
/*!40000 ALTER TABLE `t1` ENABLE KEYS */; /*!40000 ALTER TABLE `t1` ENABLE KEYS */;
UNLOCK TABLES; UNLOCK TABLES;
/*!50003 SET @SAVE_SQL_MODE=@@SQL_MODE*/;
DELIMITER ;; DELIMITER ;;
/*!50003 SET SESSION SQL_MODE="" */;; /*!50003 SET SESSION SQL_MODE="" */;;
/*!50003 CREATE */ /*!50017 DEFINER=`root`@`localhost` */ /*!50003 TRIGGER `trg1` BEFORE INSERT ON `t1` FOR EACH ROW begin /*!50003 CREATE */ /*!50017 DEFINER=`root`@`localhost` */ /*!50003 TRIGGER `trg1` BEFORE INSERT ON `t1` FOR EACH ROW begin
...@@ -2260,7 +2262,7 @@ end if; ...@@ -2260,7 +2262,7 @@ end if;
end */;; end */;;
DELIMITER ; DELIMITER ;
/*!50003 SET SESSION SQL_MODE=@OLD_SQL_MODE */; /*!50003 SET SESSION SQL_MODE=@SAVE_SQL_MODE*/;
DROP TABLE IF EXISTS `t2`; DROP TABLE IF EXISTS `t2`;
CREATE TABLE `t2` ( CREATE TABLE `t2` (
`a` int(11) default NULL `a` int(11) default NULL
...@@ -2271,6 +2273,8 @@ LOCK TABLES `t2` WRITE; ...@@ -2271,6 +2273,8 @@ LOCK TABLES `t2` WRITE;
/*!40000 ALTER TABLE `t2` ENABLE KEYS */; /*!40000 ALTER TABLE `t2` ENABLE KEYS */;
UNLOCK TABLES; UNLOCK TABLES;
/*!50003 SET @SAVE_SQL_MODE=@@SQL_MODE*/;
DELIMITER ;; DELIMITER ;;
/*!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" */;; /*!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" */;;
/*!50003 CREATE */ /*!50017 DEFINER=`root`@`localhost` */ /*!50003 TRIGGER `trg4` BEFORE INSERT ON `t2` FOR EACH ROW begin /*!50003 CREATE */ /*!50017 DEFINER=`root`@`localhost` */ /*!50003 TRIGGER `trg4` BEFORE INSERT ON `t2` FOR EACH ROW begin
...@@ -2280,7 +2284,7 @@ end if; ...@@ -2280,7 +2284,7 @@ end if;
end */;; end */;;
DELIMITER ; DELIMITER ;
/*!50003 SET SESSION SQL_MODE=@OLD_SQL_MODE */; /*!50003 SET SESSION SQL_MODE=@SAVE_SQL_MODE*/;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
...@@ -2628,13 +2632,15 @@ INSERT INTO "t1 test" VALUES (1),(2),(3); ...@@ -2628,13 +2632,15 @@ INSERT INTO "t1 test" VALUES (1),(2),(3);
/*!40000 ALTER TABLE "t1 test" ENABLE KEYS */; /*!40000 ALTER TABLE "t1 test" ENABLE KEYS */;
UNLOCK TABLES; UNLOCK TABLES;
/*!50003 SET @SAVE_SQL_MODE=@@SQL_MODE*/;
DELIMITER ;; DELIMITER ;;
/*!50003 SET SESSION SQL_MODE="" */;; /*!50003 SET SESSION SQL_MODE="" */;;
/*!50003 CREATE */ /*!50017 DEFINER=`root`@`localhost` */ /*!50003 TRIGGER `test trig` BEFORE INSERT ON `t1 test` FOR EACH ROW BEGIN /*!50003 CREATE */ /*!50017 DEFINER=`root`@`localhost` */ /*!50003 TRIGGER `test trig` BEFORE INSERT ON `t1 test` FOR EACH ROW BEGIN
INSERT INTO `t2 test` SET a2 = NEW.a1; END */;; INSERT INTO `t2 test` SET a2 = NEW.a1; END */;;
DELIMITER ; DELIMITER ;
/*!50003 SET SESSION SQL_MODE=@OLD_SQL_MODE */; /*!50003 SET SESSION SQL_MODE=@SAVE_SQL_MODE*/;
DROP TABLE IF EXISTS "t2 test"; DROP TABLE IF EXISTS "t2 test";
CREATE TABLE "t2 test" ( CREATE TABLE "t2 test" (
"a2" int(11) default NULL "a2" int(11) default NULL
...@@ -2788,6 +2794,8 @@ LOCK TABLES `t1` WRITE; ...@@ -2788,6 +2794,8 @@ LOCK TABLES `t1` WRITE;
/*!40000 ALTER TABLE `t1` ENABLE KEYS */; /*!40000 ALTER TABLE `t1` ENABLE KEYS */;
UNLOCK TABLES; UNLOCK TABLES;
/*!50003 SET @SAVE_SQL_MODE=@@SQL_MODE*/;
DELIMITER ;; DELIMITER ;;
/*!50003 SET SESSION SQL_MODE="IGNORE_SPACE" */;; /*!50003 SET SESSION SQL_MODE="IGNORE_SPACE" */;;
/*!50003 CREATE */ /*!50017 DEFINER=`root`@`localhost` */ /*!50003 TRIGGER `tr1` BEFORE INSERT ON `t1` FOR EACH ROW BEGIN /*!50003 CREATE */ /*!50017 DEFINER=`root`@`localhost` */ /*!50003 TRIGGER `tr1` BEFORE INSERT ON `t1` FOR EACH ROW BEGIN
...@@ -2795,7 +2803,7 @@ SET new.a = 0; ...@@ -2795,7 +2803,7 @@ SET new.a = 0;
END */;; END */;;
DELIMITER ; DELIMITER ;
/*!50003 SET SESSION SQL_MODE=@OLD_SQL_MODE */; /*!50003 SET SESSION SQL_MODE=@SAVE_SQL_MODE*/;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
...@@ -3334,5 +3342,27 @@ SELECT * FROM v1; ...@@ -3334,5 +3342,27 @@ SELECT * FROM v1;
1 1
DROP VIEW v1; DROP VIEW v1;
# #
# Bug #29788: mysqldump discards the NO_AUTO_VALUE_ON_ZERO value of
# the SQL_MODE variable after the dumping of triggers.
#
CREATE TABLE t1 (c1 INT);
CREATE TRIGGER t1bd BEFORE DELETE ON t1 FOR EACH ROW BEGIN END;
CREATE TABLE t2 (c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY);
SET @TMP_SQL_MODE = @@SQL_MODE;
SET SQL_MODE = 'NO_AUTO_VALUE_ON_ZERO';
INSERT INTO t2 VALUES (0), (1), (2);
SET SQL_MODE = @TMP_SQL_MODE;
SELECT * FROM t2;
c1
0
1
2
SELECT * FROM t2;
c1
0
1
2
DROP TABLE t1,t2;
#
# End of 5.0 tests # End of 5.0 tests
# #
...@@ -1554,6 +1554,28 @@ DROP VIEW v1; ...@@ -1554,6 +1554,28 @@ DROP VIEW v1;
SELECT * FROM v1; SELECT * FROM v1;
DROP VIEW v1; DROP VIEW v1;
--echo #
--echo # Bug #29788: mysqldump discards the NO_AUTO_VALUE_ON_ZERO value of
--echo # the SQL_MODE variable after the dumping of triggers.
--echo #
CREATE TABLE t1 (c1 INT);
CREATE TRIGGER t1bd BEFORE DELETE ON t1 FOR EACH ROW BEGIN END;
CREATE TABLE t2 (c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY);
SET @TMP_SQL_MODE = @@SQL_MODE;
SET SQL_MODE = 'NO_AUTO_VALUE_ON_ZERO';
INSERT INTO t2 VALUES (0), (1), (2);
SET SQL_MODE = @TMP_SQL_MODE;
SELECT * FROM t2;
--exec $MYSQL_DUMP --routines test >$MYSQLTEST_VARDIR/tmp/bug29788.sql
--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/bug29788.sql
SELECT * FROM t2;
DROP TABLE t1,t2;
--echo # --echo #
--echo # End of 5.0 tests --echo # End of 5.0 tests
--echo # --echo #
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