MySQL Forums
Forum List  »  Stored Procedures

Transactions in a function
Posted by: Karloz .
Date: October 21, 2006 11:46AM

Hello,

I am new in MySQL but I have worked with another DataBases.
I am trying to develop a function wich manages transactions.
In other words, if exists an SQLEXCEPTION, I want to do ROLLBACK and return '-1'. In other case, if the transaction is successful I want to return '01' and do COMMIT.

I writed the stored procedure, but when I try to add the transacctions I don't know who to validate it.

the code is as follows:

***********************************
delimiter //

CREATE function handlerdemo () returns char(2)
BEGIN
DECLARE valor char(2) DEFAULT '00';

BEGIN
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET valor = '-1';

SET AUTOCOMMIT=0;
START TRANSACTION;

INSERT INTO test.t VALUES (1);


IF(valor<>'-1',COMMIT;,ROLLBACK;); /* <---THIS IS THE PART THAT I DON'T */
/*KNOW HOW TO VALIDATE AND EXECUTE.*/

SET AUTOCOMMIT=1;

RETURN IF(valor<>'-1',valor1,'01');

END;
END;
//
******************************************

Somebody can help me?

Thanks

Sugoicarl

Options: ReplyQuote


Subject
Views
Written By
Posted
Transactions in a function
2674
October 21, 2006 11:46AM
1627
October 21, 2006 12:57PM
5652
October 21, 2006 10:06PM
2003
October 22, 2006 09:14AM
1693
October 30, 2006 10:57PM
1673
November 01, 2006 06:41AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.