Solved

Foxpro for DOS 2.6 record locking

Posted on 2013-11-10
4
920 Views
Last Modified: 2013-11-12
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
Comment
Question by:Idarac
4 Comments
 
LVL 29

Expert Comment

by:Olaf Doschke
Comment Utility
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
 
LVL 41

Accepted Solution

by:
pcelba earned 500 total points
Comment Utility
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
 
LVL 27

Expert Comment

by:CaptainCyril
Comment Utility
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
 
LVL 1

Author Closing Comment

by:Idarac
Comment Utility
Great answer
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
HOW TO: Connect to the VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere (HTML5 Web) Host Client 6.5, and perform a simple configuration task of adding a new VMFS 6 datastore.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now