LPARAMETERS pcAlias, pcDatabase * Define constants for the arrays #DEFINE BUFFERNEW laFields( lnCnt, 2 ) #DEFINE TABLENEW laFields( lnCnt, 3 ) LOCAL llRet, laFields(1), lnCnt, lnNext, llGotOne, llView, lcUser, lcTable DIMENSION laFields(1) llRet = .T. llView = ( CursorGetProp( "SOURCETYPE", pcAlias ) = 1 ) IF llView * Fail the resoution for updateable views RETURN .F. ENDIF SET DATABASE TO (pcDatabase) * Attempts to resolve a failed TableUpdate() * * Compares OldVal() and Buffer values to find the * changed values, then checks CurVal() to see if * these are among the fields that are different * in the file. If the changed fields are not * among the different file values, the buffer * is updated from the table and the TableUpdate() * is forced. Otherwise the TableUpdate is allowed * to fail and the SaveChanges will also fail. * Select the work area being resolved SELECT (pcAlias) * Build an array of fields names AFIELDS(laFields) * Get the first modified record lnNext = GETNEXTMODIFIED(0,pcAlias) * As long as we have a modified record and we have not failed DO WHILE lnNext <> 0 AND llRet * Set for no conflicts llGotOne = .F. * Move to the modified record GOTO lnNext * Check buffer against OLDVAL() to build a list of changed fields * result of comparison is stored in column 2 of laFields FOR lnCnt = 1 TO ALEN(laFields,1) * Ignore the update and create fields BUFFERNEW = OLDVAL( laFields( lnCnt, 1 ) ) <> ; EVALUATE(pcAlias+"."+laFields(lnCnt,1)) ENDFOR * Check changed fields against CURVAL() to find any conflicts * Store conflict detection result in column 3 of laFields FOR lnCnt = 1 TO ALEN(laFields,1) TABLENEW = OLDVAL( laFields( lnCnt, 1 ) ) <> ; CURVAL( laFields( lnCnt, 1 ) ) IF BUFFERNEW AND TABLENEW AND ; EVALUATE(pcAlias+"."+laFields(lnCnt,1)) <> ; CURVAL( laFields( lnCnt, 1 ) ) * If both the buffer and the curval() are new from the oldval() * and they are not the same value * Set conflict flag llGotOne = .T. ENDIF ENDFOR * If any conflicts IF llGotOne * Set to fail llRet = .F. * LOOP back to exit DO WHILE LOOP ELSE * There are no field collisions so we will fix the buffered field * values to match the disk image for the unedited fields FOR lnCnt = 1 TO ALEN(laFields,1) IF TABLENEW REPLACE (pcAlias+"."+laFields(lnCnt,1)) WITH ; CURVAL( pcAlias+"."+laFields( lnCnt, 1 ) ) ENDIF ENDFOR ENDIF * Force TableUpdate() IF NOT TableUpdate( .F., .T., pcAlias ) llRet = .F. LOOP ENDIF * Get the next modified record lnNext = GETNEXTMODIFIED(lnNext,pcAlias) ENDDO RETURN llRet