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

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


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值