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.
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
* 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
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?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.