I have created a cfc (posted below) that replaces a cfquery statement (posted
below also). The cfc handles the query with no problems. The problem I am
having is with the return variables and the cfif statement that checks for
errors. The cfif doesn't recognize GetLocation.recordcount. I have tried
adding it to the cfc but I have trouble with the different type returns. Howdo
I recode the cfif statement to work with <cfreturn GetLocations>? I thank you
all in advance for your help.
Here is my original code:
********************************************
<cfquery name="GetLocations" datasource="#request.data_source#">
SELECT MIN(location_id) AS location_id, location_zip_code, location_city,
location_state,
location_city_alias_name, location_county_name
FROM location
WHERE location_zip_code = '#trim(attributes.classified_zip_code)#'
AND location_city_type = 'P'
GROUP BY location_zip_code, location_city, location_state,
location_city_alias_name, location_county_name
ORDER BY location_city, location_city_alias_name, location_county_name
</cfquery>
<cfif NOT GetLocations.recordcount>
<cfset location_not_found = 1>
<cfset error = 1>
<cfelseif GetLocations.recordcount GT 1>
<cfset multiple_location_matches = 1>
<cfelse>
<cfset temp_location_id = GetLocations.location_id>
<cfset insert_classified = 1>
</cfif>
********************************************************************************
**********************
Here is the new component that replaces the query
**************************************************************
location.cfc***********************
<cfcomponent>
<!-- Get all locations -->
<cffunction name="Location" access="public" returntype="query" hint="return
city, state based upon zip code">
<cfargument name="location_zip_code" type="numeric" required="yes">
<cfquery name="GetLocations" datasource="#request.data_source#">
SELECT MIN(location_id) AS location_id, location_zip_code, location_city,
location_state,
location_city_alias_name, location_county_name
FROM location
WHERE location_zip_code = location_zip_code
AND location_city_type = 'P'
GROUP BY location_zip_code, location_city, location_state,
location_city_alias_name, location_county_name
ORDER BY location_city, location_city_alias_name, location_county_name
</cfquery>
<cfreturn GetLocations>
</cffunction>
</cfcomponent>
************************************************************************
cfc call
<cfinvoke
component="css6.CFC.location"
method="Location"
returnvariable="GetLocations">
<cfinvokeargument name="location_zip_code"
value="#trim(attributes.classified_zip_code)#"/>
</cfinvoke>
Simeon - 30 Dec 2005 17:47 GMT
In your cfinvoke tag your return variable is getLoacations not getLocation.
Your query gets returned as the variable name y ou specifiy in your
returnvariable attributes.
So the easy fix is either use getLocations.recordcount in your cfif, or change
the return variable to getLocation.
Good Luck.
simeon
BKBK - 30 Dec 2005 18:24 GMT
Your code looks fine to me. That is,
<cfcomponent>
: : :
</cfcomponent>
cfc call
<cfinvoke
component="css6.CFC.location"
method="Location"
returnvariable="GetLocations">
<cfinvokeargument name="location_zip_code"
value="#trim(attributes.classified_zip_code)#"/>
</cfinvoke>
<cfif NOT GetLocations.recordcount>
<cfset location_not_found = 1>
<cfset error = 1>
<cfelseif GetLocations.recordcount GT 1>
<cfset multiple_location_matches = 1>
<cfelse>
<cfset temp_location_id = GetLocations.location_id>
<cfset insert_classified = 1>
</cfif>