来自CFQUERY和CFIF比较的意外结果

时间:2016-11-09 11:36:47

标签: coldfusion railo lucee

这段代码正在生产中,根据使用情况阻止IP。触发了一个电子邮件,并执行了一个插入,其IP地址满足cfif条件。但是,当我在SQL编辑器中执行查询时,对于相同的IP,它将计数返回为0(即getNin​​eHundredCnt.maxDownload)。

这只发生在一个用户身上。它对其他用户来说很好用,每天有近1L用户访问该应用程序。任何人都可以帮忙解释它为什么会发生吗?

<cfquery name="getExcessiveUsageConfig" DATASOURCE="#arguments.datasrc#">
    SELECT * FROM ExcessiveUsageConfig
</cfquery>

<cfset usageLimitStruct.maxFifMinDownload = getExcessiveUsageConfig.MAXFIFMINDOWNLOAD >

<!---- This value is 900 and not changed --->
<cfquery name="getNineHundredCnt" DATASOURCE="#arguments.datasrc#">
   SELECT 
         ( select count(9)  
           from   downloads 
           where  download_time > dateadd(minute,-15,getdate()) 
           and    USER_IP = <cfqueryparam value="#remoteAddress#" cfsqltype="CF_SQL_VARCHAR">
        ) as maxDownload,
        ( select TOP 1 DATEDIFF(second, DOWNLOAD_TIME, GETDATE())  
          from   CAPTCHA 
          WHERE  USER_IP = <cfqueryparam value="#remoteAddress#" cfsqltype="CF_SQL_VARCHAR"> 
          and    Erights_sessionId = <cfqueryparam value="#arguments.erightsCookie#" cfsqltype="CF_SQL_VARCHAR">
          order by DOWNLOAD_TIME DESC
        ) as Ccheck 
</cfquery>


<cfif getNineHundredCnt.maxDownload gte usageLimitStruct.maxFifMinDownload>

   <cfquery name="checkToBlockIpExcessUsage" DATASOURCE="#arguments.dataAuthentication#">
      INSERT INTO DisabledIPs(IP,TIMEDISABLED)
      VALUES (<cfqueryparam value="#remoteAddress#" cfsqltype="CF_SQL_VARCHAR">,GETDATE())
   </cfquery>

     <cfmail from="xxx@xxx.com" to="xxx@xxx.com" subject="IP Blocked"  type="text">
     IP : #remoteAddress#
     Time : #currentTime#
     The IP has been blacklisted 
     </cfmail>

</cfif>

1 个答案:

答案 0 :(得分:3)

一种可能性是getNin​​eHundredCnt.maxDownload为0,usageLimitStruct.maxFifMinDownload也为0。输出值并验证。