|
2#
楼主 |
发表于 2008-6-24 17:03:17
|
只看该作者
接上
'TestType测试类型,
'0:普通类型(操作包含:Insert每张表插入2条记录(所有字段内容,长度为定义的最大长度),Update (任意所有字段)2条2个字段记录,Delete一条记录)
'1:完全测试 测试类型(完全测试类型(操作包含:Insert:对每张表插入1条记录(所有字段内容,长度为定义的最大长度),另外对每个可为空的字段插入一条为空的记录,
' Update (更新每个字段)、delete:删除1条记录)
'2:性能测试,随机插入10000条记录,更新5000条记录,删除4000条记录
'3:所有类型 。
'默认类型为:0
Function StructureSql(aTableDesc,TestType)
Dim sTableName,sTempFiled,aTempArray,aTableValue,aTableValue1,aTableSql,nFiledCount,nTableCount,aTempFiledString,aTempValuesString,aTemp,aTempArray1,aFlag,aFlag2,aFlag3,aPrim,aPrim2
Dim aTempValuesString1,sUpdateValue,sUpdateValue1,sCondition,sCondition1,aTemp1,nIsNullFiledCount,aTemp2
Dim oCon
nFiledCount = 0
nTableCount = 0
nIsNullFiledCount = 0
Num = 0
If TestType <>0 Then
If TestType <>1 Then
If TestType <>2 Then
If TestType <>3 Then
TestType = 0
End If
End If
End If
End If
For i = 1 To UBound(aTableDesc)
aTempArray = Split(aTableDesc(i), "~", -1, 1)
If aTempArray(0) <> "" Then
nTableCount = nTableCount + 1
End If
Next
For i = 1 To UBound(aTableDesc)
aTempArray = Split(aTableDesc(i), "~", -1, 1)
If aTempArray(4) = "1" Then
nIsNullFiledCount = nIsNullFiledCount + 1
End If
Next
Select Case TestType
Case 0
ReDim aTableSql(5*nTableCount -1)'
For i = 1 To (UBound(aTableDesc))
nFiledCount = 0
aTemp = Split(aTableDesc(i), "~", -1, 1)
If aTemp(0) <> ""Then
aTempArray = Split(aTableDesc(i), "~", -1, 1)
sTableName = aTempArray(0)
If sTableName <> "" Then
For j = 0 To (UBound(aTableDesc))
If i + j < UBound(aTableDesc) Or i + j = UBound(aTableDesc) Then
If Left(aTableDesc(i+j) ,(Instr(1, aTableDesc(i+j) , "~", 1) -1) ) = "" or Left(aTableDesc(i+j) ,(Instr(1, aTableDesc(i+j) , "~", 1) -1) ) =sTableName Then
nFiledCount = nFiledCount + 1
Else
Exit For
End If
Else
End If
Next
End If
ReDim aTableValue(nFiledCount)
ReDim aTableValue1(nFiledCount)
ReDim aFlag(nFiledCount)
aTableValue(0) = "字段名"&"~"&"值"
aFlag(0)="标志位" '用于image ntext text的判断
For k = 1 To nFiledCount
If i+k-1< UBound(aTableDesc) Or i+k-1 = UBound(aTableDesc) Then
aTempArray = Split(aTableDesc(i+k-1), "~", -1, 1)
aTableValue(k) = aTempArray(1)&"~"&StructureDataTypeVaule(aTempArray(2),aTempArray(3))
aTableValue1(k) = aTempArray(1)&"~"&StructureDataTypeVaule(aTempArray(2),aTempArray(3))
If aTempArray(2) ="image" or aTempArray(2)="ntext" or aTempArray(2)="text" Then
aFlag(k)=1
Else
aFlag(k)=0
End If
If k = nFiledCount -1 Then
aTempArray = Split(aTableDesc(i+k-1), "~", -1, 1)
sUpdateValue = aTempArray(1)&"~"&StructureDataTypeVaule(aTempArray(2),aTempArray(3))
aTempArray = Split(aTableDesc(i+k), "~", -1, 1)
sUpdateValue = aTempArray(1)&"~"&StructureDataTypeVaule(aTempArray(2),aTempArray(3))
End If
Else
Exit For
End If
Next
aTempArray = Split(aTableValue(1), "~", -1, 1)
aTempFiledString = aTempArray(0)
aTempValuesString = aTempArray(1)
If aFlag(1)=1 Then
sCondition = aTempFiledString&" LIKE "&aTempValuesString
Else
sCondition = aTempFiledString&" = "&aTempValuesString
End If
aTempArray1 = Split(aTableValue1(1), "~", -1, 1)
aTempFiledString1 = aTempArray1(0)
aTempValuesString1 = aTempArray1(1)
'image 、 ntext 、 text在进行update delete时判断的条件格式特殊,当表中只有这三个类型的字段时,"LIKE"该去掉,因为用它还是会出错
If aFlag(1)=1 Then
sCondition1 = aTempFiledString1&" LIKE "&aTempValuesString1
Else
sCondition1 = aTempFiledString1&" = "&aTempValuesString1
End If
For l = 2 To UBound(aTableValue)
aTempArray = Split(aTableValue(l), "~", -1, 1)
aTempFiledString = aTempFiledString&","&aTempArray(0)
aTempValuesString = aTempValuesString&","&aTempArray(1)
If aFlag(l)=1 Then
sCondition = sCondition'&" and "&aTempArray(0)&" LIKE"&aTempArray(1),在此不对这些字段进行判断
Else
sCondition = sCondition&" and "&aTempArray(0)&"= "&aTempArray(1)
End If |
|