Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!--- start by building a new query object --->
- <cfset masterQuery = QueryNew("ID,Name,SubQuery", "INTEGER,VARCHAR,OBJECT")>
- <!--- add a row and some basic data --->
- <cfset QueryAddRow(masterQuery)>
- <cfset QuerySetCell(masterQuery, "ID",1)>
- <cfset QuerySetCell(masterQuery, "Name", "Dave")>
- <!--- create a new sub query --->
- <cfset subQuery = QueryNew("TestColumn1,TestColumn2","VARCHAR,VARCHAR")>
- <!--- lets add a few rows to the subQuery --->
- <cfloop from="1" to="3" index="b">
- <!--- new row --->
- <cfset queryAddRow(subQuery)>
- <!--- subQuery data --->
- <cfset QuerySetCell(subQuery,"TestColumn1","Hello World")>
- <cfset QuerySetCell(subQuery,"TestColumn2","All Your Base are Belong to Us")>
- </cfloop>
- <!--- populate the master query column "subQuery" with the new query object we created --->
- <cfset QuerySetCell(masterQuery, "SubQuery", subQuery)>
- <!--- dump the data so we can make sure it looks good --->
- <cfdump var="#masterQuery#">
- <!--- now loop through the query, and assign all of the columns in the query to the variables scope --->
- <cfloop list="#masterQuery.columnList#" index="a">
- <cfset "VARIABLES.#a#" = masterQuery["#a#"]>
- </cfloop>
- <!--- this generates an error in CF 10 (maybe other versions) --->
- <cftry>
- <!--- try and run a QofQ --->
- <cfquery dbtype="query" name="getSubQuery">
- SELECT *
- FROM subQuery
- </cfquery>
- <cfdump var="#getSubQuery#">
- <cfcatch type="any">
- <cfdump var="ERROR: #cfcatch.Message#">
- </cfcatch>
- </cftry>
- <!--- Now try using evaluate() instead. This doesn't generate an error for some reason --->
- <cfloop list="#masterQuery.columnList#" index="a">
- <cfset "VARIABLES.#a#" = evaluate('masterQuery.#a#')>
- </cfloop>
- <!--- run the QofQ again --->
- <cfquery dbtype="query" name="getSubQuery">
- SELECT *
- FROM subQuery
- </cfquery>
- <cfdump var="#getSubQuery#">
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement