Discussion:
Begin & End Transaction - Delete problem...
(too old to reply)
Debbie
2005-04-02 01:10:07 UTC
Permalink
I have a problem deleting records during a Begin and End Transaction.
Basically this is what is happening:

If User1 is viewing a record in MYTABLE at the same time that User2 runs a
procedure to delete a batch of records from MYTABLE then all the records get
deleted except for the one that User1 was looking at. I have tried
including the following code, but it makes no difference!

SELECT mytable
SCAN
IF EXP1 = EXPR2
DO WHILE !RLOCK("mytable")
LOOP
ENDDO
DELETE IN mytable
TABLEUPDATE(0,.T.,"mytable")
UNLOCK IN mytable
ENDIF
ENDSCAN

Could someone please tell me where I am going wrong?

Many thanks - Debbie
Cindy Winegarden
2005-04-04 14:43:08 UTC
Permalink
Hi Debbie,

You didn't include the Transaction code in your example. In any case, the
Help on Begin Transaction says:
When you modify records in a table that is part of a transaction, other
users on the network do not have access (read or write) to the records until
you end the transaction.

When other users on the network try to access records you have modified,
they must wait until you end your transaction. They receive the message
"Record not available ... please wait" until the records become available.
Because of this, it is important to keep the length of the transaction to a
minimum or conduct the transaction during times when others do not need
access.
<<
--
Cindy Winegarden MCSD, Microsoft Visual Foxpro MVP
***@msn.com www.cindywinegarden.com
Blog: http://spaces.msn.com/members/cindywinegarden
Post by Debbie
I have a problem deleting records during a Begin and End Transaction.
If User1 is viewing a record in MYTABLE at the same time that User2 runs a
procedure to delete a batch of records from MYTABLE then all the records get
deleted except for the one that User1 was looking at. I have tried
including the following code, but it makes no difference!
SELECT mytable
SCAN
IF EXP1 = EXPR2
DO WHILE !RLOCK("mytable")
LOOP
ENDDO
DELETE IN mytable
TABLEUPDATE(0,.T.,"mytable")
UNLOCK IN mytable
ENDIF
ENDSCAN
Could someone please tell me where I am going wrong?
Many thanks - Debbie
Olaf Doschke
2005-04-07 20:55:42 UTC
Permalink
Post by Debbie
DO WHILE !RLOCK("mytable")
LOOP
ENDDO
In addition to what Cindy told you, it's
not a good idea to wait for a recordlock
to work, because this locks the application
of User2 until User1 has finished with it's
work on the record.

Simply rollback the transaction and tell
User2 that deleting isn't possible right now,
and he should try again later.

Bye, Olaf.

Loading...