Welcome! Log In Create A New Profile

Advanced

Locked Records

Posted by Paul Ziegler 
Paul Ziegler
Locked Records
November 26, 2008 07:25PM
Is the only way a Hyper File record gets locked is with: HLockRecNum?
I have read the Help and just want to verify that Queries, HReadFirst, NReadNext, etc do not automatically lock records.

Also, if I want to put a database into Ready Only for certain clients, I could use HLockFile for all the files and nothing will unlock the file for that client (HFCS) except HUnlockFile?

If I lock a file in HFCS, it is only locked for that client?
If I lock a file, in HF Classic network that file is locked for other users?

Thanks,
Paul
Fabrice Harari
Re: Locked Records
November 26, 2008 08:24PM
Hi Paul...

It has to be locled explicitely (no function will lock it without YOU asking for it)...

if you lock the file, ONLY the user locking the file will be able to access it...

A lock is for EVERYBODY accessing the file (or locking would have very little purpose), and it's the same in classic or HFCS...

basically you want to lock a record ONLY while you are modifying it (and not while the form is open, only during the save button process), and a file only while you are doing maintenance work on it (if you have a process merging duplicates records by example)

Best regards

Fabrice Harari
WinDev, WebDev, Windev Mobile consulting
Paul Ziegler
Re: Locked Records
November 26, 2008 09:27PM
Fabrice,

Thanks for the reply. It is very helpful to know exactly how the locking is working. In my last design tool, whenever we did a query a record was loaded and locked. The same for some other db functions.

If I only lock the record when I run a Save procedure, what stops another user from opening the same record and doing some modifications at the same time?

Thanks,
Paul
Fabrice Harari
Re: Locked Records
November 26, 2008 10:34PM
Hi Paul...

When working on this problem, you first have to define 'at the same time'...

I personally find that most of the time, blocking a record as soon as a form is open is not acceptable (what happen when the user stays logged and leave for the week end.. On Thursday?)

So what I do is a little more complex, but less intrusive for the users:
- when opening the form, I save the original values
- when the user clicks save, I check if anything was modified
- if not, there is nothing to save, hence no blocking necessary
- if something was modified, I then check the record in the DB
- if it's the same than the original one, I can just block my record and save it
- if the record was modified while I was working, I check what fields were modified outside and by me... If they are different, I just merge the changes, block and modify...
- the only DIFFICULT case is when another user modified the same field(s) than I did...

In that case, 2 different strategies are possible:
- display the conflict and let the user decide (I find that difficult to understand for the user, and anyway, he generally doesn't know any better than always say that HIS changes should win)
- decide once and for all that LAST IN WINS, and therefore write MY modifications in the record...

But of course, that's just me :-)

Best regards

Fabrice Harari
WinDev, WebDev, WinDev Mobile consulting
Paul Ziegler
Re: Locked Records
November 26, 2008 11:37PM
Fabrice,

Thanks for the info. You take good care of your users.

Before when I asked if a record lock was locked to other users, I was not thinking. What I wanted to say was is there an easy way to just set one user to a Read Only status? In my old tool I would set all files to Read Only and it would only affect the Local User.

Thanks,

Paul
Fabrice Harari
Re: Locked Records
November 27, 2008 12:07PM
Hi Paul...

well, you CAN do a hOpen with hRead option, and all add/modify/delete will be impossible, but you will still need to test for the corresponding errors each time your code tries to do something like this...

you could intercept these errors with a when exception of course, but if you procede like that, the user will have no visual clue that he is in read only, and THEN will have an error message (even if it's a pretty one) when he tries to edit something (after he entered all the changes)...

It seems to me that you'd better have a global flag and grey all save button when entering forms, the process would be more user friendly

Best regards

Fabrice Harari
WinDev, WebDev, WinDev Mobile Video Courses
Paul Ziegler
Re: Locked Records
November 27, 2008 03:38PM
Fabrice,

Thanks for the advice. You have been very helpful.

Paul
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: