Maxrows Issue in CFQuery?
<cfquery name="test" datasource="www"> SELECT n.newsID, n.siteID FROM tblNews n WHERE siteID = <cfqueryparam value="starwars" cfsqltype="cf_sql_varchar"> </cfquery> <P>
<p><cfoutput>#test.recordCount#</cfoutput></p> <P>
<cfquery name="test" datasource="www" maxrows="-1"> SELECT n.newsID, n.siteID FROM tblNews n WHERE siteID = <cfqueryparam value="starwars" cfsqltype="cf_sql_varchar"> </cfquery> <P>
<p><cfoutput>#test.recordCount#</cfoutput></p> <P>
<cfquery name="test" datasource="www" maxrows="3"> SELECT n.newsID, n.siteID FROM tblNews n WHERE siteID = <cfqueryparam value="starwars" cfsqltype="cf_sql_varchar"> </cfquery> <P>
<p><cfoutput>#test.recordCount#</cfoutput></p> <P>
<cfquery name="test" datasource="www"> SELECT n.newsID, n.siteID FROM tblNews n WHERE siteID = <cfqueryparam value="starwars" cfsqltype="cf_sql_varchar"> </cfquery> <P>
<p><cfoutput>#test.recordCount#</cfoutput></p> <P>
<cfquery name="test" datasource="www" maxrows="-1"> SELECT n.newsID, n.siteID FROM tblNews n WHERE siteID = <cfqueryparam value="starwars" cfsqltype="cf_sql_varchar"> </cfquery> <P>
<p><cfoutput>#test.recordCount#</cfoutput></p>
On the first run, this returned:
391 <P>
391 <P>
3 <P>
3 <P>
3
Notice how the last two returned only the 3 rows even though they are identical to the first two queries. On a second pass, all the queries will only return 3. The only way to change this appears to be either 1) set an different explicit max rows number other than -1 or 2) set the max pooled statements for the DSN to 0 temporarily to reset it. The problem with solution 1 is rather obvious, and solution 2 only works until you use the maxrows attribute.
I know this code has worked in the past, and the unless it is somehow specific to all of our servers, the only other potential culprit at this point seems to be HotFix 2. In HotFix 2 they did make a change related to maxrows:
61508 - cfquery, cfstoredproc maxrows not passed to the JDBC driver (performance issue on large tables)
Could that be what has changed? Has anyone else run into this issue? I may be dense, but I cannot seem to figure out how you uninstall a hotfix, any suggestions? Just to note, I am running this against MS SQL Server 2000.
In my case, I tested it against Oracle and I'm using Enterprise edition in the multiserver configuration.
SELECT
SELECT n.newsID, n.siteID
FROM tblNews n
WHERE siteID = <cfqueryparam value="starwars" cfsqltype="cf_sql_varchar">
LIMIT 3
Rob, I am using MS SQL, which has SELECT TOP (count) and while that is one solution I have looked into, it means alot of code changes that really aren't necessary. Right now I am looking into whether HotFix 2 contained any fixes we actually needed and potentially rolling it back.
