[Progress Communities] [Progress OpenEdge ABL] Forum Post: RE: Table locking?

  • Thread starter Thread starter ChUIMonster
  • Start date Start date
Status
Not open for further replies.
C

ChUIMonster

Guest
You appear to be attempting a pessimistic locking strategy. Furthermore you are attempting to use a SHARE-LOCK and never actually EXCLUSIVE-LOCK the record. This is never going to work. You should do something more like this: DO: define buffer upd_invTarjeta for invTarjeta. DEFINE VARIABLE rFila AS ROWID NO-UNDO. IF VALID-EVENT(FOCUS, "VALUE-CHANGED") THEN DO: ASSIGN Barra. /* what is this? */ FIND InvTarjeta WHERE invtarjeta.periodo = giperiodo AND invtarjeta.perinv = giperinv AND InvTarjeta.NroTarj = Barra NO-LOCK NO-ERROR. IF AVAILABLE invtarjeta THEN DO for upd_invTarjeta transaction: find upd_invTarjeta exclsuive-lock where recid( upd_invTarjet ) = recid (invTarjeta ) no-wait no-error. if not available ( upd_invTarjeta ) then do: message "invTarjeta is locked...". /* or however you want to handle that problem... */ return no-apply. end. ASSIGN upd_InvTarjeta .FlgBarrido = YES upd_InvTarjeta .InvPeso = InvTarjeta.SdoNeto upd_InvTarjeta .InvNroMet = InvTarjeta.NroMet. rFila = ROWID(InvTarjeta). FIND CURRENT invtarjeta NO-LOCK NO-ERROR. qhInvTarjeta:REPOSITION-TO-ROWID(rFila). END. ELSE DO: /* Other stuff */ END. /* FIND CURRENT InvTarjeta NO-LOCK NO-ERROR. */ Barra:SCREEN-VALUE = "". APPLY "ENTRY" TO Barra. RETURN NO-APPLY. END. Please excuse the terrible formatting -- "Communities" is not made for sharing code. The key points are: 1) First try to find the record NO-LOCK. 2) If it exists attempt to gain an EXCLUSIVE-LOCK on the upd_* buffer for that record. 2a) all references to the upd_* buffer are STRONG SCOPED to the transaction block (the "DO FOR upd_* TRANSACTION" part of things. This is critical. 2b) if the compiler complains that there is already a transaction active then you need to show more code and you have a bigger problem than you think you do. 2c) if the compiler complains that you cannot strong scope the upd_* buffer then you have a typo. 3) Testing for success of the exclusive-lock and handling failure as a contingency is the "optimistic" part of things. You are assuming that you will usually get the lock.

Continue reading...
 
Status
Not open for further replies.
Back
Top