# Lock Table : Help me to write an alternative code in RoR

**URL:** <https://www.ruby-forum.com/t/lock-table-help-me-to-write-an-alternative-code-in-ror/168286>\
**Category:** Rails\
**Created:** [May 19, 2009, 7:51am UTC](https://www.ruby-forum.com/t/lock-table-help-me-to-write-an-alternative-code-in-ror/168286 "2009-05-19T07:51:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![venkat\_ruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/4af34b/32.png) [@venkat\_ruby](https://www.ruby-forum.com/u/venkat_ruby)\
**Post date:** [May 19, 2009, 7:51am UTC](https://www.ruby-forum.com/t/lock-table-help-me-to-write-an-alternative-code-in-ror/168286/1 "2009-05-19T07:51:07Z")

</div>

Please help me to write an alternative code for below in ROR…

ActiveRecord::Base.connection.execute(“LOCK TABLES table\_name WRITE”)  
ActiveRecord::Base.connection.execute(‘UNLOCK TABLES’)

Regards,

---

<div class="post-metadata">

**Author:** ![venkat\_ruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/4af34b/32.png) [@venkat\_ruby](https://www.ruby-forum.com/u/venkat_ruby)\
**Post date:** [May 19, 2009, 9:26am UTC](https://www.ruby-forum.com/t/lock-table-help-me-to-write-an-alternative-code-in-ror/168286/2 "2009-05-19T09:26:55Z")

</div>

On May 19, 6:51 am, Venkat E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Please help me to write an alternative code for below in ROR…

There’s nothing built into rails as far as table locks go, so there’s  
not much more that you can do than that (apart I suppose from wrapping  
things up nicely so that you can’t forget to unlock tables).

Fred

---

<div class="post-metadata">

**Author:** ![venkat\_ruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/4af34b/32.png) [@venkat\_ruby](https://www.ruby-forum.com/u/venkat_ruby)\
**Post date:** [May 19, 2009, 9:27am UTC](https://www.ruby-forum.com/t/lock-table-help-me-to-write-an-alternative-code-in-ror/168286/3 "2009-05-19T09:27:31Z")

</div>

On Mon, May 18, 2009 at 10:51 PM, Venkat E. \<  
removed\_email\_address@domain.invalid\> wrote:

> Please help me to write an alternative code for below in ROR…
> 
> ActiveRecord::Base.connection.execute(“LOCK TABLES table\_name WRITE”)  
> ActiveRecord::Base.connection.execute(‘UNLOCK TABLES’)

Venkat, what are you trying to do exactly? It seems that you’re trying  
to  
do the  
following:

a) lock the table  
b) do some db modifications  
c) unlock the table

If this is the case, I would recommend reading up on the transaction  
support  
within RoR. If this doesn’t do the job for you, you may consider  
wrapping  
these methods in before and after filters respectively at the controller  
or  
model level.

Good luck,

-Conrad
