Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Muli-user/Multi-record updates
Message
From
18/02/2003 19:41:24
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Muli-user/Multi-record updates
Miscellaneous
Thread ID:
00754761
Message ID:
00754761
Views:
36
Existing Appliocation, VFP 7, Multi-User, Mult-Record Updates
I posted question about this and have gotten advise on what to look for and what
to try to fix. I think I have a solution but would like feed back to make sure I
understand what I am doing. Tables are related in the data enviroment by a common
key in tables vitems instock. In the dataenvironment of the driver form the buffer
mode for instock is 3 and that for vitems is 5. I think the data enviorment is
set to private since it has an init method (how to I check that?). The driver file
for the applications has set lock off, multilocks on, and set reprocess is set to
10 seconds. Does this make a difference? Quick overview of existing code.
SELECT vitems
SET ORDER TO TAG ordkey IN vitems
SCAN FOR vitems.clordno = Order_List.cordno
* some calculations and figure out which records need to be updated
  IF lnOnHandQty <> 0 && update on hand qty, on order qty, and completion flag
     RLOCK('instock')
     REPLACE instock.feilda with valuea, .... instock.fieldn with valuen
        IN instock
     TABLEUPDATE(0,.T.,'instock')
     UNLOCK IN instock
     IF flag <> value
        RLOCK('vitems)
        REPLACE vitems.field with value
        TABLEUPDATE(0,.T.,'vitems'
        UNLOCK IN vitems
     ENDIF
   ENDIF
ENDSCAN
SELECT vitems    *** Question 1. I do not understand why are these two commmands here?
TABLEUPDATE(.T.)
I would like to add error check the be sure records are locked and fields are updated.
Will the following code work, ie lock selected records during update process, update
then if all goes well, undo changes if it does not. What affect (if any) do SET
commands have?
SELECT vitems
SET ORDER TO TAG ordkey IN vitems
BEGIN TRANSACTION
SCAN FOR vitems.clordno = Order_List.cordno
* some calculations and figure out which records need to be updated
  IF lnOnHandQty <> 0 && update on hand qty, on order qty, and completion flag
     llRlock = RLOCK('instock')
     IF NOT llRlock
        EXIT
     ENDIF
     REPLACE instock.feilda with valuea, .... instock.fieldn with valuen
        IN instock
     TABLEUPDATE(0,.T.,'instock')
     UNLOCK IN instock
     IF flag <> value
        llRlock = RLOCK('vitems)
        IF NOT llRlock
           EXIT
        ENDIF
        REPLACE vitems.field with value IN vitems
        TABLEUPDATE(0,.T.,'vitems')
     ENDIF
   ENDIF
ENDSCAN
IF NOT llRlock
   ROLLBACK
   TABLEREVERT(.T.,'instock')
   TABLEREVERT(.T.,'vitems')
ELSE
    llTableUpdate = TABLEUPDATE(.T.,'instock')
    IF NOT llTableUpdate
       ROLLBACK
       TABLEREVERT(.T.,'instock')
       TABLEREVERT(.T.,'vitems')
    ELSE
       llTableUpdate = TABLEUPDATE(.T.,'vitems')
       IF NOT llTableUpdate
          ROLLBACK
          TABLEREVERT(.T.,'instock')
          TABLEREVERT(.T.,'vitems')
       ELSE
          END TRANSACTION
       ENDIF
   ENDIF
ENDIF
UNLOCK IN instock
UNLOCK IN vitems
IF llRlock AND llTableUpdate
   WAIT WINDOW AT 20,50 'Updates accepted'
ELSE
   WATI WINDOW AT 30,50 'Updates failed'
ENDIF
Reply
Map
View

Click here to load this message in the networking platform