[Commits] 5803178: MDEV-4829 BEFORE INSERT triggers dont issue 1406 error.

Alexey Botchkov holyfoot at askmonty.org
Mon Nov 16 22:43:29 EET 2015


revision-id: 580317835f9758a9536150e02031ff520e747089 (mariadb-10.1.8-54-g5803178)
parent(s): 0dfa0eef596ee677b55976793d632dc9b36928c7
committer: Alexey Botchkov
timestamp: 2015-11-17 00:42:18 +0400
message:

MDEV-4829 BEFORE INSERT triggers dont issue 1406 error.
  Turn the 'abort_on_warning' on for assigning value to fields.

---
 mysql-test/r/trigger.result | 15 +++++++++++++++
 mysql-test/t/trigger.test   | 22 ++++++++++++++++++++++
 sql/sp_head.cc              |  3 +++
 3 files changed, 40 insertions(+)

diff --git a/mysql-test/r/trigger.result b/mysql-test/r/trigger.result
index 9dfa589..c178081 100644
--- a/mysql-test/r/trigger.result
+++ b/mysql-test/r/trigger.result
@@ -2273,3 +2273,18 @@ SET optimizer_switch=@save_optimizer_switch;
 DROP TRIGGER tr;
 DROP TABLE t1, t2;
 End of 5.3 tests.
+SET @@session.sql_mode = 'STRICT_ALL_TABLES,STRICT_TRANS_TABLES';
+CREATE TABLE t1 (c CHAR(1) NOT NULL);
+CREATE TRIGGER t1_bi
+BEFORE INSERT
+ON t1
+FOR EACH ROW
+BEGIN
+SET NEW.c = 'www';
+END;
+|
+SET @@session.sql_mode = default;
+INSERT INTO t1 VALUES ('a');
+ERROR 22001: Data too long for column 'c' at row 1
+DROP TRIGGER t1_bi;
+DROP TABLE t1;
diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test
index 384dd6c..033a197 100644
--- a/mysql-test/t/trigger.test
+++ b/mysql-test/t/trigger.test
@@ -2613,3 +2613,25 @@ DROP TABLE t1, t2;
 
 --echo End of 5.3 tests.
 
+#
+# MDEV-4829 BEFORE INSERT triggers dont issue 1406 error
+#
+
+SET @@session.sql_mode = 'STRICT_ALL_TABLES,STRICT_TRANS_TABLES';
+CREATE TABLE t1 (c CHAR(1) NOT NULL);
+DELIMITER |;
+CREATE TRIGGER t1_bi
+  BEFORE INSERT
+  ON t1
+  FOR EACH ROW
+ BEGIN
+  SET NEW.c = 'www';
+ END;
+|
+DELIMITER ;|
+SET @@session.sql_mode = default;
+--error ER_DATA_TOO_LONG
+INSERT INTO t1 VALUES ('a');
+DROP TRIGGER t1_bi;
+DROP TABLE t1;
+
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index a117963..01e649b 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -3229,7 +3229,10 @@ sp_instr_set_trigger_field::execute(THD *thd, uint *nextp)
 int
 sp_instr_set_trigger_field::exec_core(THD *thd, uint *nextp)
 {
+  bool sav_abort_on_warning= thd->abort_on_warning;
+  thd->abort_on_warning= thd->is_strict_mode() && !thd->lex->ignore;
   const int res= (trigger_field->set_value(thd, &value) ? -1 : 0);
+  thd->abort_on_warning= sav_abort_on_warning;
   *nextp = m_ip+1;
   return res;
 }


More information about the commits mailing list