MySQL EXIT HANDLER is not catching all the errors?
My MySQL procedure looks like:
create procedure create_feed (_id int)
begin
declare exit handler for sqlexception
begin
rollback;
开发者_运维技巧 select false;
end;
start transaction;
insert into t1(id)
values (_id);
insert into wrong_table_name (id, createdtime)
values (
_id,
CURRENT_TIMESTAMP
);
commit;
select true;
end//
After I called this procedure, the t1 table is updated, and the value 'true' is returned. The wrong_table_name does not exist at all. Why?
I recommend that you use a function instead of a procedure if you want it to return a value. Another option is to use out parameters if you want your procedure to return one or more values.
Nonetheless, I am surprised by your results. If wrong_table_name
does not exist, then that proc should return true. As for t1 being updated, that would happen if you are using a non-transactional storage engine like MyISAM, which ignores the rollback.
I tested your code in MySQL 5.5.8, and it worked properly for me. Namely, it always entered the exit handler when wrong_table_name
did not exist.
精彩评论