Обсуждение: lock row in table

Поиск
Список
Период
Сортировка

lock row in table

От
Daniel Michał
Дата:
Hallo everybody,
I have a problem that I can not to solve in a simple way.
 
SOME INFORMATION:
I have a postgresql database version 7.2.2 on Linux platform. I communicate with Postgresql from a Delphi application using microolap drivers and  everything works fine.
 
PROBLEM DESCRIPTION:
I have to lock one row in table1 for user1. In the same time other users should be able to read this record but when other user for example user2 want to edit this record  user2 should get information "The row you try to edit is currently edit" - or sometihing similar.
 
Of course I can lock record with syntax "Begin; select * from table1 where ID=12 for update; update table1 set field1="New value" where ID=12; commit;"
but I can not to inform other user that the record is edited?
 
MAIN TARGET:
How to get information that current record is edited? Which function can I use?
 
Please help me, Maybe someone have similar problem?
Greetings,
Daniel
 

Re: lock row in table

От
"Yudha Setiawan"
Дата:
 
Of course I can lock record with syntax
"Begin;
        select * from table1 where ID=12 for update; 
        update table1 set field1="New value" where ID=12; 
commit;"
but I can not to inform other user that the record is edited?
 
MAIN TARGET:
How to get information that current record is edited? Which function can I use?
 
* as long as i know, the only message you could create is just
raise notice 'ur_message'; or raise exception 'ur_error_message';
* and the only message that delphi could read is just raise exception.
 
* And if you wanna make your own message, perhaps you must using try and except
* and you could give your own message via ShowMessage('ur_message') or other
* Class object on delphi.
 
 
Please help me, Maybe someone have similar problem?
Greetings,
Daniel
 
Hope it Help, GOD Bless You and Bravo PostgreSQL.

Re: lock row in table

От
"Daniel"
Дата:
Hi,
No, I am sure that I can get this message from Delphi. Check it on web site www.microolap.com
For example when I try to put  a non-unique value in a primary key I get message from database that I get conflict with
primarykey :-) 
of course I use raise ... except ... but everything work perfectly...  error handling works correctly :-)

so I am waiting for an answer for my question how check that the rekord is currently edited,
Greetings,
Daniel

>
>
>*********** REPLY SEPARATOR ***********
>
>On 2003-08-28 at 17:42 Yudha Setiawan wrote:
>
>Of course I can lock record with syntax
>"Begin;
>        select * from table1 where ID=12 for update;
>        update table1 set field1="New value" where ID=12;
>commit;"
>but I can not to inform other user that the record is edited?
>
>MAIN TARGET:
>How to get information that current record is edited? Which function can I
>use?
>
>* as long as i know, the only message you could create is just
>* raise notice 'ur_message'; or raise exception 'ur_error_message';
>* and the only message that delphi could read is just raise exception.
>
>* And if you wanna make your own message, perhaps you must using try and
>except
>* and you could give your own message via ShowMessage('ur_message') or
>other
>* Class object on delphi.
>
>
>Please help me, Maybe someone have similar problem?
>Greetings,
>Daniel
>
>Hope it Help, GOD Bless You and Bravo PostgreSQL.



Re: lock row in table

От
Tom Lane
Дата:
Daniel Michał <danielosch@o2.pl> writes:
> I have to lock one row in table1 for user1. In the same time other users sh=
> ould be able to read this record but when other user for example user2 want=
>  to edit this record  user2 should get information "The row you try to edit=
>  is currently edit" - or sometihing similar.

> Of course I can lock record with syntax "Begin; select * from table1 where =
> ID=3D12 for update; update table1 set field1=3D"New value" where ID=3D12; c=
> ommit;"
> but I can not to inform other user that the record is edited?

Try using the contrib/userlock/ functions.
        regards, tom lane