Forum: Ruby on Rails if one has a nested transaction does the outer-most transaction take precedence?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Greg H. (Guest)
on 2009-02-05 13:48
(Received via mailing list)
Hi,

Anyone know, if I have a nested transaction, will it be the outer most
transaction (i.e. from outermost transaction start, to outermost
transaction end) that will be used?

i.e. noting Rails doesn't currently support nested transactions.
Another way to ask would be to say, if there was a database statement
error between the end of the innermost transaction and the end of the
outmost transaction, would the innermost transaction database
statements be rolled back?

--
Greg
http://blog.gregnet.org/
Frederick C. (Guest)
on 2009-02-05 14:52
(Received via mailing list)
On 5 Feb 2009, at 11:47, Greg H. wrote:

> outmost transaction, would the innermost transaction database
> statements be rolled back?

THis is probably database dependant but on mysql at least a nested
begin will commit the existing transaction and begin a new one (which
is why rails is careful not to start a new actual transaction in this
case). rails 2.3 supports savepoints for what it's worth.

Fred
Greg H. (Guest)
on 2009-02-05 22:04
(Received via mailing list)
thanks - so this means for the moment at least (until v2.3) one has to
be careful re having a method with a transaction begin, that within
may call another method that itself has a transaction begin.  So
really group your methods into ones that use & don't use transactions
explicitly I guess...

2009/2/5 Frederick C. <removed_email_address@domain.invalid>:
>>
>
> >
>



--
Greg
http://blog.gregnet.org/
Frederick C. (Guest)
on 2009-02-06 00:43
(Received via mailing list)
On 5 Feb 2009, at 20:03, Greg H. wrote:

>
> thanks - so this means for the moment at least (until v2.3) one has to
> be careful re having a method with a transaction begin, that within
> may call another method that itself has a transaction begin.  So
> really group your methods into ones that use & don't use transactions
> explicitly I guess...
>
You're ok if you're not doing things by hand: if you do

Foo.transaction do
   Foo.transaction do
     ...
   end
end

then the inner call to transaction is basically a no-op.

Fred
Greg H. (Guest)
on 2009-02-06 02:26
(Received via mailing list)
ok  - so just to be clear then, statement A will rollback if there is
an issue with the statement B?  this is at least good then for me

Foo.transaction do
  Foo.transaction do
     statement A
    ...
  end
  statement B
end


2009/2/6 Frederick C. <removed_email_address@domain.invalid>:
>>
> Fred
>>>> Anyone know, if I have a nested transaction, will it be the outer
>>>> statements be rolled back?
>>>> Greg
>> --
>> Greg
>> http://blog.gregnet.org/
>>
>> >
>
>
> >
>



--
Greg
http://blog.gregnet.org/
Frederick C. (Guest)
on 2009-02-06 03:24
(Received via mailing list)
On 6 Feb 2009, at 00:25, Greg H. wrote:

> end
>

Correct. The above is equivalent to

Foo.transaction do
  statement A
  statement B
end

(Again assuming you're not using 2.3's savepoint support (which is
turned off by default I believe))

Fred
This topic is locked and can not be replied to.