> I think for readability returning the values in a
> structure is going
> to do a.k.a S.Isaac
> <cfset data = myCFC.getQueries()>
> <cfloop query="data.getUsers">...</cfloop>
> <cfloop query="data.getRoles">...</cfloop>
> But the idea of going through a function to get the
> different
> recordsets, and referencing via the array would mean that
> there is no
> need to know the name of the queries? defently beneficial.
> Cheers everyone for you help
Another option is if your object has persistence and that persistence
is maintained via a caching mechanism, that you could simply execute
the stored procedure on an as-needs basis, and then use separate
methods to return the individual record-sets from the stored
procedure... as an example:
<cfcomponent>
<cffunction name="getSP" access="private">
<cfargument name="refresh" type="boolean" default="false">
<cfif refresh or not isdefined("variables.spr")>
<cfset variables.spr = structnew()>
<cfstoredproc procedure="mySP" ...>
<cfprocresult name="variables.spr.set1" result="1">
<cfprocresult name="variables.spr.set2" result="2">
</cfstoredproc>
</cfif>
<cfreturn variables.spr>
</cffunction>
<cffunction name="getSet1" access="public">
<cfreturn getSP().set1>
</cffunction>
<cffunction name="getSet2" access="public">
<cfreturn getSP().set2>
</cffunction>
</cfcomponent>
In this example, the caching mechanism is internal to the CFC, which
is useful if you expect the methods might be called multiple times
during a single page request (or within a single custom tag call) --
although it doesn't address the more wide-scale issue of caching the
object incrementally in memory for the duration of a session or the
application for true scalability.
In general, I tend to view the multiple result sets returned from a
stored procedure as being somewhat antithetical to the idea of a
method or a function in general -- that is that a function accepts
potentially multiple inputs to produce a singular output. I think of
them as being like a funnel. The stored procedure is a many-to-many
process, accepting potentially multiple inputs and producing
potentially multiple outputs. More like a tree which has roots
branching out at the bottom (input) and branches and leaves at the top
(output).
And in general what I know of "encapsulation" says that things should
largely fallow the model of functions -- the black box (component)
doesn't require you to know how the internals work -- you provide
multiple inputs and get back a singular result. Put the car in reverse
(input 1) and step on the gas (input 2) and the car backs up (singular
result). You may know how the engine works to accomplish this, but
that knowledge is irrespective of your ability to produce the singular
desired result of backing the car.
In a lot of cases we do end up returning structures from functions,
but in general my thinking is that if it's possible to return a
structure, then in most cases, particularly when the content of the
structure is varied and complex such as queries, there should also be
a consistent syntax to produce any of the individual values in that
structure independent of the structure itself, whether that's
getNameOfStructureKey() or getProperty("nameOfStructureKey") (my
preference). At this point the function which returns the structure is
merely a convenience afforded for the sake of processes which utilize
a large amount of the returned data at once, rather than needing only
certain discrete bits of it.
s. isaac dealey 954.522.6080
new epoch : isn't it time for a change?
add features without fixtures with
the onTap open source framework
http://macromedia.breezecentral.com/p49777853/
http://www.sys-con.com/story/?storyid=48229&DE=1
http://www.sys-con.com/story/?storyid=44477&DE=1
http://www.sys-con.com/story/?storyid=45569&DE=1
http://www.sys-con.com/story/?storyid=48229&DE=1
http://www.fusiontap.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble
Ticket application
http://www.houseoffusion.com/banners/view.cfm?bannerid=48
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:197331
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54