Subject Re: [IBO] "with lock" SQL function
Author bwc3068
Hi Helen--

As always, thanks for the prompt reply!

It didn't work.


I'll supply a few more details:

DataModule has 2 persistent queries. 1 is for the read-only display
for the grid, another is what I use to put the user into "edit" mode.

The read-only query is straight ahead..."select blahblahblah".

The edit-query is setup like this:

dmMain.dbInterbase.DefaultTransaction.StartTransaction;
qe.active := False;
qe.SQL.clear;
qe.SQL.add('Select T.* from '+sTableName + ' T');
qe.SQL.add('where T.UniqueKey ='+quotedstr(sUK));
//v5.02K to prevent multiple concurrent edit to same record
//v5.02K did work? qe.SQL.add('with lock');
qe.Active := True;
qe.Edit;

In the properties in dmMain, I set .PessimisticLocking := True
and .RequestLive := True for both (although the grid display query
never puts it into edit mode).

If 1 FB application clicks "edit" so the above query puts the record
into edit mode, the other user cannot resolve a display query using
the grid-display tIBOQuery. If i execute the "select blahblahblah"
for display only and .open it, I get the same "lock conflict on no
wait transaction deadlock".

Both have their .IB_Transaction = (blank) (if i click it it
changes to "<default>", they seem to be the same?)

There is a tIBOTransaction on the dmMain. .AutoCommit =
True; .ReadOnly = False; .Isolation = tiCommitted. Rest I believe
are the default properties.

I also have an tIB_Session and tIB_Connection on the dmMain.

tIB.Connection.DefaultTransaction = IBOTransaction (ie. the
transaction component on dmMain). The rest of the properties look
default / standard.


This is a converted BDE application and it's a very old application
so I cannot change the way there are 2 queries...1 for edit, 1 for
display (if that matters).

help please.

Thanks again.
Kelly


--- In IBObjects@yahoogroups.com, Helen Borrie <helebor@...> wrote:
>
> 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
>