Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
INSERT not as maintainable?
Message
From
26/07/2006 16:18:39
 
 
To
26/07/2006 16:06:18
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01140411
Message ID:
01140425
Views:
27
mine is a specific reason why i've started using insert more than replace.

What I have found with doing an audit trail is that each replace command adds a row to my audit table, which if i'm replacing a number of fields at one time (say for example with a "save" button on a form), i get a number of rows in my table for the same "save" command. with the insert command, i get only one row which makes it much much easier for me to track changes made to my tables.

here is an example of my audit function just so you can see. it is pretty much similar to what someone else posted on UT (i'm not sure of their name right now).
Function myaudit (tctriggertype)
local lnfield, lcfieldname, lctable, lcusername, lcchanges, lcimacid

lcusername = substr(alltrim(sys(0)),1,atc(" ",alltrim(sys(0)))-1)
lctable = juststem(dbf())
lcchanges = ""
lcimacid = 0

do case
case tctriggertype = "I"
	for lnfield = 1 to fcount()
		lcfieldname = field(lnfield)
		if Upper(lcfieldname) = "IMAC_ID" then
			lcimacid = curval(lcfieldname)
		endif
		if oldval(lcfieldname) <> eval(lcfieldname) then
		lcfieldname = field(lnfield)
		lcchanges = lcchanges + lcfieldname + ": ";
			+ transform(eval(lcfieldname)) ;
			+ chr(13) + chr(10) 			
	endif
	next
case tctriggertype = "U"
	for lnfield = 1 to fcount()
	lcfieldname = field(lnfield)
		if Upper(lcfieldname) = "IMAC_ID" then
			lcimacid = curval(lcfieldname)
		endif
		if oldval(lcfieldname) <> eval(lcfieldname) then
			lcchanges = lcchanges + lcfieldname + ": " ;
			+ transform(oldval(lcfieldname)) + " -> " ;
			+ transform(eval(lcfieldname)) ;
			+ chr(13) + chr(10) 			
		endif
	next
endcase

if empty(lcchanges) = .f. then
insert into myaudit;
	(tablename, username, trigtype, whenchang, changes, imac_id);
  values;
  	(lctable, lcusername, tctriggertype, datetime(), lcchanges, lcimacid)
endif
endproc
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform