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