mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Save and clear run context before executing a stored function or trigger and restore it afterwards.
This allows us to use statement replication with functions and triggers The following things are fixed with this patch: - NOW() and automatic timestamps takes the value from the main event for functions and triggers (which allows these to replicate with statement level logging) - No side effects for triggers or functions with auto-increment values(), last_insert_id(), rand() or found_rows() - Triggers can't return result sets Fixes bugs: #12480: NOW() is not constant in a trigger #12481: Using NOW() in a stored function breaks statement based replication #12482: Triggers has side effects with auto_increment values #11587: trigger causes lost connection error mysql-test/r/trigger.result: Added test fpr big mysql-test/t/sp-error.test: Changed error message numbers mysql-test/t/trigger.test: Added test for trigger returning result (#11587) sql/item_func.cc: Store the first used seed value for RAND() value. (This makes rand() replicatable in functions and triggers) Save and clear run context before executing a stored function and restore it afterwards. This removes side effects of stored functions for RAND(), auto-increment values and NOW() and makes most stored function replicatable sql/share/errmsg.txt: Reuse error message also for triggers sql/sp_head.cc: If in function or trigger, don't change value of NOW() (This allows us to use statement replication with functions that directly or indirectly uses timestamps) sql/sql_class.cc: Added framework for storing and retrieving run context while exceuting triggers or stored functions. sql/sql_class.h: Added framework for storing and retrieving run context while exceuting triggers or stored functions. sql/sql_parse.cc: If in function or trigger, don't change value of NOW() (This allows us to use statement replication with functions that directly or indirectly uses timestamps) sql/sql_trigger.cc: Moved process_triggers function from sql_trigger.h Use reset/restore sub_statement_state while executing triggers to avoid side effects and make them replicatable sql/sql_trigger.h: Moved process_triggers function from sql_trigger.h Use reset/restore sub_statement_state while executing triggers to avoid side effects and make them replicatable sql/sql_yacc.yy: Give error message if trigger can return a result set (Bug #11587) tests/fork_big2.pl: Removed return from end of lines mysql-test/r/rpl_trigger.result: New BitKeeper file ``mysql-test/r/rpl_trigger.result'' mysql-test/t/rpl_trigger.test: New BitKeeper file ``mysql-test/t/rpl_trigger.test''
This commit is contained in:
@ -664,3 +664,36 @@ end|
|
||||
update t1 set data = 1;
|
||||
update t1 set data = 2;
|
||||
drop table t1;
|
||||
create table t1 (c1 int, c2 datetime);
|
||||
create trigger tr1 before insert on t1 for each row
|
||||
begin
|
||||
set new.c2= '2004-04-01';
|
||||
select 'hello';
|
||||
end|
|
||||
ERROR 0A000: Not allowed to return a result set from a trigger
|
||||
insert into t1 (c1) values (1),(2),(3);
|
||||
select * from t1;
|
||||
c1 c2
|
||||
1 NULL
|
||||
2 NULL
|
||||
3 NULL
|
||||
drop procedure if exists bug11587;
|
||||
create procedure bug11587(x char(16))
|
||||
begin
|
||||
select "hello";
|
||||
select "hello again";
|
||||
end|
|
||||
create trigger tr1 before insert on t1 for each row
|
||||
begin
|
||||
call bug11587();
|
||||
set new.c2= '2004-04-02';
|
||||
end|
|
||||
insert into t1 (c1) values (4),(5),(6);
|
||||
ERROR 0A000: PROCEDURE test.bug11587 can't return a result set in the given context
|
||||
select * from t1;
|
||||
c1 c2
|
||||
1 NULL
|
||||
2 NULL
|
||||
3 NULL
|
||||
drop procedure bug11587;
|
||||
drop table t1;
|
||||
|
Reference in New Issue
Block a user