table lock

vendor/rails/activerecord/lib/active_record/locking/pessimistic:     # Pass <tt>:lock => true</tt> to ActiveRecord::Base.find to obtain an exclusive     # lock on the selected rows:     # # select * from accounts where id=1 for update     # Account.find(1, :lock => true)

vendor/rails/activerecord/lib/active_record/locking/pessimistic: # Pass <tt>:lock => true</tt> to ActiveRecord::Base.find to obtain an exclusive

That's a row lock :slight_smile: If you want a table lock you need to run the appropriate sql statement for your database by hand.

Fred

That's a row lock :slight_smile: If you want a table lock you need to run the appropriate sql statement for your database by hand.

Fred

oh, i'm sorry. it seems i'm still a little bit sleepy and didn't read the question correctly. i thought you were looking for a row lock...

Frederick Cheung wrote:

Frederick Cheung wrote:

vendor/rails/activerecord/lib/active_record/locking/pessimistic: � � # Pass <tt>:lock => true</tt> to ActiveRecord::Base.find to
obtain an exclusive

That's a row lock :slight_smile: If you want a table lock you need to run the appropriate sql statement for your database by hand.

Fred

Please give me some examples to accomplish the table level lock.

That depends on your database. ActiveRecord::Base.connection.execute
allows you to execute arbitrary sql statements.

Fred

I have a two tables a and b . At first I am fetching one records from a.Then I have to use table lock to lock that table. Then I will do some operatins,Then I insert a record in b table.Then I will remove the lock.Untill such times other rails application should not read the data from a table.How to do this using ActiveRecord::Base class , Say Sql Query to do that.

Like i said before, depends on your database (and in general table locks are a bad idea and will hurt you as your number of users increases)

Fred

This is a MySQL page where it talks about table locking:

http://dev.mysql.com/doc/refman/5.0/en/lock-tables.html

Pepe