Subject Re: [IBO] "with lock" SQL function
Author Helen Borrie
At 11:32 AM 27/11/2008, you wrote:
>Hi--
>
>I'm trying to do something very simple but can't figure it out.
>
>I want to prevent more then one person from editing the same record
>at the same time.
>
>Right now, 2 different users can both put the same record into edit
>mode in my application.
>
>I want to prevent that.
>
>About the only thing I could find online was adding a "with lock" to
>the end of the SQL that puts the single record into edit mode. (I
>start an explicit transaction before it goes into edit mode.)
>
>But that doesn't give me what I'm looking for.

NoNoNoNo.

> When the record is
>in edit mode, the other users cannot query the table for a read-only
>result that includes the record that's locked. In my application,
>there is a grid of records and that query is set to read-only. If a
>user puts a record into edit mode and another user wants to display
>the grid that includes that record, they end up with an error
>message of "lock conflict on no wait transaction deadlock".
>
>How do I prevent 2 users from both putting the same record into edit
>mode at the same time?

Set PessimisticLocking true on the dataset. As soon as the user attempts to go into Edit mode (a client-side concept) the application will send a "dummy update" to the server, thus either a) acquiring a write lock for that record for that transaction or b) denying the lock because some other transaction already has a write lock on the same record. If the lock is denied, IBO won't let the dataset go into Edit mode.

Obviously this only works if a) the transaction is read/write and b) the dataset is also set RequestLive true (or its equivalent for multi-table sets).

Helen