CFLib.org – Common Function Library Project

typedQueryNew(columnData)

Last updated November 16, 2010

author

Ryan Stille

Version: 1 | Requires: CF7 | Library: DataManipulationLib

Description:
Creating large queries with queryNew() and specifying data types can be frustrating. The long comma separated lists of fields and datatypes can be hard to correlate. This function makes it easier to create queries with datatypes specified.

Return Values:
Returns a query.

Example:

<cfset myQuery = typedQueryNew( {
   name = 'varchar',
   age = 'integer',
   address = 'varchar'
   } ) />

Parameters:

Name Description Required
columnData Structure of label/type fields for the query. Yes

Full UDF Source:

/**
 * Function to easily create query objects with data types.
 * 
 * @param columnData 	 Structure of label/type fields for the query. (Required)
 * @return Returns a query. 
 * @author Ryan Stille (ryan@stillnet.org) 
 * @version 1, November 16, 2010 
 */
function typedQueryNew(columnData) {
	
	var columnname = "";
	var stringofColumns = "";
	var stringofTypes = "";
	var counter = 0;
	
	for (columnName in arguments.columnData) {
		counter++;
			
		stringOfColumns &= columnName;
		stringOfTypes &= arguments.columnData[columnName];
		if (counter NEQ StructCount(arguments.columnData)) {
			stringofColumns &= ", ";
			stringofTypes &= ", ";
			}
		}

	return queryNew(stringofColumns,stringofTypes);

	}
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