Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Record Update

Status
Not open for further replies.

sohrab100

Programmer
Jan 18, 2002
56
0
0
HK
How can i use buffer mode 5 and update the same record by two network user at the same time and maintain the consistency of the record?

sohrab100
 
you'll need to use some sort of conflict catcher. there's a few different scenarios when dealing with multi-user environment...

[ol][li]First User wins

[/li][li]Last User wins

[/li][li]Last user wins if changes aren't in conflict

[/li][li]Consolidation scheme programmed by programmer that allows both user's to win[/li][/ol]

...as a start look at the following screen (run the following line in your command window):

MODIFY FORM (_samples + "solution\ffc\conflicts.scx")

...another one to check out is a little more simplistic approach wrapped up in a class, check out the following:

MODIFY CLASS _datachecker OF (HOME() + "ffc\_datanav.vcx")


Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
When you run with buffering there are 3 values.

CURRENT VALUE (what's data table has)
OLD-VALUE (what it was when you started your updated)
NEW-VALUE (what you changed it to).

In your save routine you can check the OLD VALUE to CURRENT VALUE. If they are different, someone changed the record on you. Then you can compare OLD-VALUE to CURRENT-VALUE to see what someone else changed, and OLD-VALUE to NEW-VALUE to determine what you changed.

Based on that you can do a few things.
1. If the data fields are different, you can incorporate both changes in your save logic.
2. If they are the same field names, see if the values are different, if so you will need to prompt the user or that someone else changed it or make it so your business rules handle it (last one wins, don't update, etc.)

Look at the OLDVAL() and CURVAL() functions and they will set you in the right direction. Remember, you will need to set buffermode on.



Jim Osieczonek
Delta Business Group, LLC
 
FROM VFP8 HELP. You may have to modify the code to use AFIELDS() function to get the name of all fields. Then it would be a FOR i = 1 to (# of fields). Look at the AFILEDS() to get that syntax. Let us know if you need more help.



CLOSE DATABASES
CLEAR

* Create new table and add blank record
CREATE TABLE employee (cLastName C(10))
APPEND BLANK

* Insert initial value
INSERT INTO employee (cLastName) VALUES ("Smith")

* Enable and set table buffering
SET MULTILOCKS ON && Allow table buffering
=CURSORSETPROP("Buffering", 5, "employee" ) && Enable table buffering

* Display initial value
=MESSAGEBOX("Original cLastName value: "+ cLastName, 0, "Results")

* Change record value and display results
REPLACE cLastName WITH "Jones"
=MESSAGEBOX("Modified cLastName value: "+ cLastName, 0, "Results")

* Store the old value of the field to cTemp variable and display results
cTemp=OLDVAL("cLastName", "employee")
=MESSAGEBOX("Original cLastName value: "+ cTemp, 0, "Results")

* Update table and display final value
=TABLEUPDATE(.T.)
=MESSAGEBOX("Final cLastName value: "+ cLastName, 0, "Results")

* Close and delete example table file
USE
DELETE FILE employee.dbf


Jim Osieczonek
Delta Business Group, LLC
 
if i need to update a number of goods 's stock and running in multi-user envirnment, how can i make use of curval, oldval?

Sample code

select order
scan
select goods
seek (alltrim(order.items))
if found()
replace goods.store with store - order.num
endif
select order
endscan

select goods
=tableupdate(.t.)

if two users select the same items the same time, and run the sample code above, there will be one can update and other cannot update the goods's stock. But what if i use the curval, oldval,

replace goods.store with curval("store", "goods")-order.num

there still have problem when my order have many items because after doing the loop, some more goods stock may change. E.g

User1 User2

items1 items3
items2 items2
items3 items1

if User1 run the code first, and the User2 run the code after and when User2 run items1 before User1's tableupdate
the problem will rise. It's my logic right?

sohrab100
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top