Set oCon=CreateObject("Adodb.Connection")
Set oRecord1 =CreateObject("Adodb.Recordset")
Set oRecord2 =CreateObject("Adodb.Recordset")
'20070904增加对timestamp类型的判断,因为sqlserver2000中不用对它进行处理
'20070905,修改了查询条件:不对表dtproperties处理,
'2007917 sSql2查询的表信息中增加了主键的查询,目的是用于update时条件的判断
sSql1 = "select count(*) as totle from syscolumns c inner join systypes t on c.xusertype=t.xusertype left join sysproperties p on c.id=p.id and c.colid = p.smallid left join syscomments m on c.cdefault=m.id"&_
" where objectproperty(c.id,'IsUserTable')=1 and t.name!='timestamp' and object_name(c.id)<>'dtproperties' "
sSql2="SELECT (case when a.colorder=1 then d.name else '' end)表名, a.name 字段名, b.name 数据类型,COLUMNPROPERTY(a.id,a.name,'PRECISION') as 长度,(case when a.isnullable=1 then '1'else '0' end) 允许空,"&_
"isnull(e.text,'NULL') as 默认值, (case when (SELECT count(*) FROM sysobjects WHERE (name in (SELECT name FROM sysindexes WHERE (id = a.id) AND (indid in (SELECT indid FROM sysindexkeys "&_
"WHERE (id = a.id) AND (colid in (SELECT colid FROM syscolumns WHERE (id = a.id) AND (name = a.name))))))) AND (xtype = 'PK'))>0 then '1' else '0' end) 主键 FROM syscolumns a left join systypes b "&_
"on a.xtype=b.xusertype inner join sysobjects d on a.id=d.id and d.xtype='U' and d.name<>'dtproperties' left join syscomments e on a.cdefault=e.id left join sysproperties g on a.id=g.id AND a.colid = g.smallid "&_
"where b.name<>'timestamp' order by d.name,a.colorder"
If oCon.State = 0 Then
Reporter.ReportEvent micFail, "错误", "连接数据库失败,请检查数据库连接设置"
End If
oRecord1.Open sSql1,oCon
Do
If oRecord1("totle").Value <>"" Then
iCountRow = oRecord1("totle").Value
End If
oRecord1.MoveNext
Loop Until oRecord1.Eof=true
oRecord1.Close
Set oRecord1=Nothing
oRecord2.Open sSql2,oCon
If bMoreTable = 0 Then
ReDim aTableDesc(iCountRow)
aTableDesc(0) = "表名"&"~"&"字段名"&"~"&"数据类型"&"~"&"长度"&"~"&"允许空"&"~"&"默认值"&"~"&"主键"
Do
If iNum - 1<iCountRow Then
aTableDesc(iNum) = oRecord2("表名").Value&"~"&oRecord2("字段名").Value&"~"&oRecord2("数据类型").Value&"~"&oRecord2("长度").Value&"~"&oRecord2("允许空").Value&"~"&oRecord2("默认值").Value&"~"&oRecord2("主键").Value
iNum = iNum +1
End If
oRecord2.MoveNext
Loop Until oRecord2.Eof=true
Else
ReDim aTableDesc(500)
aTableDesc(0) = "表名"&"~"&"字段名"&"~"&"数据类型"&"~"&"长度"&"~"&"允许空"&"~"&"默认值"&"~"&"主键"
If iStartTable = 0 Then
i = 0
Do
If iNum - 1<iCountRow Then
aTableDesc(iNum) = oRecord2("表名").Value&"~"&oRecord2("字段名").Value&"~"&oRecord2("数据类型").Value&"~"&oRecord2("长度").Value&"~"&oRecord2("允许空").Value&"~"&oRecord2("默认值").Value&"~"&oRecord2("主键").Value
iNum = iNum +1
If oRecord2("表名").Value <>"" Then
i = i + 1
End If
If i = iTableCount Then
oRecord2.MoveNext
iNum = iNum +1
For j = 0 To 150
If oRecord2("表名").Value = "" Then
aTableDesc((iNum+j)-1) = oRecord2("表名").Value&"~"&oRecord2("字段名").Value&"~"&oRecord2("数据类型").Value&"~"&oRecord2("长度").Value&"~"&oRecord2("允许空").Value&"~"&oRecord2("默认值").Value&"~"&oRecord2("主键").Value
Else
Exit For
End If
oRecord2.MoveNext
Next
End If
End If
oRecord2.MoveNext
Loop Until i = iTableCount
Else
j = 0
i = 0
Do
If oRecord2("表名").Value <>"" Then
j = j + 1
End If
If oRecord2.Eof=true Then
j = iStartTable
End If
oRecord2.MoveNext
If j = iStartTable Then
oRecord2.MoveNext
For k = 0 To 150
If oRecord2("表名").Value <> "" Or oRecord2.Eof=true Then
Exit For
End If
oRecord2.MoveNext
Next
End If
Loop Until j = iStartTable
oRecord2.MovePrevious
Do
If iNum - 1<iCountRow Then
aTableDesc(iNum) = oRecord2("表名").Value&"~"&oRecord2("字段名").Value&"~"&oRecord2("数据类型").Value&"~"&oRecord2("长度").Value&"~"&oRecord2("允许空").Value&"~"&oRecord2("默认值").Value&"~"&oRecord2("主键").Value
iNum = iNum +1
If oRecord2("表名").Value <>"" Then
i = i + 1
End If
If oRecord2.Eof=true Then
i = iTableCount
End If
If i = iTableCount Then
oRecord2.MoveNext
iNum = iNum +1
For j = 0 To 150
If oRecord2("表名").Value = "" Then
aTableDesc((iNum+j)-1) = oRecord2("表名").Value&"~"&oRecord2("字段名").Value&"~"&oRecord2("数据类型").Value&"~"&oRecord2("长度").Value&"~"&oRecord2("允许空").Value&"~"&oRecord2("默认值").Value&"~"&oRecord2("主键").Value
If oRecord2.Eof=true Then
Exit For
End If
Else
Exit For
End If
oRecord2.MoveNext
Next
End If
End If
oRecord2.MoveNext
Loop Until i = iTableCount
End If
End If
oRecord2.Close
Set oRecord2=Nothing
oCon.Close
Set oCon=Nothing
iNum = 0
For i = 0 To UBound(aTableDesc)
If aTableDesc (i) <> "" Then
iNum = iNum + 1
End If
Next
aTempArray = aTableDesc
ReDim aTableDesc(iNum - 1)
For i = 0 To iNum-1
aTableDesc (i) = aTempArray (i)
Next
GetTableInfo = aTableDesc
End Function作者: erwinsun 时间: 2008-6-24 17:03 标题: 接上 '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
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作者: erwinsun 时间: 2008-6-24 17:03 标题: 续 If k=1 Then
dd=0
End If
If aTempArray(6) =1 Then
aFlag3(k)=1
dd=dd+1
aPrim2(k,0)="插入字段可为空时主键的值"'1012新增
'918修改,用于不记录相同的随机数
m=1
While m<>nFiledCount
If m=1 Then
aPrim2(k,m)=StructureDataTypeVaule(aTempArray(2),aTempArray(3))
m=m+1
Else
nn=1
Resu=StructureDataTypeVaule(aTempArray(2),aTempArray(3))
While nn<=m-1 and aPrim2(k,nn)<>Resu
nn=nn+1
Wend
If nn=m Then
aPrim2(k,m)=Resu
m=m+1
Else
m=m
End If
End If
Wend
Else
aFlag3(k)=0
End If
If k = nFiledCount Then '此处修改了
If k<>dd Then'用到的变量dd,它是记录该表的主键数目
'917新增,找到一个非主键的字段,同时增加一个标志qq,否则会是死循环,还有不能直接对k操作,否则同样会进入外部FOR循环的死循环
nn=k
qq=0
While aFlag3(nn)=1 and nn>=1 and qq=0
nn=nn-1
If aFlag3(k-1)=1 Then
nn=nn-1
Else
qq=1
End If
Wend
aTempArray = Split(aTableDesc(i+nn-1), "~", -1, 1)
sUpdateValue = aTempArray(1)&"~"&StructureDataTypeVaule(aTempArray(2),-3)'917修改,为了update操作成功,将此语句中的"aTempArray(3)"换成-3,转到赋值那边返回个不同值
Else
aTempArray = Split(aTableDesc(i+k-1), "~", -1, 1)
sUpdateValue = aTempArray(1)&"~"&StructureDataTypeVaule(aTempArray(2),aTempArray(3))
End If
End If
Else
Exit For
End If
Next作者: erwinsun 时间: 2008-6-24 17:05 标题: 续 aTempArray = Split(aTableValue(1), "~", -1, 1)
aTempFiledString = aTempArray(0)
aTempValuesString = aTempArray(1)
tt1=0 '该变量用于标记第一个字段是否处理过,1表示处理过
If aFlag(1)=1 Then
Else
sCondition3 = aTempFiledString&" = "&aTempValuesString
tt1=1
End If
'919新增,当表中第一个及后面几个都是该过滤掉的时候,该变量tt2记录最后一个过滤字段的位置,tt3是标记是否第一个可作update的条件
tt2=1
tt3=0
For l = 2 To UBound(aTableValue)
If aTableValue(l)<>"" Then '此处增加了表中值是否为空的判断
aTempArray = Split(aTableValue(l), "~", -1, 1)
aTempFiledString = aTempFiledString&","&aTempArray(0)
aTempValuesString = aTempValuesString&","&aTempArray(1)
If aFlag(l)=1 Then
tt2=l
Else
If aFlag(l-1)=1 and l-tt2=1 and tt3=0 and tt1=0 Then '914新增,因为当表中第一个字段刚好为过滤时,若不在此加条件,之后的update的条件里面会有上个表的字段
sCondition3 = aTempArray(0)&"= "&aTempArray(1)
tt3=1
Else
sCondition3 = sCondition3&" and "&aTempArray(0)&"= "&aTempArray(1)
End If
End If
Else
Exit For
End If
Next
'907新增对字段的值可为空的处理
m=1
k=1
j=1
While m<>nFiledCount +1 '这里应该用该表有多少个字段来做条件
aTempArray = Split(aTableValue(m), "~", -1, 1)
If aFlag2(m)=0 and aTempArray(2)=1 Then
'下面对i之前处理过的字段赋值
For k=1 To m-1
If aTableValue(k)<>"" Then '此处增加了表中值是否为空的判断
aTempArray = Split(aTableValue(k), "~", -1, 1)
If k=1 Then
aTempFiledString1(j)=aTempArray(0)
If aFlag3(k)=1 Then'917新增,如果该字段为主键,则赋不同的值
aTempValuesString1(j) = aPrim2(k,j)
Else
aTempValuesString1(j) = aTempArray(1)
End If
Else
aTempFiledString1(j)=aTempFiledString1(j)&","&aTempArray(0)
If aFlag3(k)=1 Then
aTempValuesString1(j) = aTempValuesString1(j)&","&aPrim2(k,j)
Else
aTempValuesString1(j) = aTempValuesString1(j)&","&aTempArray(1)
End If
End If
Else
Exit For
End If
Next
'下面是对i对应的本字段处理,不给它赋值
aTempArray = Split(aTableValue(m), "~", -1, 1)
If m=1 Then
Else
aTempValuesString1(j) = aTempValuesString1(j)
End If
aFlag2(m)=1
'对i之后的字段正常赋值
For l = m+1 To UBound(aTableValue) '这里循环次数要修改
If aTableValue(l)<>"" Then '此处增加了表中值是否为空的判断
aTempArray = Split(aTableValue(l), "~", -1, 1)
If l=2 Then'这样有问题,当前面的aTempFiledString1(j)已经有值时,这样会丢失掉之前的值
aTempFiledString1(j)=aTempArray(0)
If aFlag3(l)=1 Then
aTempValuesString1(j)=aPrim2(l,j)'1012这个地方再研究一下
Else
aTempValuesString1(j) = aTempArray(1)
End If
Else
aTempFiledString1(j)=aTempFiledString1(j)&","&aTempArray(0)
If aFlag3(l)=1 Then
aTempValuesString1(j) = aTempValuesString1(j)&","&aPrim2(l,j)'aPrim((j-1)*nIsNullFiledCount +l)
Else
aTempValuesString1(j) = aTempValuesString1(j)&","&aTempArray(1)
End If
End If
Else
Exit For
End If
Next
'下面是对i(包括i字段)之前处理过的字段,让它们正常赋值
Else
End If
m=m+1
'910修改,当此次循环中aTempValuesString1数组值为空时,下标不往下移动
If aTempValuesString1(j)=Empty Then
Else
j=j+1
End If
Wend作者: erwinsun 时间: 2008-6-24 17:06 标题: 续 aTableSql(Num) = "insert into "&sTableName&" ("&aTempFiledString&") "&"values ("&aTempValuesString&")"
Num = Num + 1
aTempArray = Split(sUpdateValue, "~", -1, 1)
aTableSql(Num) = "update "&sTableName&" set "&aTempArray(0)&" = "&aTempArray(1)&" where "&sCondition3
Num = Num + 1
aTempArray1 = Split(sCondition3, " and ", -1, 1)
For m = 0 To UBound(aTempArray1)
aTemp1 = Split(aTempArray1(m), " = ", -1, 1)
If aTemp1(0)= aTempArray(0) Then
aTemp2 = Split(sUpdateValue, "~", -1, 1)
sUpdateValue = aTemp2(0)&" = "&aTemp2(1)
aTempArray1(m) = sUpdateValue
End If
Next
'delete条件由aFlag最后一位来确定,当最后一位为要过滤的字段时,delete条件沿用update的条件;否则,只要update中set中那个字段及值就可以了
If aFlag( UBound(aFlag))=1 Then
Else
sCondition3=aTempArray(0)&" = "&aTempArray(1)
End If
aTableSql(Num) = "delete from "&sTableName&" where "&sCondition3
Num = Num + 1
'907新增对可空字段,每个都插入一条数据
n=1
While n<>nFiledCount+1 and aTempValuesString1(n)<>Empty '这里可能越界,所以在定义该aTempValuesString时,空间放大点, and
aTableSql(Num) = "insert into "&sTableName&" ("&aTempFiledString1(n)&") "&"values ("&aTempValuesString1(n)&")"
Num = Num + 1
n=n+1
Wend
aTempArray = Split(sUpdateValue1, "~", -1, 1)
aTableSql(Num) = "update "&sTableName&" set "&aTempArray1(0)&" where "&sCondition3
Num = Num + 1
End If
Next
Case 2
Case 3
End Select
Num = 0
For i = 0 To UBound(aTableSql)
If aTableSql (i) <> "" Then
Num = Num + 1
End If
Next
aTempArray1 = aTableSql
ReDim aTableSql(Num - 1)
For i = 0 To Num-1 '914修改,原先为 i = 0 To Num -1
aTableSql (i) = aTempArray1 (i)
Next
StructureSql = aTableSql
End Function作者: erwinsun 时间: 2008-6-24 17:06 标题: 续 Function StructureDataTypeVaule(FiledType,nFiledLen)
Select Case FiledType
Case "bigint"
If nFiledLen<>-3 Then
If nFiledLen <=12 Then '1014修改,因为当长度超过12位时,sqlserver2000里面用科学计数表示时,只是精确到小数点后11位,这样如果它为主键,且不处理,有时会报主键不能重复插入相同值的错误。
For k=1 To nFiledLen-3
strTemp="2"&strTemp
Next
Randomize
iTemp = Int((999 * Rnd) + 1)
strTemp=strTemp&CStr(iTemp)
RetValue=CDbl(strTemp)
Else
strTemp="222222"
Randomize
iTemp = Int((999 * Rnd) + 1)
strTemp=strTemp&CStr(iTemp)
RetValue=CDbl(strTemp)
End If
Else
RetValue=888
End If
Case "binary"
If nFiledLen<>-3 Then
If nFiledLen>=3 Then '修改,因为有时遇到binary长度小于3的情况
For k = 1 To nFiledLen-3
If k=197 Then'916新增
Exit For
Else
strTemp = "1"&strTemp
End If
Next
If k>=nFiledLen-3 Then '916增
Randomize
iTemp = Int((999 * Rnd) + 1)
strTemp=strTemp&CStr(iTemp)
RetValue="convert(binary("& nFiledLen&"),'0x"&strTemp&"')"
Else
Randomize
iTemp = Int((999 * Rnd) + 1)
strTemp=strTemp&CStr(iTemp)
RetValue="convert(binary("&k-1&"),'0x"&strTemp&"')"
End If
Else '相对于If nFiledLen>=3 Then
RetValue="convert(binary(1),'0x1')"
End If
Else ' 相对于If nFiledLen<>-3 Then
RetValue="convert(binary(1),'0x6')"
End If
Case "bit"
If nFiledLen<>-3 Then
RetValue=1
Else
RetValue=0
End If
Case "char"
If nFiledLen<>-3 Then
If nFiledLen<=3 Then '919新增当nFiledLen小于3时的情况,不过这种情况一般很少
If nFiledlen=1 Then
Randomize '1014修改,本来是用字符的,不过当长度为1,且为主键时,用数字字符方便处理
iTemp = Int((9 * Rnd) + 1)
RetValue="'"&CStr(iTemp)&"'"
Else
Randomize '1014修改,本来是用字符的,不过当长度为2到3,且为主键时,用数字字符方便处理
iTemp = Int((99 * Rnd) + 1)
RetValue="'"&CStr(iTemp)&"'"
End If
Else
For k = 1 To nFiledLen-3'917修改,留出三位空间给主键的赋值使用
strTemp = "a"&strTemp
Next
Randomize
iTemp = Int((999 * Rnd) + 1)
RetValue="'"&strTemp&CStr(iTemp)&"'"
End If
Else
strTemp="b" '注意 ,在此只赋一个值的用途:1.给更新的字段赋值;2.当更新字段恰好只为一个长度时,能避免赋其他值时碰到的长度不匹配
RetValue="'"&strTemp&"'"
End If
Case "datetime"
If nFiledLen<>-3 Then
strTemp="1753-10-1 20:"
strTemp1=":12"
Randomize '1014修改,因为有将datetime类型设置为主键的情况
iTemp = Int((45* Rnd) + 1)
RetValue="'"&strTemp&CStr(iTemp)&strTemp1&"'"
' RetValue=CDate(strTemp)
Else
strTemp="'1853-10-1 20:45:12'"
RetValue=strTemp
End If
Case "decimal"
If nFiledLen<>-3 Then
If nFiledLen<9 Then '1014修改,因为有可能定义的长度小于9,且为主键,不处理,会报错
Randomize
iTemp = Int((99 * Rnd) + 1)
RetValue=CDbl(iTemp)
Else
For k=1 To nFiledLen/2-3
strTemp="2"&strTemp
next
Randomize
iTemp = Int((999 * Rnd) + 1)
RetValue=CDbl(strTemp&CStr(iTemp))
End If
Else
strTemp="0"
RetValue=CDbl(strTemp)
End If
Case "float"
If nFiledLen<>-3 Then
strTemp="1234567"
Randomize
iTemp = Int((999 * Rnd) + 1)
RetValue=CDbl(strTemp&CStr(iTemp))
Else
strTemp="11111111"
RetValue=CDbl(strTemp)
End If
'image类型处理
Case "image"
If nFiledLen<>-3 Then
strTemp="111111111111111111111111111"
Else
strTemp="888"
End If
RetValue="'"&strTemp&"'"
Case "int"
If nFiledLen<>-3 Then
Randomize
RetValue = Int((999* Rnd) + 1)
Else
RetValue=0
End If
Case "money"
If nFiledLen<>-3 Then
strTemp="8223372035477.5807"
Else
strTemp="666666.123"
End If
RetValue=CCur(strTemp)
Case "nchar"
If nFiledLen<>-3 Then
For k = 1 To nFiledLen-3
strTemp="b"&strTemp
Next
Randomize
iTemp = Int((999 * Rnd) + 1)
RetValue="'"&strTemp&CStr(iTemp)&"'"
Else
strTemp="cc"
RetValue="'"&strTemp&"'"
End If
Case "ntext" '没有定义长度
If nFiledLen<>-3 Then
RetValue = "'cccccccccccccccccccc'"
Else
RetValue = "'aaaaa'"
End If作者: erwinsun 时间: 2008-6-24 17:07 标题: 续 Case "numeric"
If nFiledLen<>-3 Then
If nFiledLen<>18 Then '这样处理时因为定义numeric类型的字段时,当不采用默认的情况下,读出的长度和精度在显示表信息那里没有处理。所以这里暂时这样处理
Randomize
iTemp = Int((99* Rnd) + 1)
RetValue="'"&strTemp&CStr(iTemp)&"'"
Else
For k=1 To nFiledLen-3
strTemp="2"&strTemp
next
Randomize
iTemp = Int((999 * Rnd) + 1)
RetValue="'"&strTemp&CStr(iTemp)&"'"
End If
Else'相对于 If nFiledLen<>-3 Then
strTemp="1111"
RetValue=CDbl(strTemp)
End If
Case "nvarchar"
If nFiledLen<>-3 Then
For k = 1 To nFiledLen-3
If k=200 Then '916修改,因为当表同时还有varchar类型时,且都达到他们的最大,那么在运行插入语句时,报"无法创建大小为8084的行,该值最大允许8060"
Exit For
Else
strTemp="d"&strTemp
End If
Next
Randomize
iTemp = Int((999 * Rnd) + 1)
RetValue="'"&strTemp&CStr(iTemp)&"'"
Else
strTemp="g"
RetValue="'"&strTemp&"'"
End If
Case "real"
If nFiledLen<>-3 Then
For k=1 To nFiledLen
strTemp="2"&strTemp
next
Else
strTemp="9"
End If
RetValue=CSng(strTemp)
Case "smalldatetime"
If nFiledLen<>-3 Then
strTemp="1900-1-1 20:45"
Else
strTemp="1999-1-1 20:45"
End If
RetValue="'"&strTemp&"'"
Case "smallint"
If nFiledLen<>-3 Then
Randomize
RetValue = Int((999* Rnd) + 1)
Else
RetValue=888
End If
Case "smallmoney"
If nFiledLen<>-3 Then
strTemp="200000"
Else
strTemp="100000"
End If
RetValue=CCur(strTemp)
Case "sql_variant"
If nFiledLen<>-3 Then
strTemp="'1900-1-1 20:45'"
Else
strTemp="'1999-1-1 20:45'"
End If
RetValue=strTemp
Case "text"
If nFiledLen<>-3 Then
RetValue = "'eeeeeeeeeeeeeeeeeee'"
Else
RetValue = "'zzz'"
End If
'timestamp不用处理,每次更新表的时候,系统自动插入一个时间戳
Case "tinyint"
If nFiledLen<>-3 Then
Randomize
iTemp = Int((255 * Rnd) + 1)
RetValue=iTemp
Else
RetValue=100
End If
Case "uniqueidentifier"
If nFiledLen<>-3 Then
strTemp="67EE7C0B-989D-46FB-8657-36088FC6C20B"
Else
strTemp="7D8146EE-88D6-4F36-BBD8-1090DD045860"
End If
RetValue="'"&strTemp&"'"
Case "varbinary" '914修改,让该类型的字段直接插入为本16进制的数据
If nFiledLen<>-3 Then
For k = 1 To nFiledLen
If k=100 Then '916增
Exit For
Else
strTemp = "1"&strTemp
End If
Next
If k>nFiledLen Then '916增
RetValue="convert(varbinary("& nFiledLen&"),'0x"&strTemp&"')"
Else
RetValue="convert(varbinary("&k-1&"),'0x"&strTemp&"')"
End If
Else
RetValue="convert(varbinary(6),'0x111111')"
End If
Case "varchar"
If nFiledLen<>-3 Then
For k = 1 To nFiledLen-3
strTemp="h"&strTemp
Next
If nFiledLen<=3 Then '919新增当nFiledLen小于3时的情况,不过这种情况一般很少
Randomize '1014修改,本来是用字符的,不过当长度小于3,且为主键时,用数字字符方便处理
iTemp = Int((9 * Rnd) + 1)
RetValue="'"&CStr(iTemp)&"'"
Else
Randomize
iTemp = Int((999 * Rnd) + 1)
RetValue="'"&strTemp&CStr(iTemp)&"'"
End If
Else
strTemp="v"
RetValue="'"&strTemp&"'"
End If
End Select
StructureDataTypeVaule = RetValue
' msgbox(typename(RetValue)) '检测返回值类型
End Function作者: erwinsun 时间: 2008-6-24 17:08 标题: 续 Function ExecSql(aTableSql)
Dim oCon,sSql1
Set oCon=CreateObject("Adodb.Connection")
'Set fso = CreateObject("Scripting.FileSystemObject")
'Set MyFile = fso.CreateTextFile("c:\ExecSQLs.txt", True)
'在以下修改数据库的连接,指定数据库服务器名(SERVER、WSID)、帐号(UID)、密码(PWD)、项目使用的数据库(DATABASE)
oCon.Open "Description=db1;DRIVER=SQL Server;SERVER=erwin\erwin;UID=erwinWD=erwin;DATABASE=Test1"
If oCon.State = 0 Then
Reporter.ReportEvent micFail, "错误", "连接数据库失败,请检查数据库连接设置"
End If
'记录执行的SQL语句数
' i = 655
i = 0
While i < UBound(aTableSql)
'每次执行10条SQL语句
For j = 0 To 10
If j = 0 Then
oCon.BeginTrans
'MyFile.WriteLine "Begin Tran abc"
End If
If i = UBound(aTableSql) Then
Exit For
Else
sSql1 = aTableSql(i)
oCon.Execute sSql1
'MyFile.WriteLine sSql1
i=i+1
End If
Next
oCon.CommitTrans
'MyFile.WriteLine "Commit Tran abc"
' oCon.RollbackTrans
Services.ThinkTime(2)
Wend
oCon.Close
Set oCon=Nothing
End Function作者: 没有蛀牙 时间: 2008-6-24 17:09
先顶一把吧
谢谢楼主分享,还没细看作者: kakamissyou 时间: 2008-6-24 21:32 标题: 什么垃圾玩艺 什么垃圾玩艺作者: caodongjian 时间: 2008-6-24 23:28
LZ.最好整一个TXT文件.呵呵.这样好一些作者: wzdoxu 时间: 2008-6-25 09:31
就是啊,楼主应该整理成一篇文档,这样可以方便别人阅读!作者: cebio 时间: 2010-12-13 17:40 本帖最后由 cebio 于 2010-12-13 17:41 编辑