I don't know if this is a possible bug (or maybe i am doing something
wrong), but when using recursion with a query in the function scope
it is overwritten on the next call of the function. i did find a
workaround, but want to know is what is intended.
I have this function which orders sibilings from a result set that is
a hierarchacl tree of nodes with ids and parentids.(btw i know in
oracle 9i this functino exists, but we are running 8i) the query
looks like this:
<cfquery name="getStandardRet" datasource="test">
SELECT upper(name) as uppername, name,level as
depth,frameid,description,parentid
FROM sn_standard
START WITH frameid = '#arguments.key#'
CONNECT BY PRIOR frameid = parentid
</cfquery>
I call the orderbysibling function by passing the the parent of the
tree.
<cfset startid = getStandardRet["frameid"][1] />
<cfset orderedQuery =
QueryNew("frameid,parentid,depth,name,description") />
<cfset QueryAddRow(orderedQuery) />
<cfset
QuerySetCell(orderedQuery,"frameid",getStandardRet["frameid"][1])>
<cfset QuerySetCell(orderedQuery,"depth",getStandardRet["depth"][1])>
<cfset QuerySetCell(orderedQuery,"name",getStandardRet["name"][1])>
<cfset
QuerySetCell(orderedQuery,"description",getStandardRet["description"][1])>
<cfset
QuerySetCell(orderedQuery,"parentid",getStandardRet["parentid"][1])>
<cfset orderbySibling(startid) />
---orderbySibling function
<cffunction name="orderbySibling">
<cfargument name="nodeid" required="true" />
<cfquery name="qsiblings" dbtype="query">
select frameid,depth,name,description,parentid
from getStandardRet
where parentid = '#nodeid#'
order by uppername
</cfquery>
<cfloop query="qsiblings">
<cfset QueryAddRow(orderedQuery) />
<cfset QuerySetCell(orderedQuery,"frameid",qsiblings.frameid)>
<cfset QuerySetCell(orderedQuery,"depth",qsiblings.depth)>
<cfset QuerySetCell(orderedQuery,"name",qsiblings.name)>
<cfset
QuerySetCell(orderedQuery,"description",qsiblings.description)>
<cfset QuerySetCell(orderedQuery,"parentid",qsiblings.parentid)>
<cfset orderbySibling(qsiblings.frameid) />
</cfloop>
</cffunction>
--- this is the workaround
<cffunction name="orderbySibling">
<cfargument name="nodeid" required="true" />
<cfargument name="foo" required="false" />
<cfquery name="qsiblings" dbtype="query">
select frameid,depth,name,description,parentid
from getStandardRet
where parentid = '#nodeid#'
order by uppername
</cfquery>
<cfset arguments.foo = qsiblings />
<cfloop query="arguments.foo">
<cfset QueryAddRow(orderedQuery) />
<cfset
QuerySetCell(orderedQuery,"frameid",arguments.foo.frameid)>
<cfset QuerySetCell(orderedQuery,"depth",arguments.foo.depth)>
<cfset QuerySetCell(orderedQuery,"name",arguments.foo.name)>
<cfset
QuerySetCell(orderedQuery,"description",arguments.foo.description)>
<cfset
QuerySetCell(orderedQuery,"parentid",arguments.foo.parentid)>
<cfset orderbySibling(arguments.foo.frameid) />
</cfloop>
</cffunction>
To me it seems that the query(all variables of the function) should
be pushed onto the stack at each time the function is called. the
workaround is a hack that forces the query qsiblings to take a
different scope so that the data will be preserved as it comes up out
of the recursive calls. i have also noticed that if you use a
varialbe in the original calling scope that it is seen as a global
variable in the recursive function and not local to the scope of the
original calling function.
Does anyone know of a good document that it explains all of the
scopes in cfmx and their relationships?
tia,
jason
__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com
[Todays Threads]
[This Message]
[Subscription]
[Fast Unsubscribe]
[User Settings]
- RE: problems with recursion in cfmx Jason Wagstaff
- RE: problems with recursion in cfmx Adrian Lynch
- RE: problems with recursion in cfmx Adrian Lynch
- RE: problems with recursion in cfmx Jason Wagstaff
- RE: problems with recursion in cfmx Tim Blair
- RE: problems with recursion in cfmx Jason Wagstaff
- RE: problems with recursion in cfmx Adrian Lynch
- RE: problems with recursion in cfmx Raymond Camden