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;
}

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