2013年10月17日 星期四

foxpro-gen_log for mysql which field change

clos data
set dele on
set memo to 200
use edward in 0
use result in 0
STORE 'EMPLOYEE' TO MMM
*EMPLOYEE
sele edward
r=''
scan for allt(name)=MMM and active
s0=allt(zdatabase)
s1=allt(label)
r=r+'IF (NEW.'+s0+' <> OLD.'+s0+') OR (NEW.'+s0+' IS NOT NULL AND OLD.'+s0+' IS NULL) OR (NEW.'+s0+' IS NULL AND OLD.'+s0+' IS NOT NULL) THEN'++chr(13)
r=r+"if (NEW."+S0+" <> OLD."+S0+") then"+chr(13)
r=r+" set logs=CONCAT(logs,'"+S0+" [ ' ,OLD."+S0+" ,'->', NEW."+S0+",']');"+chr(13)
r=r+"end if; "+chr(13)
r=r+"if (NEW."+S0+" IS NOT NULL AND OLD."+S0+" IS NULL) then"+chr(13)
r=r+" set logs=CONCAT(logs,'"+S0+" [ ' ,'NULL' ,'->', NEW."+S0+",']');"+chr(13)
r=r+"end if;"+chr(13)
r=r+"if (NEW."+S0+" IS NULL AND OLD."+S0+" IS NOT NULL) then "+chr(13)
r=r+" set logs=CONCAT(logs,'"+S0+" [ ' ,OLD."+S0+" ,'->', 'NULL',']');"+chr(13)
r=r+"end if; "+chr(13)
r=r+" set logs=CONCAT(logs,' ,');"+chr(13)
r=r+'END IF; '+chr(13)+chr(13)
endscan
sele result
locate for allt(name)==mmm
if not found()
insert into result (name) values (mmm)
endif
replace mysqllog with r
return r

沒有留言:

張貼留言