Consultor Eletrônico



Kbase 19136: Record Locking - How to know who has locked the record using VST?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   4/21/2008
Status: Verified

GOAL:

Record Locking - How to Know Who Has the Record Using VST?

GOAL:

How to find out who has a particular record locked through the use of Virtual System Tables (VST).

GOAL:

Which user is locking a record ?

GOAL:

How to know who has locked the record using VST?

FACT(s) (Environment):

OpenEdge 10.x
Progress 9.X
Progress 8.X

FIX:

To find out which locks exist for a given record, the RECID of the record should be obtained. This can be done by fetching the record with NO-LOCK and using the RECID() function.

With the RECID, the VST can be used to find out who has a particular record locked can be done by querying the tables _connect and _lock:

- _connect = Connection information
- _lock = Record Locking Table information

In Progress Versions 8.2 and 8.3:

VST must first be enabled by running the command, proutil -C enablevst. The following sample program uses the record key to get the RECID of the record and uses it to query the _lock table. Then it queries the _connect table to get the information about the device the user is connected to:

DEFINE VARIABLE wrecid AS INTEGER NO-UNDO.

/* Find the recid of the record */
FIND customer WHERE cust-num = 15 NO-LOCK.
ASSIGN wrecid = RECID(customer).

/* Use repeat loop - More efficient than FIND ... WHERE
due to lack of suitable index on _lock table */
REPEAT:
FIND NEXT _lock NO-LOCK NO-ERROR.

IF _lock-recid = wrecid AND
_lock-flag MATCHES "*X*"
/* typically we're interested in any form of exclusive lock
so we test for X lock flag */
THEN LEAVE.

IF _lock-recid = ? THEN DO:
RELEASE _lock.
LEAVE.
END.
END.

IF AVAILABLE(_lock) THEN DO:
DISPLAY _lock-usr _lock-name _lock-flag WITH FRAME A.
FIND FIRST _connect WHERE _connect-usr = _lock-usr NO-LOCK.
DISPLAY _connect-usr _connect-name _connect-device WITH FRAME b.
END.

In Progress Version 9.x and later:

VST is enabled by default. This program is very similar to that for Versions 8.2 and 8.3, but since the RECIDs in Version 9 are not unique in the database but only within a database area, the program must do additional filtering. Usually, filtering by table is the most useful; to do so the following example code uses the _file table:

DEFINE VARIABLE wrecid AS INTEGER NO-UNDO.
DEFINE VARIABLE wtable AS INTEGER NO-UNDO.

/* Find the recid of the record */
FIND customer WHERE cust-num = 15 NO-LOCK.
ASSIGN wrecid = RECID(customer).
FIND _file WHERE _file-name = "customer" NO-LOCK.
ASSIGN wtable = _file._file-num.

/* Use repeat loop - More efficient than FIND ... WHERE
due to lack of suitable index on _lock table */
REPEAT:
FIND NEXT _lock NO-LOCK NO-ERROR.

IF _lock-recid = wrecid AND
_lock-table = wtable AND
_lock-flag MATCHES "*X*"
/* typically we're interested in any form of exclusive lock
so we test for X lock flag */
THEN LEAVE.

IF _lock-recid = ? TH.EN DO:
RELEASE _lock.
LEAVE.
END.
END.

IF AVAILABLE(_lock) THEN DO:
DISPLAY _lock-usr _lock-name _lock-flag WITH FRAME A.
FIND FIRST _connect WHERE _connect-usr = _lock-usr NO-LOCK.
DISPLAY _connect-usr _connect-name _connect-device WITH FRAME b.
END..