Just to use your examples:
you should var scope your query name...
<cffunction name="getDetail" access="public" returntype="query">
<cfargument name="item" default="" required="yes" type="numeric" />
<cfset var qry_detail = ""/>
----query goes here----
<cfreturn qry_detail />
</cffunction>
then you can get that query elsewhere like so:
<cffunction name="getdescription">
<cfset var myQuery = getDetail(pass your item number) />
<cfif len(myQuery.DESCRIPTION) and myQuery.DESCRIPTION neq 0>
<cfreturn myQuery.DESCRIPTION>
</cfif>
</cffunction>
Aaron Lynch
www.InstantSpot.com
www.AaronJLynch.com
> <cfargument name="item" default="" required="yes"
> type="numeric" />
> <cfset qry_detail = "">
> <cfquery name="qry_detail" datasource="#variables.datasource#">
> SELECT TITLE, DESCRIPTION FROM mytable WHERE item = <cfqueryparam
> cfsqltype="cf_sql_integer" value="#arguments.item#" />
> </cfquery>
> </cffunction>
On Tue, 2007-10-16 at 17:33 -0400, Kevin wrote:
> I have been trying to teach myself cfc's and I am having trouble
> understanding this.
>
> I know you should var scope any variables that are available only to
> the instance in a call to a method.
>
> But should they always be scoped locally?
> eg.
>
> I have a function in a products.cfc
>
> <cffunction name="getdetail" access="public" returntype="query">
> <cfargument name="item" default="" required="yes" type="numeric" />
> <cfset qry_detail = "">
> <cfquery name="qry_detail" datasource="#variables.datasource#">
> SELECT TITLE, DESCRIPTION FROM mytable WHERE item = <cfqueryparam
> cfsqltype="cf_sql_integer" value="#arguments.item#" />
> </cfquery>
> </cffunction>
>
> I have another function in the same cfc that uses the query to get a
> field if it has a value.
>
> <cffunction name="getdescription">
> <cfif len(qry_detail.DESCRIPTION) and qry_detail.DESCRIPTION neq 0>
> <cfreturn qry_detail.DESCRIPTION>
> </cfif>
> </cffunction>
>
> And i just call it in the .cfm with #products.getdescription()#.
>
> Now I have been reading that if the var scope is not used on the
> query, a race condition can happen.
>
> But if I use
> <cfset var qry_detail = "">
> qry_detail.DESCRIPTION is not available to the getdescription function.
>
> Can a query used like this cause a race condition? Or should I redo
> the functions to contain the query only within var scope the cfc?
>
> Thanks ahead.
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CFCDev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cfcdev?hl=en
-~----------~----~----~----~------~----~------~--~---