Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Anders Altberg
  Where is Anders Altberg?
 Uppsala
 Sweden
 Anders Altberg
 To: mk sharma
  Where is mk sharma?
 mumbai
 India
 mk sharma
 Tags
Subject: RE: how to create log when change in data
Thread ID: 330803 Message ID: 330996 # Views: 30 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: General VFP Topics
Date: Sunday, December 25, 2011 1:20:23 PM         
   


> i want to create a log dbf to store data changes.
> i am using buffering .
> suppose a invoice have 10 products and user changed a record from this 10 records (Productname,quantity,rate,tax).
> how to know that which record is changed ?
> how i can do this ?
>
> Warm Regards,
> mk.

Where's the primary or candidate key column?
Why no datebase?


If the table or a modifiable local SQL view is part of a database you can use this update, delete, and insert trigger code:
CREATE TRIGGER ON Mytable FOR UPDATE AS Logit(pkcolumn) 
CREATE TRIGGER ON Mytable FOR DELETE AS Logit(pkcolumn) 
CREATE TRIGGER ON Mytable FOR INSERT AS Logit(pkcolumn) 

PROCEDURE Logit
LPARAMETERS lcPKVal
LOCAL lcTable, lcUser, ldTime, lcKey, lcStatus
  lcUser= SYS(0)
  lcTable=DBF(ALIAS())
  ldTime=DATETIME() 
  lnKey =  m.lcPkVal 
  lcStatus = GETFLDSTATE(-1) 
  INSERT INTO Log1 VALUES (m.lcUser, m.lcTable, m.ldTime, m.lnKey, m.lcStatus)
ENDPROC 

the GETFLDSTATE string has all the information about what columns and rows were changed, and delete or append state.
If you want the actual modification, copy the row to a backup.
Tableupdate of the view knows what was changed and update the view source table.
Note that at the moment the trigger fires yo're always in the update target table (not in the view) which is opened if it was not, but at the moment of the INSERT you're in the log table,

-Anders

ENTIRE THREAD

how to create log when change in data Posted by mk sharma @ 12/23/2011 7:00:32 AM
RE: how to create log when change in data Posted by tushar @ 12/23/2011 7:28:39 AM
RE: how to create log when change in data Posted by mk sharma @ 12/23/2011 8:19:34 AM
RE: how to create log when change in data Posted by tushar @ 12/23/2011 9:46:59 AM
RE: how to create log when change in data Posted by mk sharma @ 12/23/2011 10:09:18 AM
RE: how to create log when change in data Posted by mk sharma @ 12/23/2011 7:45:51 PM
RE: how to create log when change in data Posted by mk sharma @ 12/24/2011 7:48:13 AM
RE: how to create log when change in data Posted by mk sharma @ 12/24/2011 8:08:51 AM
RE: how to create log when change in data Posted by tushar @ 12/24/2011 6:58:16 PM
RE: how to create log when change in data Posted by mk sharma @ 12/24/2011 7:47:03 PM
RE: how to create log when change in data Posted by Anil Sharma @ 12/25/2011 10:23:20 AM
RE: how to create log when change in data Posted by mk sharma @ 12/25/2011 11:13:34 AM
RE: how to create log when change in data Posted by Anders Altberg @ 12/25/2011 1:20:23 PM