in reply to DBI and table locking

If I lock a table, and another program tries to access it, what happens? ... Does it just block until it becomes unlocked, or is it supposed to return a failure?

This very much depends on what sort of lock you take on a table. If you take a READ lock, then everything else will still be able to read the table also, but any updates to it will be stalled until you release your lock.

If you take a WRITE lock, however, then nothing can read or write the table(s) concerned until you release your lock.

All locked queries will just stall, waiting for the lock to release, rather than failing.

Tony

Replies are listed 'Best First'.
Re: Re: DBI and table locking
by mp3car-2001 (Scribe) on Jan 07, 2001 at 20:59 UTC
    Thanks a lot. This answers my question and I know that I can safely WRITE lock my table for a quick operation and I don't need to provide error handling for other programs that access this table. Many thanks.
      But if you are grabbing several locks be careful about what order you do it in. If programs X and Y grab locks on tables A and B respectively, and then try to lock B and A, they get into this pathetic staring contest called a deadlock. This is generally a Bad Thing...

        Obviously this is good advice in the general case, but it's slighly moot for the OP, who said he was on MySQL. It's impossible to get deadlock in MySQL as you have to declare all your locks at once .. declaring a new lock after that will free your current one.

        Tony