Skip to main content
Participant
July 17, 2006
Question

I want to return an array instead of a query

  • July 17, 2006
  • 4 replies
  • 908 views
Dear Forum,

My Flash program uses a web service connector that connects to a CFC. Everything works well with "return type="query.

Now, I would like to add one more row of (calculated) data to the query results. So I thought, let's output the query to an array, add the calculated row, and have the web service return an array instead of a query.

The problem: no column names are delivered to Flash with "return type="array." With return type="query," Flash received the column names from the web service and used those in my datagrid.

Question: should I just use two web services (one with query info and one with calculated data) or is there a way to return column names, query results, and additional info all with one web service call?

Thanks in advance!

P.S. I see using CFDump that a query result is a "special kind" of array. Can anyone explain how this works "behind the scenes?"
This topic has been closed for replies.

4 replies

swickesAuthor
Participant
August 1, 2006
Thanks Rich,

I'm assuming you don't need your column names in the application that is consuming this web service?? That is my only remaining question here; is there some way to simulate a query result (including column names) in the array you build and pass back?

Seems like Flash considers the returned data an array, whether ColdFusion is passing back a query result or an array. But somehow, Flash recognizes that column names are embedded, when the source of the array is a query result.

Any thoughts?
Steve
Inspiring
August 13, 2006
I would suggest looking at the flash remoting online docs.

I found the following which may help

Flash Remoting Recordset

Ken
Participant
August 1, 2006
Here us what I am doing.


<cffunction name="getMasterQuery" output="false" access="remote" returntype="array">
<cfargument name="pageID" required="true">
<cfargument name="docID" required="true">
<cfquery name="qText" datasource="acSnap">
SELECT * FROM text
WHERE pageID = #arguments.pageID# and docID = #arguments.docID#;
</cfquery>
<cfset myarray=arraynew(2)>

<cfloop query="qText">
<cfset myarray[CurrentRow][1]=TextID>
<!--- <cfset myarray[CurrentRow][2]=pageName> --->
<cfset myarray[CurrentRow][2]=textValue>
<cfset myarray[CurrentRow][3]=textName>
</cfloop>

<cfreturn myarray>
</cffunction>


Hope this helps,

Rich
swickesAuthor
Participant
July 18, 2006
Ken,

Thanks for your suggestion. We can add a calculated row in some circumstances. We also have the need to add additional info to the web service return variable that we'd rather have ColdFusion add. For example, customized text to explain an error.

So I'm still wondering:
1. How does a query result differ from a normal array?
2. Are there ways to have a single web service return an array and a string?

Thanks,
Steve
Inspiring
July 18, 2006
Steve,

1. How does a query result differ from a normal array?
Sorry, can't help here.

2. Are there ways to have a single web service return an array and a string?
Not as far as I know.
What I have done is in the case of an error, create an empty query.
I then set any error message to a session variable.
In the page that would display the query or error message, I ckeck if the session variable is not empty and if so display the message. I then reset the session variable to empty.

This also allows me to inform the user that an insert/update has been performed while returning error codes from stored procedures.

Ken
Inspiring
July 18, 2006
Why not just add the calculated row to the query ?

Ken