title: returning multiple stored procedure result sets from a cfc
body: <p>I am trying to convert some pages from my app to use cfc's, and one page uses a stored procedure to retrieve a couple sets of data.</p>
  
  <p>Now when I access the results, they act just like a if I used a <code>&lt;cfquery&gt;</code> tag, and all of the functionality that gives.  So now I am trying to use this same stored procedure in a cfc that I am building, and I would like to be able access the results in the same manner, and there in lies my problem.  I'm not sure how to return multiple queries from the function, without creating an array, which I have started.  By the way, the function is incomplete.  I was just trying to get something to work.  In the below setup I get an array of query objects, but I feel there is a better way to do it.</p>
  
  <p>Here is the <code>&lt;cffuntion&gt;</code>:</p>
  
  <pre><code>&lt;cffunction name="getProfileData" 
              access="public" 
              output="false" 
              returntype="string"&gt;
  
      &lt;cfargument name="cusip" type="string" required="true"&gt;
      &lt;cfargument name="report_date" type="date" required="true"&gt;
      &lt;cfset var errorMessage = "everything is good"&gt;
  
      &lt;cftry&gt;
          &lt;cfstoredproc datasource="#dsn#" procedure="prc_asset_profile_retrieve"&gt;
              &lt;cfprocparam type="in" cfsqltype="cf_sql_varchar" value="#cusip#" dbvarname="@cusip"&gt;
              &lt;cfprocparam type="in" cfsqltype="cf_sql_varchar" value="#report_date#" dbvarname="@reportDate"&gt;
              &lt;cfprocresult name="profile_head" resultset="1"&gt;
              &lt;cfprocresult name="attribution" resultset="2"&gt;
              &lt;cfprocresult name="characteristics" resultset="3"&gt;
              &lt;cfprocresult name="exposure" resultset="4"&gt;
              &lt;cfprocresult name="weights" resultset="5"&gt;
              &lt;cfprocresult name="holdings" resultset="6"&gt;
          &lt;/cfstoredproc&gt;
  
          &lt;cfset var profileArray = []&gt;
          &lt;cfset #ArrayAppend(profileArray,profile_head)#&gt;
  
          &lt;cfcatch type="any"&gt;
              &lt;cfset errorMessage = "something happened"&gt;
          &lt;/cfcatch&gt;          
      &lt;/cftry&gt;
  
      &lt;cfreturn profileArray&gt;
  &lt;/cffunction&gt;
  </code></pre>
  
  <p>When I output some test data, it matches up</p>
  
  <pre><code>&lt;cfset count = fund_profile.getProfileData("#cusip#","#report_date#")&gt; 
  &lt;cfdump var="#count[1]#"&gt;
  &lt;cfoutput&gt;
      From cfc (##count[1].recordCount##): #count[1].recordCount#&lt;br&gt;
      From stored proc (##profile_head.recordCount##): #profile_head.recordCount#
  &lt;/cfoutput&gt;
  </code></pre>
  
  <p>I get:</p>
  
  <p><b>From cfc (#count[1].recordCount#): 1<br>
  From stored proc (#profile_head.recordCount#): 1</b></p>
  
  <p>But the second way looks so much cleaner. </p>
  
  <pre><code>   -----------------------------WORKING SOLUTION------------------------------ 
  </code></pre>
  
  <p>So after working with the answer from @leigh, I came up with this.</p>
  
  <p>Here is the full cfc:</p>
  
  <pre><code>&lt;cfcomponent displayname="Fund Profile" hint="This is the cfc that will do the processing of all fund profile information" output="false"&gt;
       &lt;cfproperty name = "result1"&gt; &lt;!--- PROFILE HEAD ---&gt;
       &lt;cfproperty name = "result2"&gt; &lt;!--- ATTRIBUTION ---&gt;
       &lt;cfproperty name = "result3"&gt; &lt;!--- CHARACTERISTICS ---&gt;
       &lt;cfproperty name = "result4"&gt; &lt;!--- EXPOSURE ---&gt;
       &lt;cfproperty name = "result5"&gt; &lt;!--- WEIGHTS ---&gt;
       &lt;cfproperty name = "result6"&gt; &lt;!--- HOLDINGS ---&gt;
  
       &lt;cffunction name="init" 
              displayname="init" 
              hint="This will initialize the object" 
              access="public" 
              output="false" 
              returnType="Any"&gt;
  
          &lt;cfargument name="dsn"  type="string" required="true" /&gt;
          &lt;cfargument name="cusip" type="string" required="true" /&gt;
          &lt;cfargument name="report_date" type="date" required="true" /&gt;
  
          &lt;cfset variables.dsn = #arguments.dsn#&gt;
          &lt;cfset variables.cusip = #arguments.cusip#&gt;
          &lt;cfset variables.report_date = #arguments.report_date#&gt;
  
          &lt;cfscript&gt;
              getProfiledata(cusip,report_date);
          &lt;/cfscript&gt;     
  
          &lt;cfreturn this&gt;
      &lt;/cffunction&gt;
  
      &lt;cffunction name="getProfileData" 
              access="private" 
              output="false" 
              returntype="void"&gt;
  
          &lt;cfargument name="cusip" type="string" required="true"&gt;
          &lt;cfargument name="report_date" type="date" required="true"&gt;
  
          &lt;cfstoredproc datasource="#dsn#" procedure="prc_asset_profile_retrieve"&gt;
               &lt;!--- STORED PROCEDURE HASN'T CHANGED.  SEE ABOVE FOR CODE ---&gt;
          &lt;/cfstoredproc&gt;
  
          &lt;cfscript&gt;
              setProfilehead(profile_head);
              setAttribution(attribution);
              setCharacteristics(characteristics);
              setExposure(exposure);
              setWeights(weights);
              setHoldings(holdings);
          &lt;/cfscript&gt;
  
          &lt;cfreturn&gt;
      &lt;/cffunction&gt;
  
      &lt;!--- NOT GOING TO INCLUDE ALL SETTERS AND GETTERS, ---&gt;
      &lt;!--- BECAUSE THEY ARE ALL THE SAME OTHER THAN THE NAMES ---&gt;
  
      &lt;cffunction name="setProfileHead" access="private"&gt;
          &lt;cfargument name="ProfileHead"&gt;
          &lt;cfset variables.result1 = arguments.ProfileHead&gt;       
      &lt;/cffunction&gt;
  
      &lt;cffunction name="getProfileHead" access="public" returntype="query"&gt;
          &lt;cfreturn variables.result1&gt;
      &lt;/cffunction&gt;
  
  &lt;/cfcomponent&gt;
  </code></pre>
  
  <p>Here is the code from the calling page:</p>
  
  <pre><code>&lt;cfset fund_profile = CreateObject("component", "CFCs.fund_profile").init("#dsn#","#cusip#","#report_date#")&gt;
  &lt;cfset profile_head = fund_profile.getProfileHead()&gt;
  </code></pre>
  
  <p>Sorry for all the code, but I wanted to make the code available.  So does anyone see any problems with what I came up with?</p>