中国开发网: 论坛: 程序员情感CBD: 贴子 391984
茶壶: .....................................
<%

'On Error Resume Next
'Set asplogobj = Server.CreateObject("AspLog.CoTAspLog")

sub asplog(s)
'asplogobj.log s,1
response.write s&"<BR/>"
end sub





Class c_db

Private SQLCommand
Private rsData
Dim Conn
Dim strConn


Private Sub Class_Initialize ' 设置 Initialize 事件。

strConn="Provider=SQLOLEDB.1;user id=sa;password=;Initial Catalog=LERP;Data Source=."
Set Conn=Server.CreateObject("ADODB.Connection")
Conn.ConnectionString=strConn
Conn.Open
asplog "Class_Initialize"
Set rsData=Server.CreateObject("ADODB.Recordset")
sqlWhere=""
End Sub


Private Sub OpenSql

'response.Write("SQL=["+CStr(sqlCommand)+"]")
asplog "SQL=["+CStr(sqlCommand)+"]"

rsData. Open SQLCommand, conn, 1, 1

end sub

public function isEmpty()
if (rsData.Eof and rsData.Bof) then
isEmpty=true
else
isEmpty=false
end if
end function

Public Function testsql(aid)
SQLCommand="declare @tbinfo table (fid int ,fdata int)"
SQLCommand=SQLCommand & " insert @tbinfo values (1,1111)"
SQLCommand=SQLCommand & " insert @tbinfo values (2,2222)"
SQLCommand=SQLCommand & " insert @tbinfo values (3,3333)"
SQLCommand=SQLCommand & " insert @tbinfo values (4,4444)"
SQLCommand=SQLCommand & " insert @tbinfo values (5,5555)"

SQLCommand=SQLCommand & " declare @cid int "
SQLCommand=SQLCommand & " set @cid=" & Cstr(aid)
'--@cid==1,5 bad; 2,3,4 ok
cid=5
SQLCommand=""
SQLCommand=SQLCommand & " select a.*,isnull(b.fprevid,-1) fprevid,isnull(c.fnextid,-2) fnextid "
SQLCommand=SQLCommand & " from (SELECT * FROM tbInfo where fID="&cid&" ) a "
SQLCommand=SQLCommand & " left join (select top 1 "&cid&" as fid,fid as fprevid from tbinfo where fid<"&cid&" order by fprevid desc) b on a.fid=b.fid "
SQLCommand=SQLCommand & " left join (select top 1 "&cid&" as fid,fid as fnextid from tbinfo where fid>"&cid&" order by fnextid) c on a.fid=c.fid "

'注释下面行,就是执行复杂的sql,不注释,就是执行简单的sql
'SQLCommand="select "&Cstr(aid)&" as fd"

OpenSQL
asplog "recordcount="&Cstr(rsData.recordcount)

if isempty() then
asplog "test=empty!"
testsql=0
else
asplog "test=not empty!"
testsql=1
end if
'rsData.close
end function


Private Sub Class_Terminate ' 设置 Terminate 事件。
' conn.close
asplog "Class_Terminate"
End Sub

End Class




asplog "[[[" '这个输出了
Set db=new c_db '这个类的初始化log输出了
asplog "22222" '这个输出了
t=db.testsql(1)
asplog "testsql ret="&cstr(t) '这个没有输出!
asplog "]]]" '这个没有输出!
'然后就是这个类的终止的log输出

response.Write("TestSQL")
%>

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录