On 6/28/06, Cody Caughlan <[EMAIL PROTECTED]> wrote:
I like declaring one struct as local, e.g.
<cfset var local = StructNew()>
And then *all* my variables in a function get put into this struct, e.g. all loop counters, query
names, etc. *everything*.
This is great because once you start doing this and then later you look at code and you see a
variable that is all on its own, then you *KNOW* you have a possible problem with your method being
not thread-safe.
/Cody
Aaron Roberson wrote:
> Thanks guys, for some reason I missed that little detail. I spent at
> least an half hour trying to debug this error, that's the sad part.
>
> -Aaron
>
> On 6/28/06, Roland Collins <[EMAIL PROTECTED]> wrote:
>> You should also var your queryparam argument and scope all of the
>> arguments
>> in the body of the function. Like so:
>>
>>
>> <cffunction name="getArticles" access="public" returntype="query">
>>
>> <cfargument name="artID" required="no" type="numeric"
>> default=0>
>> <cfargument name="authID" required="no" type="numeric"
>> default=0>
>> <cfargument name="catID" required="no" type="numeric"
>> default=0>
>>
>> <cfset var queryparam = "">
>> <cfset var rsArticles = "">
>>
>> <cfif arguments.artID NEQ 0>
>> <cfset queryparam = " AND articles.artID =
>> #arguments.artID#">
>> </cfif>
>> <cfif arguments.authID NEQ 0>
>> <cfset queryparam = queryparam & " AND
>> articles.artauthor_ID =
>> #arguments.authID#">
>> </cfif>
>> <cfif arguments.catID NEQ 0>
>> <cfset queryparam = queryparam & " AND
>> articles.artcat_ID =
>> #arguments.catID#">
>> </cfif>
>>
>> <cfquery name="rsArticles" datasource="#variables.dsn#">
>> SELECT artID, artcat_ID, artauthor_ID, artTitle,
>> artDesc, artContent
>> FROM articles
>> WHERE articles.artActive = 1
>> #preservesinglequotes(queryparam)#
>> ORDER BY artID DESC
>> </cfquery>
>>
>> <cfreturn rsArticles>
>> </cffunction>
>>
>> -----Original Message-----
>> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On
>> Behalf
>> Of Aaron Roberson
>> Sent: Wednesday, June 28, 2006 6:32 PM
>> To: [email protected]
>> Subject: [CFCDev] Problem with local var in CFC methods
>>
>> I keep getting this error when I invoke my cfcs:
>>
>> "Local variable rsArticles on line 34 must be grouped at the top of
>> the function body"
>>
>> Here is what my method looks like:
>>
>> <cffunction name="getArticles" access="public"
>> returntype="query">
>>
>> <cfargument name="artID" required="no" type="numeric"
>> default=0>
>> <cfargument name="authID" required="no" type="numeric"
>> default=0>
>> <cfargument name="catID" required="no" type="numeric"
>> default=0>
>>
>> <cfparam name="queryparam" default="">
>>
>> <cfif artID NEQ 0>
>> <cfset queryparam = " AND articles.artID =
>> #arguments.artID#">
>> </cfif>
>> <cfif authID NEQ 0>
>> <cfset queryparam = queryparam & " AND
>> articles.artauthor_ID =
>> #arguments.authID#">
>> </cfif>
>> <cfif catID NEQ 0>
>> <cfset queryparam = queryparam & " AND
>> articles.artcat_ID =
>> #arguments.catID#">
>> </cfif>
>>
>> <cfset var rsArticles = 0>
>> <cfquery name="rsArticles" datasource="#variables.dsn#">
>> SELECT artID, artcat_ID, artauthor_ID, artTitle,
>> artDesc, artContent
>> FROM articles
>> WHERE articles.artActive = 1
>> #preservesinglequotes(queryparam)#
>> ORDER BY artID DESC
>> </cfquery>
>>
>> <cfreturn rsArticles>
>> </cffunction>
>>
>>
>> ----------------------------------------------------------
>> You are subscribed to cfcdev. To unsubscribe, send an email to
>> [email protected] with the words 'unsubscribe cfcdev' as the subject
>> of the
>> email.
>>
>> CFCDev is run by CFCZone ( www.cfczone.org) and supported by CFXHosting
>> (www.cfxhosting.com).
>>
>> An archive of the CFCDev list is available at
>> www.mail-archive.com/[email protected]
>>
>>
>>
>>
>>
>> ----------------------------------------------------------
>> You are subscribed to cfcdev. To unsubscribe, send an email to
>> [email protected] with the words 'unsubscribe cfcdev' as the subject
>> of the email.
>>
>> CFCDev is run by CFCZone ( www.cfczone.org) and supported by CFXHosting
>> (www.cfxhosting.com).
>>
>> An archive of the CFCDev list is available at
>> www.mail-archive.com/[email protected]
>>
>>
>>
>
>
> ----------------------------------------------------------
> You are subscribed to cfcdev. To unsubscribe, send an email to
> [email protected] with the words 'unsubscribe cfcdev' as the subject of
> the email.
>
> CFCDev is run by CFCZone (www.cfczone.org ) and supported by CFXHosting
> (www.cfxhosting.com).
>
> An archive of the CFCDev list is available at
> www.mail-archive.com/[email protected]
>
>
>
>
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting ( www.cfxhosting.com).
An archive of the CFCDev list is available at www.mail-archive.com/[email protected]
--
Aaron Rouse
http://www.happyhacker.com/ ----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).
An archive of the CFCDev list is available at www.mail-archive.com/[email protected]
