>INSERT TRIGGER track(ALIAS(),"INSERT") >UPDATE TRIGGER track(ALIAS(),"UPDATE") >DELETE TRIGGER track(ALIAS(),"DELETE") >>
>********************************************************************** Procedure TRACK(LCTABLE,LCACTION) >***** procedure to document INSERTS, UPDATES, and DELETING of records >***** updated 12/18/2006....rlh >***** 01/19/2007 ... rlh... skip tracking if no changes >Procedure TRACK(LCTABLE,LCACTION) > >Local lcAlias, ; > lcOldReprocess, ; > lnOldArea, ; > lcSelectedDBC, ; > lcDBF, ; > lcLogFileDBF, ; > lcMacro, ; > lcRecord, ; > lcUserID, ; > lcSetSeconds, ; > cNewChanges > > >If Type('oApp.p_skip_tracking') # 'U' And oApp.p_skip_tracking = .T. > *** we want to skip the tracking process >Else > lcSetSeconds = Set("Seconds") > Set Seconds On > > > lnOldArea = Select() > lcAlias = Upper(Alias()) > Select(LCTABLE) > lcSelectedDBC = CursorGetProp("Database",Alias()) > > lcLogFileDBF = Left(lcSelectedDBC,Rat'\',JustpathlcSelectedDBC)))+'MASTERDBC\MASTERDBC.DBC' > > lcOldReprocess = Set('REPROCESS') > > *-- set automatic > Set Reprocess To Automatic > Use In Select('log') > If !Used("log") > If !Dbused('MASTERDBC') > Open Database &lcLogFileDBF > Endif > Use MASTERDBC!Log In 0 Again Shared > Endif > > Select Log > lcMacro = Alltrim(LCTABLE)+'.pk' > lcRecord = &lcMacro Do this instead: lcRecord = eval(alltrim(m.lcTable)+".pk") Also use m. on field references for an extra boost and to prevent painful debugging should one of your variable names ever match a fieldname in one of your tables. > > If Type('oApp') = 'O' And Type('oApp.p_computer_userid') = 'C' > lcUserID = oApp.p_computer_userid > Else > **** direct modifications of tables by developer > lcUserID = 'Develop' > Endif > cNewChanges = '' > If lcUserID = 'Develop' &&& just save changes only > Select(LCTABLE) > For lnField = 1 To Fcount(LCTABLE) > > If (Transform(Oldval(Field(lnField,LCTABLE))) != Transform(Evaluate(Field(lnField,LCTABLE)))) > > If Isnull(Oldval(Field(lnField,LCTABLE))) And Empty(Evaluate(Field(lnField,LCTABLE))) > ** skip tracking > Else > cNewChanges = cNewChanges +'<fld>'+Field(lnField)+'</fld>'+Chr(13)+; > '<typ>'+Type('EVALUATE(FIELD(lnField))')+'</typ>'+Chr(13)+; > '<old>'+Transform(Oldval(Field(lnField,LCTABLE)))+'</old>'+Chr(13)+; > '<new>'+Transform(Evaluate(Field(lnField,LCTABLE)))+'</new>'+Chr(13) Make a small procedure to return cNewChanges. Having 2 copies of this code in this small a routine is not good practice. > Endif > Endif > Endfor > If !Empty(cNewChanges) > Select Log > Append Blank > Replace ACTION With LCACTION, ; > RECORD_PK With lcRecord, ; > CTABLE With LCTABLE, ; > DATA_BASE With Strtran(lcSelectedDBC,Left(lcSelectedDBC,Rat('\',Justpath(lcSelectedDBC))),''), ; > userid With lcUserID, ; > D8 With Datetime(), ; > ident With Sys(0),; > changes With cNewChanges IN 'log' USE SQL-INSERT command instead of 3 command (SELECT TABLE, APPEND BLANK, REPLACE...) Not only that, but make a separate small procedure to do the insert. Having 3 copies of this code throughout this routine is not good practice. You could probably also do the > Endif > Else > If LCACTION != 'DELETE' &&& skip for deleted records > **** if oApp property is set to track details > > If Type('oApp.p_skip_tracking') # 'U' And oApp.p_skip_tracking =.F. > *If CursorGetProp("Buffering",LCTABLE) > 1 &&& table is buffered > Select(LCTABLE) > For lnField = 1 To Fcount(LCTABLE) > > If Transform(Oldval(Field(lnField,LCTABLE))) != Transform(Evaluate(Field(lnField,LCTABLE))) > cNewChanges = cNewChanges +'<fld>'+Field(lnField)+'</fld>'+Chr(13)+; > '<typ>'+Type('EVALUATE(FIELD(lnField))')+'</typ>'+Chr(13)+; > '<old>'+Transform(Oldval(Field(lnField,LCTABLE)))+'</old>'+Chr(13)+; > '<new>'+Transform(Evaluate(Field(lnField,LCTABLE)))+'</new>'+Chr(13) > Endif > Endfor > > If !Empty(cNewChanges) > Select Log > Append Blank > Replace ACTION With LCACTION, ; > RECORD_PK With lcRecord, ; > CTABLE With LCTABLE, ; > DATA_BASE With Strtran(lcSelectedDBC,Left(lcSelectedDBC,Rat('\',Justpath(lcSelectedDBC))),''), ; > userid With lcUserID, ; > D8 With Datetime(), ; > ident With Sys(0),; > changes With cNewChanges IN 'log' > Endif > Endif > Else &&& deleted record > Select Log > Append Blank > Replace ACTION With LCACTION, ; > RECORD_PK With lcRecord, ; > CTABLE With LCTABLE, ; > DATA_BASE With Strtran(lcSelectedDBC,Left(lcSelectedDBC,Rat('\',Justpath(lcSelectedDBC))),''), ; > userid With lcUserID, ; > D8 With Datetime(), ; > ident With Sys(0),; > changes With cNewChanges IN 'log' > Endif > > Endif > > Use In Select('log') > USE IN SELECT('pk_list') > USE IN SELECT('pk_users') > USE IN SELECT('identity') Leave the logging tables open for the next run, if at all possible. > > > > Select (lnOldArea) > > Set Reprocess To lcOldReprocess > Set Seconds &lcSetSeconds >Endif >Endproc > > >