Reputation: 21
I have a simple update that will use a transaction. If the transaction fails, I want to rollback and send out an integer value of 0. Here is my code so far. It isn't working and all I get back is integer 1 even when it fails.
declare exit handler for not found rollback;
declare exit handler for sqlwarning rollback;
declare exit handler for sqlexception rollback;
set row = 0;
START TRANSACTION;
UPDATE user
SET name = name
WHERE code = code;
COMMIT;
set row = 1;
Does anyone have any ideas how I can fix this? Really, I'm open here. If someone has a better approach, I'm all ears.
Upvotes: 2
Views: 3147
Reputation: 822
You can enclose the commands with BEGIN and END:
DECLARE EXIT HANDLER FOR SQLEXCEPTION,NOT FOUND,SQLWARNING
BEGIN
ROLLBACK;
SELECT 0;
END;
Upvotes: 3