Sql 使用ADODB.Command.Execute设置游标类型
有没有办法为我从Sql 使用ADODB.Command.Execute设置游标类型,sql,vbscript,asp-classic,sql-injection,adodb,Sql,Vbscript,Asp Classic,Sql Injection,Adodb,有没有办法为我从ADODB.Command.Execute获取的ADODB.RecordSet设置CursorType 我知道,如果我这样做,这是可能的: rs = Server.CreateObject("ADODB.RecordSet") rs.Open(cmd) 但是,我目前使用的是命令。使用参数执行,该参数自动处理?参数的各种数组,以实现安全插值。因此,使用RecordSet.Open似乎不是一个选项 具体来说,我的代码当前看起来像: function ExecuteSQL(conn,
ADODB.Command.Execute
获取的ADODB.RecordSet
设置CursorType
我知道,如果我这样做,这是可能的:
rs = Server.CreateObject("ADODB.RecordSet")
rs.Open(cmd)
但是,我目前使用的是命令。使用参数执行,该参数自动处理?
参数的各种数组,以实现安全插值。因此,使用RecordSet.Open
似乎不是一个选项
具体来说,我的代码当前看起来像:
function ExecuteSQL(conn, sql, args)
set ExecuteSQL_CmdObj = Server.CreateObject("ADODB.Command")
ExecuteSQL_CmdObj.CommandType = adCmdText
ExecuteSQL_CmdObj.CommandText = sql
ExecuteSQL_CmdObj.ActiveConnection = conn
if Ubound(args) = -1 then
set ExecuteSQL = ExecuteSQL_CmdObj.Execute
else
set ExecuteSQL = ExecuteSQL_CmdObj.Execute(,args)
end if
end function
如果我想维护相同的API,但同时控制CursorType
,如何实现这一点?答案是,就我所能确定的而言,使用ADODB.Command.Execute
,这是不可能的,但是使用ADODB.RecordSet.Open
使用ADODB.Command.Parameters
:
函数CreateSQLParameter(arg)
set param=Server.CreateObject(“ADODB.Parameter”)
选择TypeName(arg)
大小写“字符串”
参数类型=adVarChar
参数尺寸=长度(CStr(arg))
参数值=CStr(参数)
大小写“整数”
参数类型=一个整数
参数值=CLng(参数)
案件“双重”
参数类型=可添加
参数值=CDbl(参数)
其他情况
'13是“类型不匹配”错误代码
错误。未处理Raise(13,,,“Type'”和TypeName(arg)”。请将其支持添加到CreateSQLParameter中)
结束选择
设置CreateSQLParameter=param
端函数
函数CreateSQLCommand(sql,args)
set cmd=Server.CreateObject(“ADODB.Command”)
“从http://www.w3schools.com/asp/prop_comm_commandtype.asp.
'由于某些原因,adCmdText在我们的范围内未定义。
cmd.CommandType=1
cmd.CommandText=sql
对于i=Lbound(args)到Ubound(args)
set param=CreateSQLParameter(args(i))
cmd.Parameters.Append(param)
下一个
设置CreateSQLCommand=cmd
端函数
函数ExecuteSQL(conn、sql、args)
set cmd=CreateSQLCommand(sql,args)
set rs=Server.CreateObject(“ADODB.RecordSet”)
rs.Open(cmd,conn)
set ExecuteSQL=rs
端函数
以下是一种快速简便的方法:
Dim arrErrorCode(1,1)
Dim ArrayRS
On Error Resume Next
Set rsGetIPInfo = Server.CreateObject("ADODB.Recordset")
Set oCMD = Server.CreateObject("ADODB.Command")
sSQL = "SELECT * FROM RemoteIPInfo WHERE RemoteIP_ID = ?"
oCMD.ActiveConnection = oConnGlobal
oCMD.CommandText = sSQL
oCMD.CommandType = adCmdText
oCMD.CommandTimeout = 120
oCMD.Parameters.Append oCMD.CreateParameter("@RemoteIP_ID", adVarChar, adParamInput, ,RemoteIP_ID)
rsGetIPInfo.CursorLocation = adUseClient
rsGetIPInfo.Open oCMD, ,adOpenStatic, adLockReadOnly
GetIPInfoCount = rsGetIPInfo.RecordCount
If Not rsGetIPInfo.BOF And Not rsGetIPInfo.EOF Then
ArrayRS = rsGetIPInfo.GetRows()
End If
arrRowNumberIPInfo = Ubound(ArrayRS, 1)
If Err.Number > 0 Then
arrRowNumberErrorCode = Ubound(arrErrorCode, 1)
Response.Write("Error Number: ") & Err.Number & "<br>"
Response.Write("Error Description: ") & Err.Description & "<br>"
Response.Write("Error Source: ") & Err.Source & "<br>"
Err.Raise 13
Response.End
End If
rsGetIPInfo.Close
Set rsGetIPInfo = Nothing
On Error Goto 0
Dim ARRRORCODE(1,1)
昏暗的天空
出错时继续下一步
Set rsGetIPInfo=Server.CreateObject(“ADODB.Recordset”)
设置oCMD=Server.CreateObject(“ADODB.Command”)
sSQL=“从RemoteIPInfo中选择*,其中RemoteIP\u ID=?”
oCMD.ActiveConnection=oconglobal
oCMD.CommandText=sSQL
oCMD.CommandType=adCmdText
oCMD.CommandTimeout=120
oCMD.Parameters.Append oCMD.CreateParameter(“@RemoteIP_ID”,adVarChar,adParamInput,RemoteIP_ID)
rsGetIPInfo.CursorLocation=adUseClient
rsGetIPInfo.openOCMD、adOpenStatic、adLockReadOnly
GetIPInfo=rsGetIPInfo.RecordCount
如果不是rsGetIPInfo.BOF,也不是rsGetIPInfo.EOF,则
ArrayRS=rsGetIPInfo.GetRows()
如果结束
arrRowNumberIPInfo=Ubound(ArrayRS,1)
如果错误编号>0,则
arrRowNumberErrorCode=Ubound(ArrrorCode,1)
响应。写入(“错误号:”)&Err.Number&“
”
Response.Write(“错误描述:”)&Err.Description&“
”
Response.Write(“错误源:”)&Err.Source&“
”
呃,提高13分
答复.完
如果结束
rsGetIPInfo。关闭
设置rsGetIPInfo=Nothing
错误转到0
这个问题的另一种表述是:有没有一种方法可以自动处理记录集的变量数组?
参数与记录集。打开?其中的游标类型设置在哪里?命名常量未定义,因为VBScript不知道ADO的类型库,您必须告诉它-请参阅(关于元数据的部分
)。这种封装程度不是必需的。如果您设置一个命令,使用.Append(.CreateParameter(…)
在ADODB.command
的上下文中添加参数,并将所需的值传递给它,然后使用rs.Open()执行,则其工作方式完全相同
。但是,即使您设置了游标类型,该问题也会被忽略。游标类型在哪里?