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!

VFP AND SQL UPDATE CONFLICT 2

Status
Not open for further replies.

morlassino

IS-IT--Management
Jul 1, 2004
33
0
0
US
ok i have tried requery seems to work but now if two users are in the same record at the same time and they both hit save i get an update conflict
i am ussing row buffering set to 3 is there any way around this???
thanks
Mario

MARIO P ORLASSINO
ASSISTANT MANAGER IT
"THE HOSE HEAD"
 
How are you updating? Simple SKIP or are you using TABLEUPDATE()? You need to use TALBEUPDATE() and test the success prior to moving the pointer. ie.
Code:
llSuccess = TABLEUPDATE(1,.F.)
IF ! llSuccess
   *at this point you can warn the user
   *force the update or TABLEREVERT()
ENDIF

Marcia will be along later to tell you to use Buffermode 5. <g>

Regards,

Mike
 
Hi Mario.

Actually, a safeer approach would be to have a form method called HandleError and call it if llSuccess if false. This code in HandleError():

Code:
LOCAL laErrors[1], llRetVal, loUpd, lcMsgTxt
llretVal = .T.

AERROR( laErrors )
DO CASE
  CASE laErrors[1] = 1539    && Trigger failed
    DO CASE
      CASE laErrors[5] = 1  && Insert Trigger
        lcMsgTxt = 'Unable to add new record. Insert trigger failed!'
        llRetVal = .F.
      CASE laErrors[5] = 2  && Update Trigger
        lcMsgTxt = 'Unable to save record. Update trigger failed!'
        llRetVal = .F.
      CASE laErrors[5] = 3  && Delete Trigger
        lcMsgTxt = 'Unable to Delete record. Delete trigger failed'
        llRetVal = .F.
    ENDCASE  
  CASE laErrors[1] = 1585    && Update Conflict
    *** updres is my custom form class that handles update
    *** conflicts and either resolves them or displays
    *** them to the user for intervention. If the conflicts
    *** can be resolved without user intervention, the
    *** form class merely return .F. from its init() and
    *** is never seen
    loUpd = CREATEOBJECT( 'updres', ThisForm.DataSessionID, .cPrimaryAlias )
    IF TYPE( 'loUpd' ) = "O" AND ! ISNULL( loUpd )
      loUpd.Show()
    ENDIF
    llRetVal = .T.
  CASE laErrors[1] = 1884    && Duplicate key  
    lcMsgTxt = 'Unable to Save. Duplicate key!'
    llRetVal = .F.
  OTHERWISE
    lcMsgTxt = 'Sorry. Unable to save data right now.'
    llRetVal = .F.
ENDCASE              
IF NOT llRetVal
  MESSAGEBOX( lcMsgTxt, 16, 'Unable to Save Your Changes' )
ENDIF
RETURN llRetVal


Marcia G. Akins
 
Mario,

If I remember right, your are using SQL Server as your back end? Is that correct? If so, setting buffering on won't make any difference, as it will be your remote view or cursor that is buffered, not the tables on the server.

Essentially, an update conflict means that one user is trying to overwrite another user's edits. Your application has to have a method of dealing with that, and no-one here can tell you what that method is. You have to decide what must happen in those circumstances. For example, you might decide that the second user will go ahead and overwrite the edits, or that the second user's edits will be lost.

The actual mechanics will depend on which back end you are using, so perhaps you could clarify that point.

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
ok thprocedure is working ok but..... now i get an extra record it seems to be appending.. here is my code if you can help..
Code:
SELECT buslist
	replace buslist.vinid WITH (thisform.vin.Value)
	replace buslist.yardparkd WITH (thisform.yardprkd.Value)
	replace buslist.edit WITH tTOC(DATEtime())



llSuccess = TABLEUPDATE(1,.F.)
IF ! llSuccess
   mess2 =MESSAGEBOX('Data Has Been Changed By Another User! '+(chr(13))+' Do You want to Overwrite With Your Changes?',36)
   	DO CASE 
   		CASE mess2 = 6 
		   		TABLEUPDATE(1,.T.,'buslist')
				replace buslist.vinid WITH (thisform.vin.Value)
				replace buslist.yardparkd WITH (thisform.yardprkd.Value)
				replace buslist.edit WITH tTOC(DATEtime())
		CASE mess2 = 7 
				MESSAGEBOX('YOUR CHANGES WERE ABORTED!',48)
			TABLEREVERT(.t.,'buslist')	
	ENDCASE
			
ENDIF
[\code]

MARIO P ORLASSINO
ASSISTANT MANAGER IT
"THE HOSE HEAD"
 
Hi Mario,

Can't see anything that would cause an append. The extra replaces aren't necessary.
Code:
IF mess2 = 6
   TABLEUPDATE(1,.T.,'buslist')
ELSE
   TABLEREVERT(.T.,'buslist')
ENDIF
Use a / with code instead of \.

Regards,

Mike
 
Marcia,

Nice solution, have a star.

Regards,

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top