开发者

MySQL EXIT HANDLER is not catching all the errors?

开发者 https://www.devze.com 2023-03-06 16:52 出处:网络
My MySQL procedure looks like: create procedure create_feed (_id int) begin declare exit handler for sqlexception

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号