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>

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson