Go Back   Forum Care Forums > Development Reference Area > MySQL Discussion

Reply
 
LinkBack Thread Tools Display Modes
newbie: mysql error handling & transactions etc
Old
  (#1)
Jeff
Guest
 
Posts: n/a
Default newbie: mysql error handling & transactions etc - 06-04-2007, 07:50 AM

Hey

I've created my first stored procedure in a MySql5 database, see my stored
procedure below

I wonder if I'm using the error handler and transaction correctly?

I know this code below doesn't generate any error when running it (adding
the SP to the db), but that doesn't mean it's okay.

If for example an error occur inside the transaction block in my SP, will
then the exit handler be executed?

Appreciate your comments on my SP....

delimiter //

CREATE PROCEDURE SaveProperty ( INOUT id int unsigned, field1 int, field2
int)
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
END;
START TRANSACTION;
IF (id IS NULL) THEN
INSERT INTO Property (Field1, Field2) VALUES (field1, field2);
ELSE
UPDATE Property Set Field1 = field1, Field2 = field2 WHERE Id = id;
END IF;
COMMIT;
END;
//
delimiter ;


   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Contact Us - Forum Care Forums - Archive - Top