Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Advanced Techniques / December 2005



Tip: Looking for answers? Try searching our database.

Problems converting cf code to cfc

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
nu2cf - 30 Dec 2005 17:34 GMT
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>
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.