Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Foxpro for DOS 2.6 record locking

Posted on 2013-11-10
4
998 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
ID: 39637276
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 42

Accepted Solution

by:
pcelba earned 500 total points
ID: 39637284
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
ID: 39637830
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
ID: 39641764
Great answer
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Is your phone running out of space to hold pictures?  This article will show you quick tips on how to solve this problem.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

861 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