Then the question becomes, why even bother scoping the dsName to
application. Why not just set variables.dsName in application.cfm?
----- Original Message -----
From: Dave Carabetta <[EMAIL PROTECTED]>
Date: Wednesday, June 26, 2002 10:17 am
Subject: RE: What is the best variable scope?
> > First you have to put it into an application variable, so
> code similar
> to
> > this goes into the Application.cfm :
> >
> > <cflock>
> > <cfif isDefined("Application.dsn")>
> > <cfset application.dsn = "mydatasource">
> > </cfif>
> > </cflock>
> >
> >
> > Now you have to lock all your query statements every time you
> reference > the variable:
> >
> > <cflock>
> > <cfquery datasource="#application.dsn#">
> >
> > </cfquery>
> > </cflock>
> >
> >
> > In this case, you have added additional locking code, which
> takes > additional processing time, with no real added benefit for
> storing the
> > datasource information in an application variable.
>
>
> I disagree with that example. There is no reason to have to lock
> the entire
> query just to use the application variable. I think that's one of
> the most
> commonly used examples out there that are just not accurate. All
> you have to
> do is set a local variable at the top of your page to the
> application-scope
> datasource variable, and then reference the local variable name as
> the
> datasource in the cfquery tag:
>
> <cflock timeout="5" throwontimeout="Yes" type="READONLY"
> scope="APPLICATION">
> <cfset variables.dsName = application.dsName>
> </cflock>
>
> And then in your query, use:
>
> <cfquery name="getRecords" datasource="#variables.dsName#">
> SELECT myColumn
> FROM myTable
> </cfquery>
>
> There is no reason to have to wrap the entire query in your
> example, unless
> you're trying to prevent a race condition.
>
>
> Regards,
> Dave.
>
>
>
______________________________________________________________________
Signup for the Fusion Authority news alert and keep up with the latest news in
ColdFusion and related topics. http://www.fusionauthority.com/signup.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