Versions Compared

Key

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

...

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.