# Database applications and OOness

**URL:** <https://rubytalk.org/t/database-applications-and-ooness/9606>\
**Category:** ruby-talk\
**Created:** [8 January 2004 16:33 UTC](https://rubytalk.org/t/database-applications-and-ooness/9606 "2004-01-08T16:33:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Weirich\_James](https://avatars.discourse-cdn.com/v4/letter/w/3bc359/32.png) [@Weirich\_James](https://rubytalk.org/u/Weirich_James)\
**Post date:** [8 January 2004 16:33 UTC](https://rubytalk.org/t/database-applications-and-ooness/9606/1 "2004-01-08T16:33:36Z")

</div>

> 1. Regarding transactions: I haven’t done this, but I don’t imagine it  
> would be difficult. A Ruby-like style for it might be something like:
> 
> objectStore.runTransaction {  
> account1743.balance -= 100  
> account1743.commit  
> account329.balance += 100  
> account329.commit  
> }

DBI supports this. Given a database handle db, you can do …

db.transaction do  
db.do(“UPDATE accounts SET balance = balance - 100 WHERE accnum = 1743”)  
db.do(“UPDATE accounts SET balance = balance + 100 WHERE accnum = 329”)  
end

Make sure that auto-commit mode is OFF before using the transaction method.

> **···**
>
> –  
> – Jim Weirich / Compuware  
> – FWP Capture Services  
> – Phone: 859-386-8855
