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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I handle remotely changed data in a remote view.

Status
Not open for further replies.

jrumbaug

Programmer
Apr 27, 2003
90
US
I'm still addapting to the concept of local/remote views. The multi-user app that I am develpoing in VFP 8, will eventually be used on a WAN. I am trying to prevent errors from 2 people accessing the same IdControlNumber at the same time. I have a situation where TABLEUPDATE() on a base table with an autoincemented field, will not meet my needs. I want to set up a table of id/key numbers. Is this a correct technique?

Select IdTableView && record buffering ON
REPLACE IdTableView.Number WITH IdTableView.Number + 1
nCount = 0
&& update record, do not force overwrite overwrite
DO WHILE !TABLEUPDATE(0,.F.) .and. nCount< 100
REQUERY() &&get the new value that someone else put in
REPLACE IdTableView.Number WITH IdTableView.Number + 1
nCount = nCount+1
ENDDO

Or does a failed TABLEUPDATE(0,.F.) generate an error that must be handled with an ON ERROR routine?

Thanks in Advance
Jim Rumbaugh
 

Jim,

I have a situation where TABLEUPDATE() on a base table with an autoincemented field, will not meet my needs.

Why? What's the problem with using autoinc?

But, if you really can't use autoinc, you'll need to lock the ID table just before you increment it, and unlock it immediately afterwards. That happens automatically, as the table is buffered. You shouldn't need to do the TABLEUPDATE() in a loop. VFP will automatically retry the lock for a given period or number of attempts (controlled by SET REPROCESS).

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Thanks Mike
You asked."Why? What's the problem with using autoinc?"

Without going into the LONGGGGG reason, the end result is TABLEUPDATE() moves the pointer on my view and gives me the KEYNUMBER. To refind my record, I need to know the KEY NUMBER before the TABLEUPDATE() moves the pointer. I think I've worked out my answer. I'm happy with this, because so far I haven't seen anything that addresses the issue of "what if your remote data changes before you save".

** written 8-2005 by Jim Rumbaugh
** to get new key field number from remote data (no locks)
** checks to see if field has been changed by someone else
** if so retries
** Do a "SELECT ViewFilename", then call function
** RETURNS .T. if successfull
FUNCTION GetNewNumber( cFieldName )
Local nCount , lSuccess
Replace (cFieldName) With Evaluate(cFieldName)+1
nCount = 0
lSuccess = .T. && default return
&& update record, not table. Do not force overwrite
Do While !Tableupdate(0,.F.)
&& table was updated by someone else, refresh data
Tablerevert() && gotta undo before refresh
Requery() && get the new value
Replace(cFieldName) With Evaluate( cFieldName)+1
nCount = nCount+1
If nCount = 100
Messagebox( "No Success.Try Later")
lSuccess = .F.
Exit
Endif
ENDDO
RETURN lSuccess

I'd appreciate any feedback. I have not tested this with a remote connection, just on my machine.

Jim Rumbaugh
 

Jim,

Sorry ... I hadn't taken in that your key table is on a back end server (is it?).

If so, the issue of file locking is quite different .. and depends in part on which back end you are using. In general, you can't explicitly lock rows or tables on the back end.

To find out if the remote data has changed before you save (with a remote view), you must first make sure that you have selected an appropriate option on the Update Criteria page of the view designer. Usually, the best option is "key and updated fields". If the remote data has changed, the server won't be able to find the record you want to update, and you will get a "record not found" error or something similar (the actual error code will vary with the back end). That's what you need to be checking in your reply from TABLEUPDATE().

Also, to answer your earlier question -- no, you don't need to use an error routine. If TABLEUPDATE() returns .F., use AERROR() to find the nature of the error.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Thank you, Mike

To answer you question,my data is not on a back-end server yet, but should be by the end of the project.

I consider my question answered. Unless someone else has a comment about verifying saved backend data.

Jim Rumbaugh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top