Raven
Raven

Reputation: 4903

Return error from query before finishing it

I have following mysql script:

start transaction;
set autocommit = 0;
call RollbackRemove(1, 10);
call RollbackRemove(2, 5000);
commit;

and a procedure:

create procedure RollbackRemove(a INT, b NUMERIC(8, 0))
begin
    declare ret bool;
    select Remove(a, b) into ret;
    if not ret then
        rollback;
    end if;
end //

It tries to remove certain amount from each item, and if one remove fails, the transaction is rollbacked (inside procedure). However, I have noticed that even after calling rollback the script continues execution but that is not desired. Also I would like to be able to report an error (this will be called from php). I have been searching for mechanism that would end script sooner, something like return in other languages, but haven't found anything. What should I use in such situation?

Upvotes: 1

Views: 67

Answers (1)

mgaido
mgaido

Reputation: 3055

Maybe you can use SIGNAL to raise an error.

Upvotes: 1

Related Questions