Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1141
  • Last Modified:

Foxpro for DOS 2.6 record locking

I have been asked about record and file locking in Foxpro for DOS 2.6. What would be the best way to approach record locking for record writes/updates? What about file locking?
0
Idarac
Asked:
Idarac
1 Solution
 
Olaf DoschkeSoftware DeveloperCommented:
It's like asking what is the best way to use a kitchen.

The topic locking is a bit narrower, still if you ask this question without telling what you expect of locking and how your application should work, you better first read about what locking can do for.

First of all locks are only needed for multi user environments. Is your dos app multi user at all?

Bye, Olaf.
0
 
pcelbaCommented:
Several concepts exist:

1) Do nothing and FoxPro will lock records/files automatically. You just need to process possible error messages when the lock fails.

2) Explicit file/record locking by FLOCK()  or  RLOCK() - lock the record if you are updating it, lock the file if you are updating more records. You may split this approach into two parts:

a) pessimistic locking - lock the record/file before you start editing it
b) optimistic locking -  lock the record/file just before you save your changes to it

Pessimistic locking can block your application if several users are updating same record/file. Optimistic locking is also called "The last is the winner" - changes made by the last user saving data into a file/record represent the final record/file contents.

I am using record locking for header table and automatic locking for line tables obviously. (I suppose if the Order/Invoice header is locked by me then nobody else will write to appropriate order/invoice lines.)

To have your application running smoothly the record and namely the file should remain locked as short time as possible. Never leave the record/file locked when you are waiting for user response. If this is necessary then all READ commands should have timeout activated to avoid application blocking.

You should study following commands/functions in the FoxPro help:
RLOCK(), FLOCK(), UNLOCK, SET EXCLUSIVE, SET REPROCESS, SET REFRESH, FLUSH
0
 
CaptainCyrilCommented:
The usual approach to locking a single record:

IF RLOCK('table')
    DO stuff
    UNLOCK IN table
ELSE
    WAIT WINDOW "Record is locked by another user".
ENDIF

Open in new window

0
 
IdaracAuthor Commented:
Great answer
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now