Doug's Resume
OO Lexicon
Chat with Doug!
Recent Entries
You may also be interested in...

heaters
hotels boeken in 7 sec
Engagement Rings
Online Dating Australia




SURF'S UP!
You:
Your Web Site:
<< July, 2008 >>
SMTWTFS
12345
6789101112
13141516171819
20212223242526
2728293031
Search Blog

ColdFusion Jobs
Recent Comments
Categories
Archives
Photo Albums
Funnies (5)
Family (3)
RSS
Reciprocal Links

Powered by
BlogCFM v1.11

02 March 2007
Sweet Little Snippet: Query to Arguments
I have a CFC method with one argument that is an incoming, single-row query:

<cfargument NAME="remoteData" TYPE="query" REQUIRED="yes" DISPLAYNAME="remoteData" HINT="I am the query returned (and formatted) from a remote data store." />

This method will call another internal method X in order to perform some work, but method X will be looking for the query data as arguments (necessary because method X is also used by other methods who will pass in discrete argument values).

So, I need to "convert" my 'remoteData' argument to actual argument values before I call the other method.


<!--- add our remoteData values to the arguments... --->
<cfloop list = "#arguments.remoteData.columnlist#" index="f">
     <cfset arguments[f] = remoteData[f][1] />
</cfloop>
<cfset myResults = methodX(argumentcollection = arguments) />
<cfreturn myResults />


Pretty simple, but not necessarily so straightforward when having to treat queries as a structure of arrays, so thought I'd share it.

As an aside, I went ahead and toyed with converting an entire query to a structure dynamically, too. Following is the snippet I used:


<!--- create a query to play with using querysim... --->
<cf_querysim>
UserInfo
userID,firstName,lastName,userGroups
100|Stan|Cox|33
200|Joe|Blow|35
</cf_querysim>

<cfset stArgs = structnew() />

<!--- put the query to a structure... --->
<cfoutput query="UserInfo">
    <cfset thisKey = "Record" & UserInfo.currentrow />
    <cfloop list = "#UserInfo.columnlist#" index="f">
        <cfset stArgs[thisKey][f] = UserInfo[f][UserInfo.currentrow] />
    </cfloop>
</cfoutput>

<cfdump var="#UserInfo#">
<cfdump var="#stArgs#" />

Pretty cool. Here are the dumps:




Doug out.



Posted by dougboude at 11:13 AM | PRINT THIS POST! |Link | 2 comments
Subscription Options

You are not logged in, so your subscription status for this entry is unknown. You can login or register here.

Re: Sweet Little Snippet: Query to Arguments
Pretty good generic solution, but I think the code would be more self-documenting if you hardcoded the columns that you were passing as arguments.
It would read a lot easier if you passed
ItemID, CustID instead of
remoteData[f][1]

(Second attempt to post - first was blocked by Anti-spam key)
Posted by Phillip Senn on March 2, 2007 at 11:29 AM

Re: Sweet Little Snippet: Query to Arguments
a bad job
Posted by Abel on May 25, 2007 at 7:16 AM

Name:   Required
Email:   Required your email address will not be publicly displayed.

Want to receive notifications when new comments are added? Login/Register for an account.

Time to take the Turing Test!!!

What letter comes one place(s) before the letter K?
Type your answer exactly three time(s) in the designated box.

Type in the answer to the question you see above:

Your comment:

Sorry, no HTML allowed!