用vfp的数据库自动生成CursorAdapter类代码
第一次发贴,将我以前做的一个程序贴上来,不知道对大家是否有用,反正对我有用处,我经常在用。CursorAdapter类无论是用vfp自带的生成器,还是自己写代码,都非常麻烦,并且,如果修改了数据库中的表,又得改写代码。所以,我就写了个根据数据库自动生成CursorAdapter类的代码。现奖代码贴在下面。
使用说明:参数为vfp数据库名称如:。
程序代码:****使用方法:dbctoca("chaoshi"),chaoshi是vfp数据库的名字,即这个数据库为chaoshi.dbc
FUNCTION dbctoca(dbcname)
CLOSE DATABASES
OPEN DATABASE &dbcname EXCLUSIVE
DIMENSION gatables(1)
createc=""
gatables=''
m=ADBOBJECTS(gatables, "TABLE")
IF NOT EMPTY(m)
FOR i=1 TO m
USE gatables(i) EXCLUSIVE
SELECT gatables(i)
ziduan=AFIELDS(arrayname)
createc=createc+[PUBLIC CursorOb]+gatables(i)+CHR(13)
createc=createc+[CursorOb]+gatables(i)+[=createobject("CursorAdapter") ]+CHR(13)
createc=createc+[with CursorOb]+gatables(i)+CHR(13)
createc=createc+[.Alias ="]+[Cursor]+gatables(i)+["]+CHR(13)
createc=createc+[.DataSourceType ="Native"]+CHR(13)
createc=createc+[.DataSource ="]+dbcname+["]+CHR(13)
createc=createc+[.SelectCmd = "select * from ]+gatables(i)+["]+CHR(13)
createc=createc+[.KeyFieldList = "]+arrayname(1,1)+["]+CHR(13)
createc=createc+[.cursorschema="]
upfieldlist=[TmpList1=""]+CHR(13)
upnamelist=[TmpList2=""]+CHR(13)
FOR i2=1 TO ziduan
createc=createc+arrayname(i2,1)+SPACE(1)+arrayname(i2,2)+SPACE(1)
upfieldlist=upfieldlist+[TmpList1=TmpList1+"]+arrayname(i2,1)+[,"]+CHR(13)
upnamelist=upnamelist+[TmpList2=TmpList2+"]+arrayname(i2,1)+SPACE(1)+gatables(i)+[.]+arrayname(i2,1)+[,"]+CHR(13)
IF AT(arrayname(i2,2),[CNFQV])>0
createc=createc+[(]+ALLTRIM(STR(arrayname(i2,3)))+SPACE(1)
IF EMPTY(arrayname(i2,4))=.F.
createc=createc+ALLTRIM(STR(arrayname(i2,3)))
ENDIF
createc=createc+[)]
ENDIF
createc=createc+[,]
ENDFOR
createc=LEFT(createc,LEN(createc)-1)+["]++CHR(13)
upfieldlist=LEFT(upfieldlist,LEN(upfieldlist)-3)+["]+CHR(13)
upnamelist=LEFT(upnamelist,LEN(upnamelist)-3)+["]+CHR(13)
createc=createc+[.Tables ="]+gatables(i)+["]+CHR(13)
createc=createc+upfieldlist
createc=createc+[.UpdatableFieldList = TmpList1]+CHR(13)
createc=createc+upnamelist
createc=createc+[.UpdateNameList=TmpList2]+CHR(13)
createc=createc+[.CursorFill()]+CHR(13)
createc=createc+[.cursorrefresh]+CHR(13)
createc=createc+[ENDWITH]+CHR(13)
USE
ENDFOR
ENDIF
=STRTOFILE(createc,"cca.prg")&&输出到程序文件中。
CLOSE DATABASES
ENDFUNC









