» Fig Leaf Software Home

We've Got You Covered.

Wednesday, September 11, 2013

When a ColdFusion query object is not a ColdFusion query object (or is not treated as such)


I ran into an problem using recordcount with an embedded query using ColdFusion 10.  Consider the following code snippet:

1. <cfset qquery= querynew("ConferenceName,Cost,Date,location")>
2. <cfset success= queryaddrow(qquery,1)>

3. <cfset querysetcell(qquery,"ConferenceName","ColdDusion Rocks",qquery.recordcount)>
4. <cfset querysetcell(qquery,"Cost","$100",qquery.recordcount)>
5. <cfset querysetcell(qquery,"Date","October 1, 2013",qquery.recordcount)>
6. <cfset querysetcell(qquery,"location",querynew("city,state,country"),qquery.recordcount)>

7. <cfset success = queryaddrow(qquery.location,1)>
8. <cfset querysetcell(qquery.location,"city","Chicago",1)>
9. <cfset querysetcell(qquery.location,"state","Illinois",1)>
10. <cfset querysetcell(qquery.location,"country","USA",1)>

11. <cfdump var="#qquery#">
12. <cfdump var="#isquery(qquery.location)#">
13. <cfdump var="#qquery.location.recordcount#">

14. <cfset locationquery = qquery.location>
15. <cfoutput>Location query contains #locationquery.recordcount# record</cfoutput>


A new query is being created and one of the cells in the query is itself a query.  Lines 11 and 12 dump the query and indicate whether the embedded query is actually recognized as a query and generate this output:





However, line 13 generates this error:





The workaround is to set a variable equal to the embedded query and evaluate the recordcount for that variable as is done in lines 14 and 15 that generates the output "Location query contains 1 record".


No comments:

Post a Comment

About Us

Fig Leaf Software is an award-winning team of imaginative designers, innovative developers, experienced instructors, and insightful strategists.

For over 20 years, we’ve helped a diverse range of clients...

Read More

Contact Us

202-797-7711

Fig Leaf Software

1400 16th Street NW
Suite 450
Washington, DC 20036

info@figleaf.com