您的位置:首页 > 数据库

用vfp的数据库自动生成CursorAdapter类代码

2012-10-13 19:14 204 查看
CursorAdapter类无论是用vfp自带的生成器,还是自己写代码,都非常麻烦,并且,如果修改了数据库中的表,又得改写代码。所以,我就写了个根据数据库自动生成CursorAdapter类的代码。现奖代码贴在下面。

使用说明:参数为数据库名称。

LPARAMETERS 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数据库 database table
相关文章推荐