Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Updating tables using remote views !!!
Message
From
23/04/2002 07:41:42
 
 
To
23/04/2002 06:48:17
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00648035
Message ID:
00648047
Views:
17
>Hi,
>
>I am working on a multi user system which uses remote views to update tables.I am running the following code to get a unique number from a table, and then update that number with the new uniwue one. when three or more users are running this program at the same time, only one of the users is able to update the number properly, the others get stuck in the loop and get a 'update conflict' error when hitting the tableupdate() code.
>
>
>Any ideas ??
>
>updatedok=.f.
>
>do while updatedok=.f.
> =requery("remote")
> replace remote.no with remote.no+1
>
> updatedok=tableupdate()
> if updatedok=.f.
> =tablerevert()
> unlock all
> endif
>
> loop
>enddo

Given the scenario, I'd recommend not using an RV at all, but directly use the remoted table, and explicitly spin on acquiring a lock, once the lock is acquired, grab the number, increment it, flush the update and then release the lock. Unless there's a demand that all numbers are contiguous and uniformly incremented, allocating a key and simply throwing it away if the update fails is safe and easily serialized:

Create a table IncTable, with two fields:

IncFldName C(20) && can be any size
IncFldValue I && or whatever numeric you need
FUNCTION ReturnIncValue(cIncValueName)
LOCAL nReturnValue, cInAlias
cInAlias = ALIAS()
IF ! USED('IncTable')
   USE IncTable IN 0 SHARED AGAIN
ENDIF
SELECT IncTable
LOCATE FOR IncFldName == PADR(cIncValueName,20)
IF ! FOUND()
   INSERT INTO IncTable VALUES (cIncValueName,0)
ENDIF
DO WHILE ! RLOCK()
   =DOEVENTS()
ENDDO
nReturnValue = IncFldValue
REPLACE IncFldValue WITH nReturnValue + 1
UNLOCK
USE
FLUSH
IF ! EMPTY(cInAlias)
   SELECT (cInAlias)
ENDIF
RETURN nReturnValue
This returns a value guarented to be greater than any previously requested value by 1; if you end up discarding the update, just discard the value. The mechanism will support any number of users and any number of named incremental values, and is guarenteed to be serializable.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform