On Sep 26, 2007, at 6:26 PM, Frederick Cheung wrote:

> Hmm. If the adaptor methods were private the ActiveRecord itself
> couldn't call them. In general, adaptor methods are sort of down
> their and grungy.
> If you don't use the adaptor methods then the nesting and so on just
> works
>

that is a good point.  maybe a doc issue?  we end up using the  
connection a fair bit since we're dealing with postgresql and some  
tricky sql and - obivously - that's what initially bit me.

it's still hard to say what this is good for:

   ActiveRecord::Base.connection.transaction &block

since very little will work in block.  ceratinly begin_db_transaction  
and end_db_transaction are required.  but of what value is  
transaction with a block on the connection object?

> well if you use break then you exit the block and the transaction is
> committed. that's not very nice though 'break' hardly sounds like it
> should mean commit.
>

exactly.  break != commit and raise != rollback semantically.

> I think it depends on how you view it: if the code inside the block
> raises exceptions to say 'help it's all screwed' then the current
> stuff is fine: it's not using exceptions to do control flow, it's
> using exceptions to deal with the fact that something horrible has
> happened.

oh right. there are two cases

  - something went wrong.  rollback.  this is fine now.

  - nothing went wrong in the code, but has logically, rollback with  
no errors or warnings.  that is not supported at all now and, imho,  
is a rather common scenario.

> I've tended to use transactions so that should some random thing go
> wrong then the database isn't inconsistent: the only case in which I
> rollback is if an exception is thrown. However if you are going to be
> saying commit! and rollback! as part of your actual logic then it
> makes perfect sense to make them proper things (sorry can't think of
> a better word)
>

yeah that's my point alright.  there just isn't satisfying hooks for  
it now.

>>
>> - transactions and savepoints need to be integrated.
>> sane_transactions.rb does this do in a way that connection adapters
>> can utilize, ignore, or extend.
> Coolio!

yeah it's handy - we're using it now.  i'm not the first one to patch  
this in either - there are some things on trac that do the same.

> Apart from  ActiveRecord::Base.connection.begin_db_transaction for
> some adapters (eg the mysql/postgres adapter implementation just
> calls execute 'BEGIN') (and of course execute 'BEGIN'). That's sort
> of adaptor dependant I suppose.

yeah - it's certainly sufficient though.  maybe that's where it  
belongs?  don't offer the user ruby ways to hose themselves - if they  
are writing sql they deserve it!  ;-)

cheers.

a @ http://drawohara.com/
--
we can deny everything, except that we have the possibility of being  
better. simply reflect on that.
h.h. the 14th dalai lama




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to