Skip to main content
February 2, 2009
Question

Is this a bug in CF 8

  • February 2, 2009
  • 2 replies
  • 567 views
I have the following code (just as a sample):

<CFQUERY NAME="MyProjects" DATASOURCE="DSN_Name">
select PID, PName from projects
</CFQUERY>

Assume the above query will bring only one record, I'm using CF 8 with latest hot fix, running on windows server 2003 machine, with MSSQL 2005.

Now if I try simply just to print this PID (PID is a primary key set by the table) as below:
<cfoutput>
<cfloop query="MyProjects">
#PID#
</cfloop>
<cfoutput>

Now to run the above code in a stress test with 10 concurrent users, this PID could bring NULL, while if I write it this way with same type of test it doesn't break and it doesn't bring NULL

<cfoutput>
<cfloop query="MyProjects">
#MyProjects.PID#
</cfloop>
<cfoutput>

Is this a bug in CF or maybe the JDBC drivers ? Is it scoping issue ? ... anyone notice this before ?.
    This topic has been closed for replies.

    2 replies

    Participating Frequently
    February 3, 2009
    > then CF will start looking into different scopes of that column_name if it couldn't get a value !!!

    Not exactly. If you spell column_name correctly, it will find a corresponding variable in the query scope.

    Where it comes in handy to scope your variables is if you misspell it. Let's say you have a query with a column named "passwd", and a local variable named "password". If you happen to do this:
    <cfoutput query="myquery">
    #password#
    </cfoutput>

    Coldfusion will happily pull the local variable and display it for you. If, however, you scoped that column name:
    <cfoutput query="myquery">
    #myquery.password#
    </cfoutput>

    Coldfusion will throw an error telling you that the variable is undefined (because we misspelled the column name).
    Inspiring
    February 2, 2009
    1) you do not need to use <cfoutput><cfloop query=...> construct. just
    use <cfoutput query="..."> instead

    2) it is always a good idea to scope your vars, so #MyProjects.PID# is a
    good way to reference your query var. if you use the construct from #1
    above you do not really need to scope your var with a query name, since
    inside a query output (<cfoutput query="...">) cf always first checks
    for requested var in the query scope anyway.

    run your tests using
    <cfoutput query="MyProjects">
    #PID#
    </cfoutput>
    construct and see if you get the undefined var error.


    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    February 3, 2009
    Thanks for your reply, I know I can do it as <cfoutput query= ......> but I have a friend which told me that if you don't scope a column name by the name of the query, like query_name.column_name and this column name just by chance exists as a variable in another scope (like session or application or ...etc.) and with a stress test it could jump and read that other value in the other scope.

    My understanding for CF since before until today that when you print a query like
    <cfoutput query= ......>
    #column_name#
    </cfoutput>
    then CF will look into ONLY that recordset and will not go further and make a search into other scopes. I hope there is someone here in this forum from Adobe that can give me clear answer if this SHOULD scoped or not.