Hi all, I have a doubt in transactions. Please see the code below. begin Project.transaction do p = Project.new p.name = "test" p.user_id = 10 p.save! if nil.projects puts "User is having projects" end end rescue Exception => e puts e.to_s end In the above case definitely it will fail at "nil.projects" and throws an exception. But the project is being saved and is not rolled back and when I see the log it''s showing rolled back and inthe DB the row is not getting deleted. I dont want the row to be created in the DB if there is any error even after the save. So what should be done?? The below is the log: SQL (0.001000) INSERT INTO projects (''name'', ''user_id'') VALUES(''test'', 10) app/models/project.rb:305:in `confirm_project'' app/models/project.rb:288:in `confirm_project'' app/models/project.rb:274:in `confirm_project'' app/controllers/test_controller.rb:19:in `confirm_project'' app/controllers/test_controller.rb:12:in `select_user'' SQL (0.000000) ROLLBACK What is the problem in the above code? Do I need to handle it in another way ?? Please reply me regarding this error. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 22 Sep 2008, at 14:19, Naga harish Kanegolla wrote:> > I dont want the row to be created in the DB if there is any error even > after the save. So what should be done?? > The below is the log: > SQL (0.001000) INSERT INTO projects (''name'', ''user_id'') > VALUES(''test'', 10) > app/models/project.rb:305:in `confirm_project'' > app/models/project.rb:288:in `confirm_project'' > app/models/project.rb:274:in `confirm_project'' > app/controllers/test_controller.rb:19:in `confirm_project'' > app/controllers/test_controller.rb:12:in `select_user'' > SQL (0.000000) ROLLBACK >That''s normal. Were you expecting to see DELETE FROM projects ... ? Fred> What is the problem in the above code? Do I need to handle it in > another > way ?? > Please reply me regarding this error. > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Fred, Yes I am expecting to see DELETE FROM projects.. Is it not possible in the transaction block?? Frederick Cheung wrote:> On 22 Sep 2008, at 14:19, Naga harish Kanegolla wrote: >> app/controllers/test_controller.rb:12:in `select_user'' >> SQL (0.000000) ROLLBACK >> > That''s normal. Were you expecting to see DELETE FROM projects ... ? > > Fred-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 22 Sep 2008, at 14:43, Naga harish Kanegolla wrote:> > Hi Fred, > Yes I am expecting to see DELETE FROM projects.. > Is it not possible in the transaction block??That''s just not how transactions work. The ROLLBACK statement does the work of unwinding all the changes since the previous BEGIN. Fred> > > Frederick Cheung wrote: >> On 22 Sep 2008, at 14:19, Naga harish Kanegolla wrote: >>> app/controllers/test_controller.rb:12:in `select_user'' >>> SQL (0.000000) ROLLBACK >>> >> That''s normal. Were you expecting to see DELETE FROM projects ... ? >> >> Fred > > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sep 22, 9:53 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> That''s just not how transactions work. The ROLLBACK statement does the > work of unwinding all the changes since the previous BEGIN.I''m a little out of date here. Does MySQL support nested transactions, and if it does, does AR support it? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 22 Sep 2008, at 15:00, Erol Fornoles wrote:> > On Sep 22, 9:53 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> That''s just not how transactions work. The ROLLBACK statement does >> the >> work of unwinding all the changes since the previous BEGIN. > > I''m a little out of date here. Does MySQL support nested transactions, > and if it does, does AR support it?Mysql 5 has savepoints. AR doesn''t do anything with them. Fred> > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
But a roll back should come to the previous state. so in this case how i can get back to the previous state with out inserting into DB.. What should I do?? Frederick Cheung wrote:> On 22 Sep 2008, at 14:43, Naga harish Kanegolla wrote: > >> >> Hi Fred, >> Yes I am expecting to see DELETE FROM projects.. >> Is it not possible in the transaction block?? > > That''s just not how transactions work. The ROLLBACK statement does the > work of unwinding all the changes since the previous BEGIN. > > Fred-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 22 Sep 2008, at 15:11, Naga harish Kanegolla wrote:> > But a roll back should come to the previous state. so in this case > how i > can get back to the previous state with out inserting into DB.. > What should I do??The ROLLBACK statement magically unwinds all changes made. The database (ie not your app or activerecord) takes care of that.> > > Frederick Cheung wrote: >> On 22 Sep 2008, at 14:43, Naga harish Kanegolla wrote: >> >>> >>> Hi Fred, >>> Yes I am expecting to see DELETE FROM projects.. >>> Is it not possible in the transaction block?? >> >> That''s just not how transactions work. The ROLLBACK statement does >> the >> work of unwinding all the changes since the previous BEGIN. >> >> Fred > > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, Thanks a lot. Now its working fine. Right now my table type is MyISAM and I changed the type into InnoDB Storage. In this type the transactions are safe. Now all the transactions are getting rolled back. Frederick Cheung wrote:> On 22 Sep 2008, at 15:11, Naga harish Kanegolla wrote: > >> >> But a roll back should come to the previous state. so in this case >> how i >> can get back to the previous state with out inserting into DB.. >> What should I do?? > > The ROLLBACK statement magically unwinds all changes made. The > database (ie not your app or activerecord) takes care of that.-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 23 Sep 2008, at 05:52, Naga harish Kanegolla <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org > wrote:> > Hi, > Thanks a lot. Now its working fine. Right now my table type is MyISAM > and I changed the type into InnoDB Storage. In this type the > transactions are safe. > Now all the transactions are getting rolled back.Ah yes. As you have found out, myisam doesn''t do transactions at all Fred> > > Frederick Cheung wrote: >> On 22 Sep 2008, at 15:11, Naga harish Kanegolla wrote: >> >>> >>> But a roll back should come to the previous state. so in this case >>> how i >>> can get back to the previous state with out inserting into DB.. >>> What should I do?? >> >> The ROLLBACK statement magically unwinds all changes made. The >> database (ie not your app or activerecord) takes care of that. > > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---