Allen's is the closest to what I would think Anthony's looking for (just my
opinion). 

I have a couple points of clarification to Allen's code for Anthony, since
he's really new at this. 

First, you would put the CFFUNCTION in side of a file called something.cfc.
And you should (though you don't technically have to) wrap the CFFUNCTION(s)
inside a CFCOMPONENT tag. So you could create a myqueries.cfc, saved in the
same place as your action.cfm, with this code:

<cfcomponent>
        ...Allen's CFFUNCTION and its code
</cfcomponent>

Note that you could also put the CFC in other places like CF's "customtags"
directory, as well as a directory you create an Admin mapping to point to,
etc.) See the docs or other resources for more.

Second, you could then call it from your action.cfm page with the first line
of Allen's CFSCRIPT code modified then to be as follows:

myObject = createObject("component", "myqueries");

Note that you DO NOT say myqueries.cfc in the code above. 

Third, while Allen showed doing it in a CFSCRIPT, since you're new to all
this, note that you don't have to. You could do it as:

<cfset myObject = createObject("component", "myqueries")>
<cfset qryWindows = myObject.GetOSData("windows")>

You can also use CFOBJECT or CFINVOKE instead. Again, check out the docs for
more on those alternatives. 

Finally, you may still wonder, "yeah, but how do I get my recordcount and
query columns?" Well, note that the result of the call to the GetOSData call
was a query (see the CFRETURN and the RETURNTYPE of CFFUNCTION), so you
could now access your columns and the recordcount just as before, but you
would use that resulting variable he shows, such as qryWindows above, for
your queryname in the subsequent code.

Hope that's helpful.

I mentioned in an earlier note about caching. I'll address that in a
follow-up. This is getting too long for many readers. :-)

/Charlie
http://www.carehart.org/blog/  

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
Sent: Friday, February 02, 2007 1:44 PM
To: [email protected]
Subject: RE: [ACFUG Discuss] CFC and reuse query

Before anyone attacks you on this...you shouldn't do something like this:
<cfquery> select blah from blah where #col# = #val#</cfquery> - big security
risk...plus, using cfqueryparam (in most cases) will help a database store
the query plan.

But, you could do something like this:
<cffunction name="GetOSData" returntype="query" output="false"> <cfargument
name="osName" required="true" type="string" /> <cfquery
datasource="#APPLICATION.dsn#" name="qryOS">
        SELECT *
        FROM stats
        WHERE os = <cfqueryparam cfsqltype="cf_sql_varchar"
value="#arguments.osName#"> </cfquery>

<cfreturn qryOS />
</cffunction>

Then, on your page you could do something like this:
<cfscript>
myObject = createObject("component", "yourCFCName"); qryWindows =
myObject.GetOSData("windows"); qryLinux = myObject.GetOSData("linux");
//etc....
</cfscript>

Hope that helps...

Allen




-------------------------------------------------------------
To unsubscribe from this list, manage your profile @ 
http://www.acfug.org?fa=login.edituserform

For more info, see http://www.acfug.org/mailinglists
Archive @ http://www.mail-archive.com/discussion%40acfug.org/
List hosted by http://www.fusionlink.com
-------------------------------------------------------------



Reply via email to