Thanks Douglas.

All it took was a moment of playing to see that of course you can call a
method from another. Foolish question!

Thanks for the time.

 

________________________________

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Douglas
Knudsen
Sent: Wednesday, December 20, 2006 8:42 AM
To: [email protected]
Subject: Re: [ACFUG Discuss] best practice for code reuse in cfcs

 

your example has the repeated query within a single CFC.  Repeated
functionality within your CFC could be put into a method, say
getStudentInfo().  If repeating across CFCs, maybe a different model
approach?  A Student object with methods that StudentProcessing,
StudentFoo, etc can utilise.  

DK

On 12/20/06, Tepfer, Seth <[EMAIL PROTECTED]> wrote:

Across different methods in a single CFC, I find myself occasionally
repeating queries. What is the best practice for reusing the code within
the CFC?

*         use include files

*         have one method in the CFC call the other method in the same
CFC

*         other?

 

Thanks

An example:

 

<cfcomponent hint="Student Processing">

 

<cffunction name="getStudent" output="false" access="public"
returntype="query" hint="I return a single OS Student">

            <cfargument name="EmplID" required="Yes" type="string"
hint="The EmplID to search for a student">

                        <cfquery name="aStudent"
datasource="#ClearinghouseDSN#">

                                    SELECT OSSID, StudentName, EmplID,
Term, OSStatus, IsCanceled, DateCreated

                                    FROM         OSStudents

                                    WHERE       EmplID = <cfqueryparam
value="#EmplID#" cfsqltype="CF_SQL_VARCHAR" maxlength="9">

                                                AND     IsCanceled =
FALSE                 

                        </cfquery>

            <cfreturn aStudent>

</cffunction>

 

 

 

<cffunction name="setBatchOSStudent" output="false" access="public"
returntype="query" hint="I return a list of all Current OS Students">

            <cfargument name="currentTerm" required="Yes" type="string"
hint="The term to search for OS Students">

            <cfargument name="processStyle" required="Yes" type="string"
hint="[Add|Replace] How to process the Empl ID List">

            <cfargument name="importedEmplIDList" required="Yes"
type="string" hint="a list of Empl IDs to mark as in OS, separated by
returns">

 

                        <!---  get all current OS students  --->

                        <cfquery name="currentOSStudents"
datasource="#ClearinghouseDSN#">

                                    SELECT OSSID, StudentName, EmplID,
Term, OSStatus, IsCanceled, DateCreated

                                    FROM OSStudents

                                    WHERE Term = <cfqueryparam
value="#currentTerm#" cfsqltype="CF_SQL_VARCHAR" maxlength="4">

                                                AND IsCanceled = FALSE

                        </cfquery>

                        <!---  made it a list of Empls in oxford studies
--->

                        <cfset currentEmplsInOS =
ValueList(currentOSStudents.EmplID)>

            

                        <cfloop list="#importedEmplIDList#"
index="myEmplID">

                                    <cfif NOT
ListContains(currentEmplsInOS, myEmplID)>

                                    <!---  if myEmplID not in list of
EmplsInOS, insert  --->

                                                <!---  get Student Info
--->

                        <!--- this is the same query as above! --->

<cfquery name="aStudent" datasource="#ClearinghouseDSN#">

                                    SELECT OSSID, StudentName, EmplID,
Term, OSStatus, IsCanceled, DateCreated

                                    FROM         OSStudents

                                    WHERE       EmplID = <cfqueryparam
value="#EmplID#" cfsqltype="CF_SQL_VARCHAR" maxlength="9">

                                                AND     IsCanceled =
FALSE                

                        </cfquery> 

                        

                                                <!---  add each student
in the EmplID list to OS for current term  --->

                                                <cfquery
datasource="#ClearinghouseDSN#">

                                                            INSERT INTO
OSStudents

 
(StudentName, EmplID, OSStatus, Term, IsCanceled, DateCreated)

 
VALUES(<cfqueryparam value="#studentName.LastName#,
#studentName.FirstName#" cfsqltype="CF_SQL_VARCHAR" maxlength="100">

 
, <cfqueryparam value="#myEmplID#" cfsqltype="CF_SQL_VARCHAR"
maxlength="9">

 
, 'Enrolled'

 
, <cfqueryparam value="#currentTerm#" cfsqltype="CF_SQL_VARCHAR"
maxlength="4">

 
, FALSE

 
, #CreateODBCDateTime(NOW())#

 
)

                                                </cfquery>


                                    </cfif>                          

                        </cfloop>

</cffunction>

</cfcomponent>


------------------------------------------------------------- 
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 FusionLink <http://www.fusionlink.com>  
------------------------------------------------------------- 




-- 
Douglas Knudsen
http://www.cubicleman.com
this is my signature, like it? 
------------------------------------------------------------- 
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 FusionLink <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