CFLib.org – Common Function Library Project

structToQueryRow(query, struct)

Last updated April 25, 2008

author

Brian Rinaldi

Version: 1 | Requires: CF6 | Library: DataManipulationLib

Description:
Adds a row to a query object and populates it with the values of a structure.

Return Values:
returns the query with the added row

Example:

<cfset qry = queryNew("my,column,names") />

<cfset s = structNew() />
<cfset s.my = "foo" />
<cfset s.column = "bar" />
<cfset s.names = "goo" />

<cfset q = structToQueryRow(qry ,s) />
<cfdump var="#q#">

Parameters:

Name Description Required
query the query to which the struct should be added as a row to Yes
struct the struct that will be added to the query as a query row Yes

Full UDF Source:

<!---
 Adds a row to a query object and populates it with the values of a structure.
 
 @param query 	 the query to which the struct should be added as a row to (Required)
 @param struct 	 the struct that will be added to the query as a query row (Required)
 @return returns the query with the added row 
 @author Brian Rinaldi (brian.rinaldi@gmail.com) 
 @version 1, April 25, 2008 
--->
<cffunction name="structToQueryRow" output="false" access="public" returntype="query">
	<cfargument name="query" required="true" type="query" />
	<cfargument name="struct" required="true" type="struct" />
	<cfset var item = "" />
	<cfset var returnQ = arguments.query />

	<cfset queryAddRow(arguments.query) />
	
	<cfloop collection="#arguments.struct#" item="item">
		<cfif listFindNoCase(returnQ.columnList,item)>
			<cfset querySetCell(returnQ,item,arguments.struct[item]) />
		</cfif>
	</cfloop>
	
	<cfreturn returnQ />
</cffunction>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson