Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Is this a bug in CF 8

Guest
Feb 02, 2009 Feb 02, 2009
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 ?.
484
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 02, 2009 Feb 02, 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/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 02, 2009 Feb 02, 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 03, 2009 Feb 03, 2009
Qais wrote:
> 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. If there is someone here in this forum from Adobe
> can I get a clear answer if this SHOULD scoped or not.

>

Yes, scoping is considered a best practice. Inside an <cfoutput...>
block, ColdFusion will look in the named query *first*, but it does not
stop there. If the value is not found in the query, then it will look
into other scopes in a defined and documented order.

Outside of an <cfoutput...>, i.e., in your first example with a
<cfloop...> I suspect the query is not the first scope looked into.

http://www.adobe.com/devnet/server_archive/articles/using_cf_variables2.html#scopes
http://www.chapter31.com/2008/03/28/evaluating-coldfusion-unscoped-query-variables/
http://www.oreillynet.com/pub/a/oreilly/web/news/coldfusion_0701.html

Not exactly a hidden secret here.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 03, 2009 Feb 03, 2009
Of course I should have started with the documentation.
http://livedocs.adobe.com/coldfusion/8/htmldocs/Variables_32.html
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 03, 2009 Feb 03, 2009
I'm confused here, forget about the code I put before, let's talk about this example now:
<cfoutput query= ......>
#column_name#
</cfoutput>

so if I don't put it as

<cfoutput query= ......>
#query_name.column_name#
</cfoutput>

then CF will start looking into different scopes of that column_name if it couldn't get a value !!!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 03, 2009 Feb 03, 2009
LATEST
It is the other way around.

<cfoutput query="aQry">
#aCol#
</cfoutput>

In this code CF will start with aQry and look for aCol inside of it, but
if aQry.aCol does not exist, then ColdFusion will also check any other
available scope for a variable names 'aCol' and if it finds one, use
that version.

In a better scoped version.
<cfoutput query="aQry">
#aQry.aCol#
</cfoutput>

Then ColdFusion will only search for #aQry.aCol# and if that variable
does not exist, it will properly throw an error, not use another "aCol"
that may be floating around.

Of course if you somehow have two ore more #aQry.aCol# variables hanging
around in different scopes then you should be more explicit in your
variable naming. I.E. #variables.aQry.aCol# or #session.aQry.aCol#.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Feb 03, 2009 Feb 03, 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).
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources