Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Updating Multiple Records with Multiple Users
Message
From
03/10/2001 03:18:34
 
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00562935
Message ID:
00563449
Views:
17
* procedure Class.UpdateAllTables
lparameters llForceOverwrite
...
BEGIN TRANSACTION
llCont = .T.
for i=1 to alen(this.aTableList,1)
  llCont = this.TryToUpdateData(this.aTableList[i],llForceOverwrite)
  if !llCont
    gcModifiedTabe = this.aTableList[i] && notofy by some way which table is not updated
    exit
  endif
endfor
if llCont
  END TRANSACTION
else
  ROLLBACK
endif
...
return llCont
TryToUpdateData - updates a single table in the "force" mode passed as a parameter. In the main routine you call the UpdateAllTables routine as many times as needed. First time call it with parameter = .F. When some tableupdate() fail in the TryToUpdateData method, transaction will rollback and that returns all buffers to the state before the BEGIN TRANSACTION. Then call second time with "force" option = .T. In the TryToUpdateData you will check specially if table is not changed again using timestamp:
....
if FSIZE("tTimeStamp")>0 AND llForceOverwrite && if timestamp field exists, do this only when
             && we're going to overwrite
  ltTimeStamp = CurVal(tTimeStamp)
  refresh() && after this CurVal() will return the lates values
  if ltTimeStamp<>CurVal(tTimeStamp)
    return .F. && again, we cannot update because record is changes in the moment between
               && first try and this moment
  endif  
endif
....
HTH.

P.S. Timestamp will be able to catch the same thing - you can even avoid playing around the "Force" option using this option. However, what is there are no such field?

P.P.S. When you have something like a child table that you use to delete records than insert new records (some sort of the selections list for parent table record), you will require to organize this by another way - track changes bys pecial query etc. So it is good idea in such case to make call of the emty class method (something liek "hook"), where you will be able to write this special code for that table.

>Vlad,
>
>Here is the problem with that: Say I have already updated 2 of the 3 tables that I wanted to and when updating the 3rd table I run into an error because some other user has changed something in that 3rd table. Not only do I not want to save the changes in the 3rd table but I want to undo the changes in the first 2. How do I determine before issuing the TABLEUPDATE command whether another user has edited the record that I want to update?
>
>Matt
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.com
ICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs

It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.
Previous
Reply
Map
View

Click here to load this message in the networking platform