2013年11月28日 星期四

foxpro getdao


para p_name
store 'VENDOR' TO P_NAME
CLOS DATA
set dele on
use result in 0
use gendao in 0
sele gendao
SET FILTER TO tableNAME=P_NAME
replace all ftype with 'BIG' FOR 'INT' $ FIELD1
REPLACE ALL FIELD1 WITH ALLT(FIELD1)
REPLACE ALL FIELD1 WITH STRTRAN(FIELD1,space(4),'')
replace ALL fieldname with  STRT(SUBS(FIELD1,AT('TABLE',FIELD1)+5),'(','') , ZTYPE WITH 'TABLE' for 'TABLE' $ FIELD1
replace all fieldname with allt(fieldname)
replace all fieldname with strt(allt(fieldname),chr(9),'')
replace ALL classname  with  proper(fieldname) for 'TABLE' $ FIELD1
replace all fieldname with  LEFT(FIELD1,AT(' ',FIELD1)),ZTYPE WITH 'FIELD'  for (not 'TABLE' $ FIELD1) and (not 'ENGINE' $ FIELD1)
replace all ZTYPE WITH 'ENGINE'  for  'ENGINE' $ FIELD1
*replace all zvariable with  lower(fieldname) for ztype='FIELD'
replace all zvariable with  lower(fieldname)
replace all varName with "seqNum" for zvariable='msg_seq_no'
replace all varName with t2v(zvariable) for (not zvariable='msg_seq_no')
replace ALL classname with upper(left(varName,1))+subs(varName,2)  for ztype='FIELD' or ztype='TABLE'
sele gendao
scan
do case
case aarray(field1,1,' ')='RECORDID'
replace fieldtype with "bigint(20) NOT NULL DEFAULT '0'"
other
if aarray(field1,2,' ')='C'
replace fieldtype with 'NVARCHAR('+aarray(field1,3,' ')+") DEFAULT ''"
endif
if aarray(field1,2,' ')='D'
replace fieldtype with 'DOUBLE DEFAULT 0'
endif
if aarray(field1,2,' ')='I'
replace fieldtype with 'INTEGER DEFAULT 0'
endif

if aarray(field1,2,' ')='F'
replace fieldtype with 'FLOAT DEFAULT 0'
endif
endcase
Endscan

select result
locate for name=p_name
if not found()
insert into result (name) value (p_name)
endif
store  createtable() to _r
replace in result createtab with _r
sele result
brow
sele gendao
set filter to
*brow field field1:30,tablename:30,fieldname:30,classname:30, varname:30,fieldtype:30
function createtable()
r= ''
select gendao
_delimiter=''
quota='"'
quota2="+"
scan
if ztype='TABLE'
r=r+quota+"create table "+allt(tablename) +' ( '+quota+quota2+chr(13)
else
r=r +quota+ _delimiter+allt(fieldname)+' '+ALLT(fieldtype)+quota+quota2+chr(13)
_delimiter=','
endif
endscan
r=r+quota+','+ "PRIMARY KEY (`RECORDID`)"+quota+quota2
r=r+quota+');'+quota+";"+chr(13)
return r

function t2v()
para p_1
for i=0 to 25
p_1=strt(p_1,'_'+chr(97+i),chr(65+i))
endfor
r=p_1
return r

沒有留言:

張貼留言