Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 6 of 6 total
Thread How to test if record is locked?
Sun, Feb 10 2019 10:39 PMPermanent Link

Polywick Studio


Q1. How to test if record is locked, by another session or another user in a different computer?

Q2. How would you notify whom (the user and machine name) locked the record?
Mon, Feb 11 2019 2:48 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Polywick

>Q1. How to test if record is locked, by another session or another user in a different computer?

If you're using optimistic row locking I think you're out of luck but have a look at ServerSessionLocks table in the OLH

>Q2. How would you notify whom (the user and machine name) locked the record?

Same answer as above

Roy
Mon, Feb 11 2019 5:53 AMPermanent Link

Polywick Studio

> if you're using optimistic row locking I think you're out of luck but have a look at ServerSessionLocks table in the OLH

Is there a VCL entry or example for this?
Mon, Feb 11 2019 6:19 AMPermanent Link

Polywick Studio

Also,

what if it's local engine? what happens?
Mon, Feb 11 2019 7:39 AMPermanent Link

Raul

Team Elevate Team Elevate

On 2/11/2019 5:53 AM, Polywick Studio wrote:
> Is there a VCL entry or example for this?

You need to query ServerSessionLocks - it's an information table so you
use normal edb query component.

It's very app specific behavior so i'm not aware of an example.

If you need even more control over this then you can also look into
manual locking - see LockCurrentRecord/UnlockCurrentRecord in help as
well as RecordIsLocked.

This way you can do this at code level without relying on edit and lock
protocol and show a message or such even before any edit.

It's more work and RecordIsLocked does not show edit based locks so
you'd need to be consistent

Raul


-

Mon, Feb 11 2019 7:51 AMPermanent Link

Matthew Jones

Polywick Studio wrote:

>
> Q1. How to test if record is locked, by another session or another user in a different computer?
>
> Q2. How would you notify whom (the user and machine name) locked the record?

I'm fairly sure I've done something like this in the past, but it isn't pretty. Basically the way to do it is all in code. When you want to edit the record, you start by checking the ID column. If it is NULL, then do an update on the record to insert the ID of the person who wants to edit it. Then you read the ID stored in the record to see if it is you. If it is not you, then you lose - someone else got in first. If it is you, then you own the record, and can do what you want. When you are done, be sure to set the editor ID back to NULL. Ideally, your future updates are "WHERE record = theRecord AND userId = myUserId".

One addition I did to this was to have a timeout field too, also set when the user is set. This allows the system to scan the system for records that were locked and the application failed to unlock it.

I've used this for work processing, where multiple threads are reading a database looking for work. This ensures only one gets it.

--

Matthew Jones
Image