Hi to all,
I'm developing a multiuser application with VFP 5, and I'm working on a
lock problem.
On the workstation A I do this code
USE myTable IN 0
SELECT myTable
RLOCK("1", "myTable") && It return .T.
ISRLOCKED(1) && It return .T.
while the record 1 is locked I go at the workstation B and I do this code:
USE myTable IN 0
SELECT myTable
ISRLOCKED(1) && It return .F. <<<< ????
RLOCK("1", "myTable") && waiting for lock ........ and
return .F. (ok record locked by workstation A)
Why ISRLOCKED() has returned .F. ? Maybe ISRLOCKED and SYS(2011) return
only the lock status modify by my workstation ? Documentation doesn't say
it !
Ok, now the REAL BIG PROBLEM
The application uses a database with reference integrity and the
transaction (because we're on a Lan and the other problem of a multi user
application)
In the store procedure the R.I. update procedure is this:
procedure RIUPDATE
lparameters tcFieldName,tcNewValue,tcCascadeParent
local llRetVal
llRetVal=.t.
IF ISRLOCKED() OR !RLOCK()
llRetVal=.F.
ELSE
IF EVAL(tcFieldName)<>tcNewValue
PRIVATE pcCascadeParent
pcCascadeParent=upper(iif(type("t
cCascadeParent")<>"C","",tcCascadeParent))
REPLACE (tcFieldName) WITH tcNewValue
IF CURSORGETPROP('BUFFERING') > 1
=TABLEUPDATE()
ENDIF
llRetVal=pnerror=0
ENDIF values don't already match
ENDIF it's locked already, or I was able to lock it
UNLOCK RECORD (RECNO())
return llRetVal
I think it's wrong because it return .F. if it cannot lock the record (
right) OR I've already locked the record (wrong for me)
Why can I say this ?
Think to this example
I'm using transaction so I've to do something like this :
RLOCK ( recno('child'), 'child')
RLOCK ( recno('parent'), 'parent') && Because other user cannot
modify data until I've ended the mine
REPLACE bla bla bla IN child Table
REPLACE code IN parentTable && change key code of index for
reference with child table
&& so Reference Integrity must work
BEGIN TRANSACTION
TABLEUPDATE(.t.,.t., "child")
UNLOCK RECORD n In child
TABLEUPDATE(.t.,.t., "parent") && ------> refrence
integrity start
UNLOCK RECORD n In Parent
END TRANSACTION
In this example the 2nd tableupdate() return .F. because trigger failed,
the RIUPDATE proc try to lock a record that I locked for my change and it
will be unlocked by the END TRANSACTION.
Maybe the RIUpdate proc has to be changed like this:
procedure RIUPDATE
lparameters tcFieldName,tcNewValue,tcCascadeParent
local llRetVal, llRecIsRlocked
llRetVal=.t.
llRecIsRlocked = ISRLOCKED()
IF llRecIsRLocked OR RLOCK() && If record is already locked or
I'm able lock it
do update operation
ELSE
llRetVal = .F.
ENDIF
IF !llRecIsLocked && if I've locked the record
UNLOCK RECORD (RECNO())
ENDIF
return llRetVal
What do you think about this ? It's a good idea or what ?
Thanks in advance for any suggestion.
Renato
MAILTO:
renato.bertuol@elmec.it