| 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 ; |