CFLib.org – Common Function Library Project

nullQuery(q, Fields, Values)

Last updated August 10, 2007

author

John Bartlett

Version: 1 | Requires: CF5 | Library: DataManipulationLib

Description:
If a query result set contains no rows but your code requires it, this function will initialize it with pre-defined values. Lists passed in are pipe delimited.

Return Values:
Returns a query.

Example:

<cfset taxes = queryNew("year,receipts,donations")>
<cfset taxes=nullQuery(Taxes,"Year|Receipts|Donations","#Year(Now())#|0|0")>
<cfdump var="#taxes#">

Parameters:

Name Description Required
q Query. Yes
Fields Fields to use. Yes
Values Values to use. Yes

Full UDF Source:

/**
 * Initialize an empty query with default values.
 * 
 * @param q 	 Query. (Required)
 * @param Fields 	 Fields to use. (Required)
 * @param Values 	 Values to use. (Required)
 * @return Returns a query. 
 * @author John Bartlett (jbartlett@strangejourney.net) 
 * @version 1, August 10, 2007 
 */
function nullQuery(q,Fields,Values) {
	var i=0;
	var NewQ=QueryNew(Replace(Fields,"|",",","ALL"));
	if (q.RecordCount GT 0) return q;
	QueryAddRow(NewQ);
	for(i=1; i LTE ListLen(Fields,'|'); i=i+1) {
		querySetCell(NewQ,ListGetAt(Fields,i,'|'),ListGetAt(Values,i,'|'));
	}
	return NewQ;
}
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