Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

If you need to read rows before finding the one to modify, don't lock until you find the row you want, but read again after you lock it.

See also

UnLockOpenSelect...By

Remarks

Lock alerts the network system that the program wishes to establish a lock on a table or row. If the program attempts to set a lock that has been previously set by another user, the current program will execute the Else statements.

...

Code Block
/* The following function fragment locks a row, then reads it, does some unspecified processing, and then unlocks the row, before concluding. */
Equate TRUE$ To 1
Equate FALSE$ To 0
table = "SAMPLE_CUSTOMERS"
key = 8
status = ""
Open table To tablevar Then
  locked = FALSE$
  Loop
    Lock tablevar,key Then
      locked = TRUE$
    End Else 
      /* set up delay for network server access */
      For ctr = 1 To 1000
      Next
    End
  Until Locked Repeat
  * we're locked, now read
  Read @RECORD From tablevar,key Then
    /* do row processing here */
  End
  * now, unlock the row we've written back
  UnLock tablevar,key Else
    Status = Set_FSError()
    /* A row should always unlock first time out. */
  End
End Else  ;* table fails to open
  status = Set_FSError()
End  ;* table taken care of
Return status

 

 

Note: Locking a table or row is not a guarantee that it will not be changed by another user. All programs must contain Lock logic to ensure that tables or rows are not simultaneously updated.