Ajas:
I am not an expert on how CF actually executes, but I am pretty darn
sure that the assumption you have is wrong.
<cfoutput>getSomething.col1 <br /> getSomething.col2 <br />
getSomething.col3 <br /> </cfoutput>
Is not re-executing the query. Once the query is run once, assuming
the query is not in a loop itself, then it's done. It only runs once.
If the original coder found that there was always only a single
record, then there is no harm in the code you have. However, it's not
great practice.
If there is any chance of ever having more than one record from that
query then your first code snip is best (<cfoutput
query="getSomething"> col1 <br /> col2 <br /> col3 <br /> </
cfoutput>), and in general, is a better idea.
I'm sure that Charlie or someone else can chime in on how CF handles
the record set in memory and how it's referenced, etc., My guess would
be that it's always better to use structured code or an actual
structure of some kind (list, array, structure) to reference multiple
record within a query. I think the question is also similar to the
old, which is better, CFLOOP or CFOUTPUT.
_____________________
Derrick Peavy
[email protected]
404-786-5036
“Innovation distinguishes between a leader and a follower.” -Steve Jobs
"A good deal that used to be a great deal, is not nearly as good as an
awful deal that was once a horrible deal." - Dan Gilbert, http://bit.ly/8gUruX
_____________________
On Feb 3, 2010, at 10:20 PM, Ajas Mohammed wrote:
Hi,
I came across code like this
<cfquery name="getSomething" datasource="test">
select col1,col2,col3 from tbl where condition
</cfquery>
Now, instead of using <cfoutput query="getSomething"> col1 <br />
col2 <br /> col3 <br /> </cfoutput>,
the code uses <cfoutput>getSomething.col1 <br /> getSomething.col2
<br /> getSomething.col3 <br /> </cfoutput>
The code in blue would do ONLY ONE CALL to query and display results.
My take is that, the code in red is executing the query every time
col1 thru col3 are referenced with query name. Is this correct? Also
if getSomething was a cfprocresult name, the stored proc would be
executed for every reference to stored proc name.colname right?
Thanks,
<Ajas Mohammed />
http://ajashadi.blogspot.com
We cannot become what we need to be, remaining what we are.
No matter what, find a way. Because thats what winners do.
You can't improve what you don't measure.
Quality is never an accident; it is always the result of high
intention, sincere effort, intelligent direction and skillful
execution; it represents the wise choice of many alternatives.