• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

缓存类及打开数据库连接函数

发布: 2007-6-30 18:56 | 作者: admin | 来源: | 查看: 19次 | 进入软件测试论坛讨论

领测软件测试网 懒人的作品,我连长一点点的代码,都写成函数了。。。

用起来,可以偷懒,哈哈。。。


<%‘’@ LANGUAGE = VBScript CodePage = 936

Dim jz
Set jz=New jz_clsmain
jz.Cache_count=0
jz.web_name="华人中小企业资源网"

Class jz_clsmain

Public rs,conn,sql,db
Public web_name,t,t_s,t_h,cache
public i_0,i_1
public Reloadtime,CacheName,LocalCacheName,Cache_Data,Cache_count

Private Sub Class_Initialize()
ReDim db(4),conn(4),rs(4),sql(4)
ReDim t(20,4),t_s(20,3)
Reloadtime=14400*60
‘’CacheNameCacheName=Replace(Replace(Replace(Server.MapPath("/"),"/",""),":",""),"\","")
CacheName=request.servervariables("url")
CacheName=left(CacheName,instrRev(CacheName,"/"))&"jz"
Cache_count=1000
web_name="匠族"
end sub


Private Sub class_terminate()
i_1=LBound(db)
for i_0=0 to i_1
On Error Resume Next
‘’Response.Write(i_0&"<br/><br/>")
if isobject(rs(i_0)) then rs(i_0).close:set rs(i_0)=nothing
If IsObject(Conn(i_0)) Then Conn(i_0).Close:Set Conn(i_0) = Nothing
next
End Sub

Public Function tree_00(str_0)
dim i,Jz_temp(1)
for i=0 to str_0
Jz_temp(0)=Jz_temp(0)&Jz_temp(1)
Jz_temp(1)="../"
next
tree_00=Jz_temp(0)
end Function

public function conn_00(str_0,str_1)
str_1=tree_00(str_1)
db(str_0)="Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath(str_1&"data/data_"&str_0&".mdb")
‘’Response.Write(db(str_0))
end function

‘’str0=0-4<定义选择的DB(str0),并定义conn(str0)及rs(str0)>;str1=true,false<是否创建数据库连接>;str2=true,false<是否创建rs对象>;
Public Function c_r_s(str0,str1,str2)
On Error Resume Next
if str1 then
Set Conn(str0) = Server.CreateObject("ADODB.Connection")
conn(str0).open db(str0)
end if
if str2 then
set Rs(str0) = Server.CreateObject( "ADODB.Recordset" )
end if
End Function

Public Function c_r_o(str0,str1,str2)
Rs(str0).Open sql(str0), Conn(str0), str1, str2
If Err Then
err.Clear
Set conn(str0) = Nothing
Response.Write "数据库连接出错,请检查连接字串。"‘’注释,需要把这几个字翻译成英文。
Response.End
End If
End Function


Public Function c_r_e(str0,str1,str2)
On Error Resume Next
if str2 then
rs(str0).close
set rs(str0)=nothing
end if
if str1 then
conn(str0).close
set conn(str0)=nothing
end if
End Function

Public Property Let Name(ByVal vNewValue)
LocalCacheName = LCase(vNewValue)
End Property
Public Property Let Value(ByVal vNewValue)
If LocalCacheName<>"" Then
ReDim Cache_Data(2)
Cache_Data(0)=vNewValue
Cache_Data(1)=Now()
Cache_Data(2)=Reloadtime
Application.Lock
Application(CacheName & "_" & LocalCacheName) = Cache_Data
Application.unLock
Else
Err.Raise vbObjectError + 1, "jzCacheServer", " please change the CacheName."
End If
End Property
Public Property Get Value()
If LocalCacheName<>"" Then
Cache_Data=Application(CacheName & "_" & LocalCacheName)
If IsArray(Cache_Data) Then
Value=Cache_Data(0)
Else
Err.Raise vbObjectError + 1, "jzCacheServer", " The Cache_Data("&LocalCacheName&") Is Empty."
End If
Else
Err.Raise vbObjectError + 1, "jzCacheServer", " please change the CacheName."
End If
End Property

Public Function ObjIsEmpty()
app_count()
ObjIsEmpty=True
Cache_Data=Application(CacheName & "_" & LocalCacheName)
If Not IsArray(Cache_Data) Then Exit Function
If Not IsDate(Cache_Data(1)) Then Exit Function
If IsEmpty(Cache_Data(2)) Then Exit Function
If DateDiff("s",CDate(Cache_Data(1)),Now()) < (Cache_Data(2)) Then ObjIsEmpty=False

End Function

Public Sub DelCahe(MyCaheName)
Application.Lock
Application.Contents.Remove(CacheName&"_"&MyCaheName)
Application.unLock
End Sub

public sub app_count()
if Application.Contents.Count>Cache_count then
Application.Lock
Application.Contents.RemoveAll()
Application.unLock
end if
end sub

function fso_000(str0)
dim jz_cache,jz_fso,jz_path,jz_file
set jz_fso = Server.Createobject("Scripting.FileSystemObject")
jz_path = server.mappath(str0)
‘’Response.Write(jz_path)
set jz_file = jz_fso.opentextfile(jz_path, 1)
do until jz_file.AtEndOfStream
jz_cache=jz_cache&jz_file.ReadLine&vbCrlf
loop
fso_000=jz_cache
jz_file.close
set jz_file = nothing
set jz_fso = nothing
end function

sub replace_000(str0)
t_h=replace(t_h,str0,cache&"")
t_empty()
end sub

sub t_empty()
for i_0=0 to 20:for i_1=0 to 4

t(i_0,i_1)=empty

next:next
i_0=empty
i_1=empty
cache=empty
end sub

Public Function target(jz_target)
Select Case jz_target
case 0
jz_target=""
case 1
jz_target="target=""new"""
end select
target=jz_target
end function


End Class
%>

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网