If one has a nested transaction does the outer-most transaction take precedence?


#1

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/


#2

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


#3

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/


#4

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


#5

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


#6

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/