I like the 1st way, as it allows you to have 1 query that returns different
things based on the arguments (which are set to optional).  

If you really don't want to return more data then needed, you can do this

<cfargument name="repaircenter" type="numeric" required="no" default="0">

<cfset var qRepairCenter="">

<CFQUERY name="qRepairCenter" datasource="#Variables.DSN#">
        SELECT centerId <cfif arguments.repaircenter>, center</cfif>
        FROM Repaircenters
        <cfif arguments.repairCenter>
           WHERE center=<cfqueryparam value="#Arguments.RepairCenter#" 
cfsqltype="CF_SQL_VARCHAR">
        </cfif>
        ORDER BY center
</CFQUERY>
-----Original Message-----
From: Michael Dinowitz [mailto:[EMAIL PROTECTED] 
Sent: Sunday, December 18, 2005 2:11 PM
To: CF-Talk
Subject: Re: CFC Function Style

Using the third style, the first SQL is looking for a single piece of data 
(an int) while the second SQL is looking for 2 (and int and a varchar). The 
first is also using a param where the second doesn't have one. I just don't 
like returning more data than is needed.
<CFQUERY name="qRepairCenter" datasource="#Variables.DSN#">
<CFIF StructKeyExists(arguments, 'repaircenter')>
   Select centerid
   from Repaircenters
    where center=<cfqueryparam value="#Arguments.RepairCenter#" 
cfsqltype="CF_SQL_VARCHAR">
<CFELSE>
   Select centerid, center
   from Repaircenters
   order by center
</CFIF>
</CFQUERY>

Using the first option, it would look like this:
<CFQUERY name="qRepairCenter" datasource="#Variables.DSN#">
<CFIF StructKeyExists(arguments, 'repaircenter')>
   Select centerid
<CFELSE>
   Select centerid, center
</CFIF>
   from Repaircenters
<CFIF StructKeyExists(arguments, 'repaircenter')>
    where center=<cfqueryparam value="#Arguments.RepairCenter#" 
cfsqltype="CF_SQL_VARCHAR">
</CFIF>
   order by center
</CFQUERY>
Two different CFIF statements to control the two different changes.

> Just recently I did the first option and it was more from the stand point 
> of
> I did not see any value to having a separate function for each need like
> this.  Seems like there is not a huge difference between the 1st and 3rd,
> both use a CFIF to decide how the output of the function is going to be.
> One just takes the route of doing a different query for the IF and the 
> ELSE
> then the other just uses one single query that then has the IF/ELSE work
> done within it.  Or am I reading the first option incorrectly?  In the 
> past
> I did option two almost exclusively but when I was evaluating that path
> recently I decided I was ending up with quite a few functions that were 
> more
> or less very similar to one another so some could be combined into one
> function with just some minor IF/ELSE logic.




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble 
Ticket application

http://www.houseoffusion.com/banners/view.cfm?bannerid=48

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:227255
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to