MACROMEDIA COLDFUSION MX 7.0.2-USING COLDFUSION MX WITH FLEX 2 Use Manual page 54

Table of Contents

Advertisement

Creating the DAO CFC
You create the DAO CFC to perform direct manipulations of the back-end database. The
DAO CFC appears as follows:
<cfcomponent output="false" >
<cffunction name="read" output="true" access="public"
returntype="samples.contact.Contact[]">
<cfargument name="id" required="false">
<cfargument name="param" required="false">
<cfset var qRead="">
<cfset var obj="">
<cfset var ret = ArrayNew(1)>
<cfquery name="qRead" datasource="contacts">
select contactId,
FirstName,
LastName,
Address,
City,
State,
Zip,
Phone
from Contacts
<cfif structKeyExists(arguments, "id")>
where contactId = <cfqueryparam cfsqltype="CF_SQL_INTEGER"
value="#arguments.id#" />
<cfelseif structKeyExists(arguments, "param")>
<!--- Adjust this WHERE clause based on how to filter. --->
<!--- For example, to filter by LastName, --->
<!--- pass in what you want to filter by in
<!--- the param attribute of the function --->
<!--- and change "where fieldname" to --->
<!--- "where LastName". --->
where LastName LIKE '%'&<cfqueryparam
cfsqltype="CF_SQL_VARCHAR" value="#arguments.param#"/>&'%'
</cfif>
</cfquery>
<cfloop query="qRead">
<cfscript>
obj = createObject("component", "samples.contact.Contact").init();
obj.setcontactId(qRead.contactId);
obj.setFirstName(qRead.FirstName);
obj.setLastName(qRead.LastName);
obj.setAddress(qRead.Address);
obj.setCity(qRead.City);
obj.setState(qRead.State);
obj.setZip(qRead.Zip);
obj.setphone(qRead.phone);
54
Using the Flex Data Service Assembler
--->

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion mx

Table of Contents