主要用于从数据库字段设计字典的文档中,生成三重对应关系的字段名:
数据库内部的字段名(可以做到无数据字典时,外人难以猜测其含义);编写代码时用的变量名(也可以作为表单的字段名);显示在界面上给用户看的文字含义名称
英文识别词分别为:DataName, CodeName, ShowName
另外,还可以用于在返回查询结果中,生成字段所对应的SELECT里的序号,例如
SELECT abID,abTitle
此时 abID的序号为0, abTitle的序号为1
SELECT abTitle,abID
此时 abTitle的序号为0, abID的序号为1
有了以下的代码,在编程时这只需要输入CodeName即可自动对应会相应的序号,而无需逐个去数。
这通常用在rs.GetRows的返回数组里,例如:
rs.open "SELECT abTitle,abID ..."
d=rs.GetRows
with ReturnObj
Response.Write d(.abTitle,0)
end with
假如没有ReturnObj,那么你就需要严格注意字段的序号了,例如d(1,0)
<%
class clsQGentor
public TheSplit,TheTail
private sall
Private Sub Class_Initialize()
On Error Resume Next
Set sall=New cls_StrCat_Q__
TheSplit=","
On Error GoTo 0
End Sub
public function reset()
sall.Reset
end function
public function addnew(arr)
if not IsArray(arr) then
if VarType(arr)=8 then sall()=arr
if Len(TheTail)>0 then sall()=TheTail
exit function
end if
dim u,i
u=UBound(arr)
if Len(TheSplit)>0 then
sall()=arr(0)
for i=1 to u
sall()=TheSplit
sall()=arr(i)
next
else
sall()=arr(0)
for i=1 to u
sall()=arr(i)
next
end if
if Len(TheTail)>0 then sall()=TheTail
end function
public function append(arr)
if not IsArray(arr) then
if VarType(arr)=8 then sall()=arr
exit function
end if
dim u,i
u=UBound(arr)
for i=0 to u
sall()=arr(i)
next
end function
public function return()
return=sall()
end function
public function getido(exn,arr)
On Error Resume Next
if not IsArray(arr) then
exit function
end if
dim u,i,s,o
set o=nothing
set s=new cls_StrCat_Q__
s()="On Error Resume Next"
s()=vbcrlf
s()="class "
s()=exn
s()=vbcrlf
u=UBound(arr)
for i=0 to u
s()="Function "
s()=arr(i)
s()=":"
s()=arr(i)
s()="="
s()=i
s()=":End Function "
s()=vbcrlf
next
s()="end class"
s()=vbcrlf
s()="On Error GoTo 0"
ExecuteGlobal s()
Execute "set o=new "&exn
Set getido=o
On Error GoTo 0
end function
end class
'字符串拼接类本模块私用版
Class cls_StrCat_Q__
Private aFStrings()
Private iFSPos,iFSLen,iFSIncr
Private Sub Class_Initialize()
On Error Resume Next
iFSIncr = STRCATBUF
If Err Then iFSIncr = 200 : Err.Clear
Reset
On Error GoTo 0
End Sub
Private Sub Class_Terminate()
Erase aFStrings
End Sub
Public Property Let Item(ByRef sData)
If iFSPos > iFSLen Then
iFSLen = iFSPos + iFSIncr
ReDim Preserve aFStrings(iFSLen)
End If
aFStrings(iFSPos) = sData
iFSPos = iFSPos + 1
End Property
Public Default Property Get Item()
Item = Join(aFStrings, "")
End Property
Public Property Get IsInit()
If iFSPos=0 Then IsInit=True Else IsInit=False
End Property
Public Sub Reset()
iFSPos = 0
iFSLen = iFSIncr
ReDim aFStrings(iFSLen)
End Sub
Public Property Get CloneArray()
Dim r
r=aFStrings
ReDim Preserve r(iFSPos-1)
CloneArray=r
End Property
End Class
'TODO : CodeMaker from lxdbdesign.xls
class ctb_lxArticleBase
Public prefix
Private m
Function getDataName(): m=0 : End Function
Function getShowName(): m=1 : End Function
Function getCodeName(): m=2 : End Function
Function getTableDataName(): getTableDataName="LXDAB00" : End Function
Function getTableCodeName(): getTableCodeName="lxArticleBase" : End Function
'Property Get \2() : Dim r : Select Case m : case 0 : r=prefix & "\1" : case 1 : r="\3" : case 2 : r="\2" : end select : \2=r : End Property
Property Get abID() : Dim r : Select Case m : case 0 : r=prefix & "ABA000" : case 1 : r="文章编号" : case 2 : r="abID" : end select : abID=r : End Property
Property Get abTitle() : Dim r : Select Case m : case 0 : r=prefix & "ABC001" : case 1 : r="文章标题" : case 2 : r="abTitle" : end select : abTitle=r : End Property
Property Get abContent() : Dim r : Select Case m : case 0 : r=prefix & "ABC002" : case 1 : r="文章内容" : case 2 : r="abContent" : end select : abContent=r : End Property
Property Get abClass() : Dim r : Select Case m : case 0 : r=prefix & "ABL003" : case 1 : r="文章类别" : case 2 : r="abClass" : end select : abClass=r : End Property
Property Get abIsDel() : Dim r : Select Case m : case 0 : r=prefix & "ABB004" : case 1 : r="文章删除" : case 2 : r="abIsDel" : end select : abIsDel=r : End Property
Property Get abDateA() : Dim r : Select Case m : case 0 : r=prefix & "ABD005" : case 1 : r="文章日期" : case 2 : r="abDateA" : end select : abDateA=r : End Property
Property Get abMemo() : Dim r : Select Case m : case 0 : r=prefix & "ABC006" : case 1 : r="文章备注" : case 2 : r="abMemo" : end select : abMemo=r : End Property
Property Get abFlagz() : Dim r : Select Case m : case 0 : r=prefix & "ABZ999" : case 1 : r="文章参数" : case 2 : r="abFlagz" : end select : abFlagz=r : End Property
end class
dim startime:startime=Timer
dim ab:set ab=new ctb_lxArticleBase
dim a,fs,k
set a=new clsQGentor
with ab
.getCodeName
'this can be make from the xls and emeditor's replace
fs=Array(.abID, .abClass, .abTitle, .abContent, .abIsDel, .abDateA, .abMemo, .abFlagz)
set k=a.getido("clsidx_" & .getTableCodeName ,fs)
'get an object content the field's sequence id, can be use to "rs.GetRows" from later code. example:
'd=rs.GetRows
'with k
'Response.Write d(.abID,0)
'Response.Write d(.abTitle,0)
'Response.Write d(.abDateA,0)
'end with
a.append "SELECT "
.getDataName
fs=Array(.abID, .abClass, .abTitle, .abContent, .abIsDel, .abDateA, .abMemo, .abFlagz) 'just copy from above
a.addnew(fs)
a.append " FROM "
a.append .getTableDataName
end with
Response.Write a.return
Response.Write "<hr>"
Response.Write k.abTitle
Response.Write "<hr>" & FormatNumber((Timer-startime)*1000,3)
%>