A number of code examples in ColdFusion MX Developer's Guide reuse code, particularly queries. To illustrate the advantages of CFCs, these examples invoke the appropriate method in the CFC that appears in the following example. Although Macromedia recommends using CFCs to create structured, reusable code, some code examples in this manual contain queries within a CFML page, rather than invoking a CFC, in order to clearly illustrate a particular element of ColdFusion.
<cfcomponent>
<cffunction name="allemployees" access="public" output="false"
returntype="query">
<cfset var getNames="">
<cfquery name="getNames" datasource="cfdocexamples">
SELECT * FROM Employee
</cfquery>
</cffunction>
<cffunction name="namesalarycontract" access="public" output="false"
returntype="query">
<cfset var EmpList="">
<cfquery name="EmpList" datasource="cfdocexamples">
SELECT Firstname, Lastname, Salary, Contract
FROM Employee
</cfquery>
</cffunction>
<cffunction name="fullname" access="public" output="false"
returntype="query">
<cfset var engquery="">
<cfquery name="engquery" datasource="cfdocexamples">
SELECT FirstName + ' ' + LastName AS FullName
FROM Employee
</cfquery>
</cffunction>
<cffunction name="bydept" access="public" output="false" returntype="query">
<cfset var deptquery="">
<cfquery name="deptquery" datasource="cfdocexamples">
SELECT Dept_ID, FirstName + ' ' + LastName
AS FullName
FROM Employee
ORDER BY Dept_ID
</cfquery>
</cffunction>
<cffunction name="employeebyURLID" access="public" output="false"
returntype="query">
<cfset var GetRecordtoUpdate="">
<cfquery name="GetRecordtoUpdate" datasource="cfdocexamples">
SELECT * FROM Employee
WHERE Emp_ID = #URL.Emp_ID#
</cfquery>
</cffunction>
<cffunction name="deleteemployee" access="public" output="false"
returntype="void">
<cfset var DeleteEmployee="">
<cfquery name="DeleteEmployee" datasource="cfdocexamples">
DELETE FROM Employee
WHERE Emp_ID = #Form.Emp_ID#
</cfquery>
</cffunction>
<cffunction name="distinctlocs" access="public" output="false"
returntype="void">
<cfset var GetDepartments="">
<cfquery name="GetDepartments" datasource="cfdocexamples">
SELECT DISTINCT Location
FROM Departmt
</cfquery>
</cffunction>
</cfcomponent>
ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | KnowledgeBase | Bug Reporting
Version 7
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/coldfusion/7/htmldocs/00001068.htm
Comments
CF_Doctor said on Aug 2, 2006 at 6:24 AM : jpesolutions said on Aug 26, 2006 at 12:56 PM :