Well I'm extending a current CFC that returns an object (struct of
resultsets - no worries not for remote use)

This wrapper CFC manages the resultset in session scope and carries a few
local methods I can execute on this subset of data...say for example I
wanted to re-sort one of the recordsets etc...

Is that crazy ?


-----Original Message-----
From: Sean A Corfield [mailto:[EMAIL PROTECTED]] 
Sent: Saturday, August 03, 2002 6:17 PM
To: CF-Talk
Subject: Re: cfreturn session.records ?

On Saturday, August 3, 2002, at 02:58 , Stacy Young wrote:
> If I have a CFC that stores its results in session scope is the data
> duplicated on the return or is the session data just referenced via 
> pointer
> of sorts?

It uses reference semantics. However, it's not really good practice to 
have CFCs store results in shared scopes - CFCs should be independent of 
their environment.

However, if the CFC stores things in session scope - why bother returning 
them at all? Why not just let the caller access session.stuff directly?

>   <cffunction name="getAccounts">

You should add returntype="query" for extra validation.

>             <cfquery name="session.test">
>             SELECT * FROM BLAH
>              </cfquery>
>             <cfreturn session.test>
>    </cffunction>

You'd be better off having the caller (only) know about the session scope 
and using a local variable inside the function:

        <cfset var test = 0/>
        <cfquery name="test">
                SELECT * FROM BLAH
        </cfquery>
        <cfreturn test/>

Then the caller would do:

        <cfinvoke component="accounts"
                method="getAccounts"
                returnvariable="session.aQuery"/>

if you wanted it to stay in session scope (the query is not copied, only a 
reference to it, so this is fast). Or, if you just wanted a local copy:

        <cfinvoke component="accounts"
                method="getAccounts"
                returnvariable="aQuery"/>

Note that since 'test' inside the function is declared with 'var', it will 
be a new copy for every invocation.

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood


______________________________________________________________________
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to