我在Dreamweaver中创建了以下记录集,该记录集查找具有以下cat_id的所有计算机
<%
Dim rsTest
Dim rsTest_cmd
Dim Test_numRows
Set Test_cmd = Server.CreateObject ("ADODB.Command")
Test_cmd.ActiveConnection = MM_test_STRING
Test_cmd.CommandText = "SELECT * FROM machinery WHERE main_site='yes' AND(Cat_id=13 OR Cat_id=14 OR Cat_id=15) ORDER BY Make"
Test_cmd.Prepared = true
Set Test = Test_cmd.Execute
Test_numRows = 0
%>
我希望有一个页面可以通过网址请求获取请求:
testpage.asp?=Cat_id=13&Cat_id=14&Cat_id=15
Dreamweaver只允许一个过滤器,它按如下方式设置recodset请求:
<%
Dim rsTest
Dim rsTest_cmd
Dim rsTest_numRows
Set rsTest_cmd = Server.CreateObject ("ADODB.Command")
rsTest_cmd.ActiveConnection = MM_Test_STRING
rsTest_cmd.CommandText = "SELECT * FROM machinery WHERE main_site='yes' AND cat_id = ? ORDER BY cut_off ASC"
rsTest_cmd.Prepared = true
rsTest_cmd.Parameters.Append rsTest_cmd.CreateParameter("param1", 5, 1, -1, rsTest__MMColParam) ' adDouble
Set Test = rsv_cmd.Execute
rsv_numRows = 0
%>
在此问题的记录集末端我需要做什么,每当我在URL字符串中输入多个请求时,我都会收到页面错误:
ADODB.Command error '800a0d5d'
Application uses a value of the wrong type for the current operation.
tespage.asp, line 19
第19行是;
rsTest_cmd.Parameters.Append rsTest_cmd.CreateParameter("param1", 5, 1, -1, rsTest__MMColParam) ' adDouble
非常感谢您花时间去寻找
答案 0 :(得分:1)
我担心你必须通过使用原始SQL来放置值来覆盖DreamWeaver来获得你想要的东西,所以你将失去对使用参数的保护。所以你必须自己清理数据。
首先,将此功能添加到您的代码中:
Function GetSafeArray(queryStringKey)
Dim arrItems(), x, y
Dim currentValue, blnExists
ReDim arrItems(-1)
For x=1 To Request.QueryString(queryStringKey).Count
currentValue = Request.QueryString(queryStringKey).Item(x)
If IsNumeric(currentValue) Then
blnExists = False
currentValue = CLng(currentValue)
For y=0 To UBound(arrItems)
If arrItems(y)=currentValue Then
blnExists = True
Exit For
End If
Next
If Not(blnExists) Then
ReDim Preserve arrItems(UBound(arrItems) + 1)
arrItems(UBound(arrItems)) = currentValue
End If
End If
Next
GetSafeArray = arrItems
End Function
该函数将返回仅包含查询字符串中的整数值的数组,而不是dupes。 SQL注入将失败,因为你无法仅使用数字来破解任何内容。
现在在你的情况下使用这个函数,有这样的代码:
Dim arrSafeValues, strSafeValues
arrSafeValues = GetSafeArray("Cat_id")
strSafeValues = Join(arrSafeValues, ", ")
Erase arrSafeValues
If Len(strSafeValues)=0 Then
Response.Write("Error: no valid values were given")
Else
Set Test_cmd = Server.CreateObject ("ADODB.Command")
Test_cmd.ActiveConnection = MM_test_STRING
Test_cmd.CommandText = "SELECT * FROM machinery WHERE main_site='yes' AND Cat_id IN (" & strSafeValues & ") ORDER BY Make"
Test_cmd.Prepared = true
Set Test = Test_cmd.Execute
Test_numRows = 0
End If