Thread: php-psql lock problem

php-psql lock problem

From
Maurizio Ortolan
Date:
Hello to everybody!

I've a little problem with LOCK-ing a
certain row in a table using PHP and
PostgreSQL on LINUX.

 >> In a few words, I'd like to undertand
 >> how find out if a certain row is locked,
 >> in order to prevent a kind of deadlock.

Which is the (system) table where all
locked row or tables are 'saved' ?
Is there any flag?

// ############################
Example 1:

User A:

BEGIN WORK;
select login from people where userid='1' for update;
[ ... ]
COMMIT WORK;

User B:
BEGIN WORK;
(***)
select login from people where userid='1' for update;

[ WAIT UNTIL 'COMMIT WORK' of user A  !  :(  ]

COMMIT WORK;

Solution:
I'd like to put in (***) a quick check in order to
know if the row with userid='1' is already locked or not.

In this way, if it's already locked, I'll use
    select login from people where userid='1';
      [ ONLY READ ]
instead of
    select login from people where userid='1' for update;
      [READ & WRITE]

// ############################
Example 2:

BEGIN WORK;
LOCK TABLE utenti IN SHARE ROW EXCLUSIVE MODE;
select login from people where userid='1';
COMMIT WORK;

// ############################


Many thanks to everybody!
Ciao!
MaURIZIO

crix98@____tin.it


It's sure that
  a small example in PHP will very very appreciated!! :))


PS: it's possible to setup a timeout for a locked table,
     in order to exec an aoutomatic ROLLBACK ??
     (for examples if the user goes away?

*******************************************
**  Happy surfing on THE NET !!      **
**           Ciao by                           **
**                       C R I X 98          **
*******************************************