ColdFusion bug or feature?

Consider this simple ColdFusion code (CFMX Ent 7.0.1.116466 and Oracle DB 8.1.7.4):

<cfquery name="q1" datasource="#dsn#">
    select rownum recnum
    from all_objects
    where rownum <= 3
</cfquery>

<cfloop query="q1">

    <cfquery name="q2" datasource="#dsn#">
        select rownum recnum
        from all_objects
        where rownum <= 3
    </cfquery> 

    Outside q2 loop: <cfoutput>#q1.recnum#</cfoutput>
    <br>

    <cfloop query="q2">
        Inside q2 loop: <cfoutput>#q1.recnum#</cfoutput>
        <br>
    </cfloop>
    <br>
</cfloop>

In this example, both q1 and q2 return three rows each (it does not matter which tables you use). Each row has one column, recnum, with a value of 1, 2, and 3. Now, I thought that the above code would output the following:

Outside q2 loop: 1
Inside q2 loop: 1
Inside q2 loop: 1
Inside q2 loop: 1

Outside q2 loop: 2
Inside q2 loop: 2
Inside q2 loop: 2
Inside q2 loop: 2

Outside q2 loop: 3
Inside q2 loop: 3
Inside q2 loop: 3
Inside q2 loop: 3

But it did not. Instead, here is what I got:

Outside q2 loop: 1
Inside q2 loop: 1
Inside q2 loop: 1
Inside q2 loop: 1

Outside q2 loop: 2
Inside q2 loop: 1
Inside q2 loop: 1
Inside q2 loop: 1

Outside q2 loop: 3
Inside q2 loop: 1
Inside q2 loop: 1
Inside q2 loop: 1 

Why is it that q1.recnum is stuck on the first row of q1 inside the q2 loop? What am I missing?

Related articles:


Tagged | Comments Closed | Trackbacks Closed