Title:
Nested cfloops with less records than outer loop cause “array index out of range” error
| View in TrackerStatus/Resolution/Reason: Closed/Fixed/
Reporter/Name(from Bugbase): Sam Daams / Sam Daams (Sam I Am)
Created: 09/08/2014
Components: Language
Versions: 10.0
Failure Type: Non Functioning
Found In Build/Fixed In Build: Final /
Priority/Frequency: Normal / All users will encounter
Locale/System: English / Platforms All
Vote Count: 6
Problem Description:
When nesting cfloops, a grouped cfloop with an inner loop outputting less records than the outer cfloop will throw error "Array index out of range: xx", with xx being the recordcount of the second query.
Steps to Reproduce:
<cfscript>
selectContent = queryNew("h2,id,content", "varchar,integer,varchar", [
["one", 1, "content.1"],
["two", 2, "content.2"],
["three", 3, "content.3"],
["four", 4, "content.4"],
["five", 5, "content.5"],
["six", 6, "content.6"],
["seven", 7, "content.7"]
]);
selectPricing = queryNew("groupCol,description,price", "varchar,varchar,varchar", [
["groupCol.1", "description.1", "1.11"],
["groupCol.2", "description.2", "2.22"],
["groupCol.2", "description.3", "3.33"],
["groupCol.3", "description.4", "4.44"],
["groupCol.3", "description.5", "5.55"],
["groupCol.3", "description.6", "6.66"]
]);
</cfscript>
<cfloop query="selectContent">
<section>
#selectContent.h2#
<cfif selectContent.id eq 3>
<cfloop query="selectPricing" group="groupCol">
<table class="pricing">
<thead>
<tr>
<th>#description#</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<cfloop>
<tr>
<td>#selectPricing.description#</td>
<td>#selectPricing.price#</td>
</tr>
</cfloop>
</tbody>
</table>
</cfloop>
</cfif>
#selectContent.content#
</section>
</cfloop>
Actual Result:
Array index out of range: 6
Expected Result:
Query output as it should.
Any Workarounds:
* replace inner cfloop group with cfoutput group.
* stick a cfbreak on that third cfloop if the currentRow matches the recordcount.
----------------------------- Additional Watson Details -----------------------------
Watson Bug ID: 3820049
External Customer Info:
External Company:
External Customer Name: Sam I Am
External Customer Email:
External Test Config: My Hardware and Environment details: Coldfusion 10 on Mac 10.9.4
Attachments:
Comments: