How writes introduce automatic locks is explained here:
I'd highlight this paragraph:
help said:
In addition to record or table locking, you can also choose automatic or manual locking. Many Visual FoxPro commands automatically attempt to lock a record or a table before the command is executed. If the record or table is successfully locked, the command is executed and the lock is released.
The second sentence somewhat invalidates the first one, especially the "choice" you have. Indeed what an UPDATE does is what it does and you have no choice there.
So your question is good, whether single replaces can be less restrictive to the shared usage than one update-sql.
Well, see the table. REPLACE differs in what exactly you do, but single record replaces only lock single records, while UPDATE-SQL is listed as doing a table lock. In all simplicity that means during an UPDATE-SQL one client does, no other updates can be done, also not an that only need a single record lock.
But avoiding UPDATE does not make things less restrictive. A single UPDATE can be done faster than many replaces, as just like SQL-SELECT Rushmore optimization improves finding the records to update and then it's easy to visit them all.
Also, the table or record lock aspect that compares to FLOCK and RLOCK isn't everything. There is that concept of Windows file systems that means there can only be one file handle with write access. No matter how small or big your write operation is. And in that sense there also is no parallelism possible only using REPLACEs. Only one process ofone client can have a write access handle on a file. That compares to VFPs FOPEN(cFilename,nAttribute) with any nAttribute value other than 0 or 10, which can be shared as it's only reading.
So also VFPs shared mode always is interrupted to be temporary exclusive when you write, no matter what command or function you use for it.
And on top of that, once you use buffering, it won't affect you, whether VFPs runtime could get write access to the file, because you act on the buffer only. The only moment you act on the DBF (or remote backend) is with TABLEUPDDATE. Or, when using record buffering only, everytime you switch record you cause an implicit TABLEUPDATE() without actively calling the function.
With buffering you don't only control when you do the update operation that needs write access. And you can have bad luck too, but as I said before:
myself said:
have a defined point of failure and can react to it, while any problem you have without buffering happen anytime anywhere and only trigger the general ON ERROR handler
That's the big advantage of buffering. It's not a VIP ticket to write access. But by doing this when you decide and by getting a response to trying that's not a raised error, you have it easier in the end, also because you reduce the network traffic that's necessary for all the single upates that each first need to get the write handle, then the table or record locks or both, then write, then unlock, then close the write handle. All this is a lot of back-and-forth network communication aside of just the data transport.
Also, forget about locks, in my experience what weighs more is the need to get write access in the first place. TABLEUPDAT of all rows that are buffered only does this first step once and keeps this write handle for all it's operations, and it does INSERTS, UPDATES, and DELETEs, all of the changes, instead of you doing this all in single commands.
If you really want to be less invasive to all other user sessions by doing a SCAN loop with REPLACES in all records than an UPDATE, you should really experiment. I'd predict this only is less inhibitive when you really slow down your process and always give a chance to other clients to process events. It's surely not better to get write access, then locks, then write, then unlock and then revert to read access, if you do it in so close succession that the short moments between reverting to read access and getting write access for the next REPLACE don't really give other clients a chance to do any write operations.
Take into account that all these state changes need to propagate and often changes in status more likely lead to misinformation. You get very little net effect with a REPLACE for all the network operations that are needed by the runtime to communicate about requesting something, getting it confirmed in a response and then realizing it can go to the next phase.
Chriss