tracker issue : CF-3808648

select a category, or use search below
(searches all categories and all time range)
Title:

Internal row pointer not correctly implemented in for(row in query)

| View in Tracker

Status/Resolution/Reason: To Fix//Investigate

Reporter/Name(from Bugbase): Adam Cameron / Adam Cameron (Adam Cameron)

Created: 08/20/2014

Components: Language

Versions: 11.0

Failure Type:

Found In Build/Fixed In Build: CF11_Final /

Priority/Frequency: Major / Some users will encounter

Locale/System: ALL / Platforms All

Vote Count: 2

Repro:
<cfscript>
// test.cfm

q = queryNew("id,data", "integer,varchar",[
	[11, "aa"],
	[22, "bb"],
	[33, "cc"]
]);
for (row in q){
	writeOutput("#q.currentRow#:#q.id#:#q.data#<br>"); // currentrow works, but others do no
}
</cfscript>

On Railo:
1:11:aa
2:22:bb
3:33:cc

On CF:
1:11:aa
2:11:aa
3:11:aa

The internal row pointer has been partially exposed just for the currentRow, but it doesn't work for fetching the data from the currentRow. If you're gonna implement *some* of the functionality; you need to implement all of it: it's poor / lazy language design not to. Railo has done the correct thing here.

-- 
Adam

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3808648

External Customer Info:
External Company:  
External Customer Name: Adam Cameron.
External Customer Email:  
External Test Config: My Hardware and Environment details:

Attachments:

Comments:

This is a duplicate of https://bugbase.adobe.com/index.cfm?event=bug&id=CF-3173191, sorry. But that one is closed with excuse of "can't be arsed doing the work properly" (or "as designed" as you guys like to frame it). Don't care which ticket you fix it against, but ought to be fixed. -- Adam
Comment by External U.
11335 | August 20, 2014 02:42:26 AM GMT
+1 - row.foo and q.foo should work identically within for(row in q)
Vote by External U.
11338 | November 23, 2014 10:10:44 PM GMT
Interesting. I use for(row in q) iteration over query objects quite a bit but never ventured to try to act on the "q" within the loop (I always treated it more like an array of structs iteration than a <cfoutput query="q"> iteration). That being said, I actually would have expected it to work just as it does now in ACF where q.data gives you the first row. This is how it works if you referenced "q.data" outside of the loop. What seems a bit odd to me is that currentRow index value is set on the q object and not the row. Since the currentRow index is on the query object it causes a problem if you have a nested for-in loops: The currentRow resets to 1 in every iteration of the parent for-in loop. See: http://trycf.com/editor/gist/d30aae9ded35bd8c4c69/acf11?theme=solarized_dark Note: Lucee works properly in this respect as it does not reset q.currentRow to 1 - though it still seems like the iteration index ought to be in the row (or in a separate var altogether).
Comment by External U.
11336 | October 01, 2015 12:11:49 PM GMT
Can you please confirm in what version of ColdFusion this is going to be implemented in. It says "to fix" but does not say which version.
Comment by External U.
11337 | January 25, 2016 08:23:37 AM GMT
+1
Vote by External U.
11339 | January 28, 2016 03:48:54 AM GMT