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

    }

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