php-psql lock problem - Mailing list pgsql-general

From Maurizio Ortolan
Subject php-psql lock problem
Date
Msg-id 5.1.0.14.2.20011014122242.00c91f48@mail.tin.it
Whole thread Raw
List pgsql-general
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          **
*******************************************


pgsql-general by date:

Previous
From: Emmanuel SARACCO
Date:
Subject: Re: retriving views name
Next
From: Robert Treat
Date:
Subject: Re: [Off-topic, Meta-question] Problems with psql-general list