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

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


Let me try to explain what I trying to accomplish a little bit better. 

I'm not sure if cfcs can do this. Documentation seems to make me think
that they can.

In my test.cfm I have the following:

<cfoutput>#qryWINDOWS.recordcount#</cfoutput>
<cfoutput>#qryLINUX.recordcount#</cfoutput>

I'm using the following query from a cfinclude action.cfm (contains
multiple queries).

<!---Query for Windows OS--->
<cfquery datasource="#APPLICATION.dsn#" name="qryWINDOWS">
SELECT *
FROM stats
WHERE os = 'WINDOWS'
</cfquery>

<!---Query for Linux OS--->
<cfquery datasource="#APPLICATION.dsn#" name="qryLINUX">
SELECT *
FROM stats
WHERE os = 'LINUX'
</cfquery>


How can I accomplish this without using mulitiple queries for LINUX,
MAC, UNIX, etc.., using a cfc?  I'm new to the cfcs and after reading
the documentation, It looks like the above is possible, plus I can cut
down on my code.

I would assume I could use variable(s) as follows:

<cfquery datasource="#APPLICATION.dsn#" name="qryOS">
SELECT *
FROM stats
WHERE #var1# = #var2#
</cfquery>

How would I pass #var1# and #var2# from my cfm to the cfc? Any examples
would be great.

How I display the return recordcount would be great as well.  By the
way, the output takes place on the same cfm (test.cfm).



-------------------------------------------------------------
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
-------------------------------------------------------------





-------------------------------------------------------------
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