mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Bug#6951: Triggers/Traditional: SET @ result wrong
While executing a trigger, we have to set thd->abort_on_warning to the value it had at trigger creation time. mysql-test/r/trigger.result: Add result for bug#6951. mysql-test/t/trigger.test: Add test case for bug#6951. sql/sp_head.cc: While executing a trigger, set thd->abort_on_warning to the value it had at trigger creation time.
This commit is contained in:
@ -965,3 +965,39 @@ SELECT * FROM t1 WHERE conn_id != trigger_conn_id;
|
|||||||
conn_id trigger_conn_id
|
conn_id trigger_conn_id
|
||||||
DROP TRIGGER t1_bi;
|
DROP TRIGGER t1_bi;
|
||||||
DROP TABLE t1;
|
DROP TABLE t1;
|
||||||
|
DROP TABLE IF EXISTS t1;
|
||||||
|
CREATE TABLE t1 (i1 INT);
|
||||||
|
SET @save_sql_mode=@@sql_mode;
|
||||||
|
SET SQL_MODE='';
|
||||||
|
CREATE TRIGGER t1_ai AFTER INSERT ON t1 FOR EACH ROW
|
||||||
|
SET @x = 5/0;
|
||||||
|
SET SQL_MODE='traditional';
|
||||||
|
CREATE TRIGGER t1_au AFTER UPDATE ON t1 FOR EACH ROW
|
||||||
|
SET @x = 5/0;
|
||||||
|
SET @x=1;
|
||||||
|
INSERT INTO t1 VALUES (@x);
|
||||||
|
SELECT @x;
|
||||||
|
@x
|
||||||
|
NULL
|
||||||
|
SET @x=2;
|
||||||
|
UPDATE t1 SET i1 = @x;
|
||||||
|
ERROR 22012: Division by 0
|
||||||
|
SELECT @x;
|
||||||
|
@x
|
||||||
|
2
|
||||||
|
SET SQL_MODE='';
|
||||||
|
SET @x=3;
|
||||||
|
INSERT INTO t1 VALUES (@x);
|
||||||
|
SELECT @x;
|
||||||
|
@x
|
||||||
|
NULL
|
||||||
|
SET @x=4;
|
||||||
|
UPDATE t1 SET i1 = @x;
|
||||||
|
ERROR 22012: Division by 0
|
||||||
|
SELECT @x;
|
||||||
|
@x
|
||||||
|
4
|
||||||
|
SET @@sql_mode=@save_sql_mode;
|
||||||
|
DROP TRIGGER t1_ai;
|
||||||
|
DROP TRIGGER t1_au;
|
||||||
|
DROP TABLE t1;
|
||||||
|
@ -1141,4 +1141,52 @@ SELECT * FROM t1 WHERE conn_id != trigger_conn_id;
|
|||||||
DROP TRIGGER t1_bi;
|
DROP TRIGGER t1_bi;
|
||||||
DROP TABLE t1;
|
DROP TABLE t1;
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Bug#6951: Triggers/Traditional: SET @ result wrong
|
||||||
|
#
|
||||||
|
--disable_warnings
|
||||||
|
DROP TABLE IF EXISTS t1;
|
||||||
|
--enable_warnings
|
||||||
|
|
||||||
|
CREATE TABLE t1 (i1 INT);
|
||||||
|
|
||||||
|
SET @save_sql_mode=@@sql_mode;
|
||||||
|
|
||||||
|
SET SQL_MODE='';
|
||||||
|
|
||||||
|
CREATE TRIGGER t1_ai AFTER INSERT ON t1 FOR EACH ROW
|
||||||
|
SET @x = 5/0;
|
||||||
|
|
||||||
|
SET SQL_MODE='traditional';
|
||||||
|
|
||||||
|
CREATE TRIGGER t1_au AFTER UPDATE ON t1 FOR EACH ROW
|
||||||
|
SET @x = 5/0;
|
||||||
|
|
||||||
|
SET @x=1;
|
||||||
|
INSERT INTO t1 VALUES (@x);
|
||||||
|
SELECT @x;
|
||||||
|
|
||||||
|
SET @x=2;
|
||||||
|
--error 1365
|
||||||
|
UPDATE t1 SET i1 = @x;
|
||||||
|
SELECT @x;
|
||||||
|
|
||||||
|
SET SQL_MODE='';
|
||||||
|
|
||||||
|
SET @x=3;
|
||||||
|
INSERT INTO t1 VALUES (@x);
|
||||||
|
SELECT @x;
|
||||||
|
|
||||||
|
SET @x=4;
|
||||||
|
--error 1365
|
||||||
|
UPDATE t1 SET i1 = @x;
|
||||||
|
SELECT @x;
|
||||||
|
|
||||||
|
SET @@sql_mode=@save_sql_mode;
|
||||||
|
|
||||||
|
DROP TRIGGER t1_ai;
|
||||||
|
DROP TRIGGER t1_au;
|
||||||
|
DROP TABLE t1;
|
||||||
|
|
||||||
# End of 5.0 tests
|
# End of 5.0 tests
|
||||||
|
@ -935,6 +935,7 @@ sp_head::execute(THD *thd)
|
|||||||
bool err_status= FALSE;
|
bool err_status= FALSE;
|
||||||
uint ip= 0;
|
uint ip= 0;
|
||||||
ulong save_sql_mode;
|
ulong save_sql_mode;
|
||||||
|
bool save_abort_on_warning;
|
||||||
Query_arena *old_arena;
|
Query_arena *old_arena;
|
||||||
/* per-instruction arena */
|
/* per-instruction arena */
|
||||||
MEM_ROOT execute_mem_root;
|
MEM_ROOT execute_mem_root;
|
||||||
@ -995,6 +996,10 @@ sp_head::execute(THD *thd)
|
|||||||
thd->derived_tables= 0;
|
thd->derived_tables= 0;
|
||||||
save_sql_mode= thd->variables.sql_mode;
|
save_sql_mode= thd->variables.sql_mode;
|
||||||
thd->variables.sql_mode= m_sql_mode;
|
thd->variables.sql_mode= m_sql_mode;
|
||||||
|
save_abort_on_warning= thd->abort_on_warning;
|
||||||
|
thd->abort_on_warning=
|
||||||
|
(m_sql_mode & (MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
It is also more efficient to save/restore current thd->lex once when
|
It is also more efficient to save/restore current thd->lex once when
|
||||||
do it in each instruction
|
do it in each instruction
|
||||||
@ -1127,6 +1132,7 @@ sp_head::execute(THD *thd)
|
|||||||
DBUG_ASSERT(!thd->derived_tables);
|
DBUG_ASSERT(!thd->derived_tables);
|
||||||
thd->derived_tables= old_derived_tables;
|
thd->derived_tables= old_derived_tables;
|
||||||
thd->variables.sql_mode= save_sql_mode;
|
thd->variables.sql_mode= save_sql_mode;
|
||||||
|
thd->abort_on_warning= save_abort_on_warning;
|
||||||
|
|
||||||
thd->stmt_arena= old_arena;
|
thd->stmt_arena= old_arena;
|
||||||
state= EXECUTED;
|
state= EXECUTED;
|
||||||
|
Reference in New Issue
Block a user