MySQL Forums
Forum List  »  Stored Procedures

Re: how to rollback stored-rountings
Posted by: Roland Bouman
Date: January 11, 2006 04:25AM

What is the problem exactly?

I mean, If I have a table like this:

CREATE TABLE `bla` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(64) NOT NULL,
`dummy` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1


and a procedure like this:

delimiter go

create procedure p_bla()
begin
set autocommit = 0;
insert into bla (name) values ('Roland');
commit;
insert into bla (name) values ('Bouman');
rollback;
end;
go

a call to that procedure:

call p_bla()
go

works exactly as expected on my 5.0.17-nt; that is, the first row is commited, and the second one is rolled back.

Or am I missing something here?

I think the restriction does hold for triggers (which should not be a problem)

BTW, what do you want to achieve here?

I think there should be a very compelling reason to want a commit or a rollback inside a procedure. In my opinion, it's better to let the caller decide wheter to commit or rollback; just as it is the case for 'normal' DML statements, like INSERT, DELETE etc.

By hardwiring the COMMIT/ROLLBACK inside the proc, the caller should be aware on beforehand that he's potentially rolling back all the other work in the session too. Things are even worse when the procedure can throw an exception - did the rollback occur already, or did it not, because of the exception.

So, I am very curious why you want to rollback inside the proc. Please let me know, Im interested.

Roland



Edited 1 time(s). Last edit at 01/11/2006 04:33AM by Roland Bouman.

Options: ReplyQuote


Subject
Views
Written By
Posted
2256
January 08, 2006 09:47PM
1439
January 10, 2006 05:36AM
1426
January 10, 2006 06:40PM
1417
January 11, 2006 12:01AM
1548
January 11, 2006 09:18PM
1520
January 11, 2006 09:27PM
1535
January 12, 2006 03:20AM
Re: how to rollback stored-rountings
1545
January 11, 2006 04:25AM


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.