Set Lock, Set("Lock"), Set Reprocess, Set("Reprocess")
SET LOCK determines whether a number of read-only commands automatically lock records in the table they're reporting on. SET REPROCESS determines the behavior that should occur when a lock cannot be placed.
Usage |
SET LOCK ON | OFF cLockOnOrOff = SET( "LOCK ") |
On the other hand, this command can really foul up a locking scheme. Setting LOCK ON means that these commands also release any pre-existing locks when they are run, as if UNLOCK ALL had been issued. See the first example below. If you really need this setting, we recommend that you wrap the individual needy commands in a SET/reSET pair to avoid problems with locking, as we show in the second example. |
Example |
SET MULTILOCKS ON SET LOCK ON ? RLOCK("2,4,6,8",ALIAS()) && Lock four records. LIST FOR SYS(2011) = "Record Locked" && Nothing! SET LOCK OFF ? RLOCK("2,4,6,8",ALIAS()) && Lock four records. LIST FOR SYS(2011) = "Record Locked" && Lists the four records. cSetLock = SET("LOCK") SET LOCK ON CALCULATE AVG(nAge), MAX(nAge) to nAvg, nEldest SET LOCK &cSetLock * Also see the combined example with SET REPROCESS below. |
Usage |
SET REPROCESS TO nAttempts | nTime SECONDS | AUTOMATIC [ SYSTEM ] nSetting = SET( "REPROCESS" ) |
Parameter |
Value |
Meaning |
nAttempts |
–2 |
This is the same as SET REPROCESS TO AUTOMATIC. When a command requiring a lock is issued, and the lock cannot be placed, the lock is retried forever (with the status bar prompt "Attempting to lock... Press ESC to cancel.") unless the user presses Escape to end the retries. If the user terminates the lock attempt and it came from a command that automatically places a lock, the ON ERROR handler receives the failed lock error. On the other hand, if a function such as LOCK() is placing the lock, the values .T. and .F. are returned to indicate the success of the operation, and the error handler is not called. |
–1 |
One of the easiest ways to get your user to turn the computer off. If a lock cannot be made, the message "Waiting for lock..." is displayed and there is nothing—nothing—the user can do. If the user with the lock on the file or record of interest is off on vacation this week, you might as well take this week off. The main FoxPro window cannot be minimized or closed. There has to be a better way—we can't think of a worse one. |
|
0 |
This one's a doozy, folks: If an ON ERROR command is in effect, no attempts at retrying are performed. If a lock cannot be made, .F. is returned if a function tried to place the lock. If a command attempted the lock, an error is generated. But, if there is no ON ERROR command in effect, both commands and functions behave just like AUTOMATIC locking. |
|
Positive integer |
The number of times to attempt to place the lock before giving up. |
|
nTime |
Positive integer |
The number of seconds during which to continuously retry the lock. |
nSetting |
Integer |
Returns the values set above, returning –2 for AUTOMATIC, and not distinguishing between settings of nAttempts and nTime. |
Example |
USE AGES lcOnError = ON("ERROR") lcSetLock = SET("LOCK") lnSetRepr = SET("REPROCESS") SET LOCK ON SET REPROCESS TO -2 ON ERROR DO lErrHand with ERROR(), MESSAGE() AVERAGE AGES TO nAges ON ERROR &lcOnError SET REPROCESS TO (lnSetRepr) SET LOCK &lcSetLock Procedure lErrHand(nErr, cMessage) IF nErr = 108 or nErr = 109 WAIT WINDOW "Some records were not available." + chr(13) + ; "Try again later. Press any key to continue..." RETURN ENDIF ENDPROC |
See Also |
Average, Calculate, Display, Error(), FLock(), IsFLocked(), IsRLocked(), Label, List, Lock(), On Error, Report, Return, Rlock(), Sum, SYS(2011), SYS(3051), SYS(3052), Total |