Progress
Programming
Handbook


Bypassing Progress Lock Protections

In some cases you might want to read a record even though another user holds an EXCLUSIVE–LOCK on that record. For example:

For cases such as these, Progress allows you bypass the normal locking mechanism and access a record with NO–LOCK. For example, p-lock6.p produces a simple customer report:

p-lock6.p
FOR EACH customer NO-LOCK: 
    DISPLAY cust-num name address city state postal-code. 
END. 

Because the FOR EACH statement in this example uses the NO–LOCK option, the procedure accesses every customer record without error even if another user holds an EXCLUSIVE–LOCK on one or more records.

For a browse widget, NO–LOCK is the default mode. If you want to update a record, then you must find that record again to apply a lock. For example, p-lock7.p browses records with NO–LOCK but allows you to select a record to update:

p-lock7.p
DEFINE BUTTON upd-cust LABEL "Update Customer".  
DEFINE BUTTON exit-app LABEL "Exit". 
DEFINE VARIABLE changes-made AS LOGICAL. 
DEFINE VARIABLE curr-cust AS ROWID. 
DEFINE QUERY seq-cust FOR customer. 
DEFINE BROWSE brow-cust QUERY seq-cust DISPLAY Cust-num Name WITH 5 DOWN. 
FORM 
   upd-cust exit-app SKIP(1) 
   brow-cust 
   WITH FRAME main-frame. 
OPEN QUERY seq-cust FOR EACH customer. 
ON VALUE-CHANGED OF brow-cust 
   DO: 
      curr-cust = ROWID(customer). 
   END. 
ON CHOOSE OF upd-cust 
   DO: /* TRANSACTION */ 
      FIND customer WHERE ROWID(customer) = curr-cust EXCLUSIVE-LOCK. 
      UPDATE customer WITH FRAME cust-frame VIEW-AS DIALOG-BOX 
         TITLE "Customer Update". 
      DISPLAY Cust-num Name WITH BROWSE brow-cust. 
      RELEASE customer. 
   END. 
ENABLE ALL WITH FRAME main-frame. 
PAUSE 0 BEFORE-HIDE. 
WAIT-FOR CHOOSE OF exit-app OR WINDOW-CLOSE OF DEFAULT-WINDOW. 

When you run this procedure and choose the upd–cust button, the trigger finds the current record again and applies an EXCLUSIVE–LOCK to it. You can then update the record.

NOTE: If you read a record with NO–LOCK before a transaction starts and then read the same record with EXCLUSIVE–LOCK within the transaction, the EXCLUSIVE–LOCK is automatically downgraded to a SHARE–LOCK when the transaction ends. Progress does not automatically return you to NO–LOCK status. If you do not want to hold a lock beyond the end of the transaction, you must execute a RELEASE statement on the record within the transaction.

In p-lock7.p, because a RELEASE statement is executed in the transaction, the record lock is released after the transaction completes.

Because NO–LOCK bypasses the normal Progress lock protection, there are risks in using NO–LOCK. For example, in p-lock7.p, the customer names you see in the browse widget might not be up-to-date. Another user might have updated one or more records since you retrieved them. You receive no warning that your data is no longer current. However, when you execute the FIND statement in the upd–cust trigger, you retrieve the up-to-date record.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095