<?xml version="1.0" encoding="UTF-8"?>
<library createdAt="06-22-2010" id="5" name="DataManipulationLib" updatedAt="06-22-2010">
				<libraries>
			        
				</libraries>
				<snippets>
					
				 	<snippet id="683" template="cfm">
			               <name>Array</name>
			               <help><![CDATA[&lt;cfdump var=&quot;#Array(&apos;one&apos;,&apos;two&apos;,&apos;three&apos;,Array(&apos;foo&apos;,&apos;bar&apos;,&apos;quux&apos;))#&quot;&gt;]]></help>
			               <description><![CDATA[Now you can make simple or complex arrays with a one-liner in CF, just like with built-in shorthand syntax in many other programming languages. You can create simple 1D arrays with ease, or nest Array() functions to create complex 2D, 3D etc arrays.]]></description>
			               <starttext><![CDATA[function Array() {
	var result = ArrayNew(1);
	var to = ArrayLen(arguments);
	var i = 0;
	for (i=1; i LTE to; i=i+1)
		result[i] = Duplicate(arguments[i]);
	return result;
}]]></starttext>
			               <endtext/>
			               <author>Erki Esken</author>
			               <platforms/>
			               <created>07-03-2002</created>
			               <lastupdated>07-03-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="1394" template="cfm">
			               <name>arrayAppend2D</name>
			               <help><![CDATA[&lt;cfset aSideNav = ArrayNew(2)&gt;
&lt;cfset aSideNav[1][1] = &quot;New Project&quot;&gt;
&lt;cfset aSideNav[1][2] = &quot;project.cfm?ID=0&quot;&gt;

&lt;cfset aSideNav = arrayAppend2D(aSideNav, &quot;Bid Results&quot;, &quot;bidresults.cfm&quot;)&gt;]]></help>
			               <description><![CDATA[This UDF appends allows the user to append a key-value set to a two-dimensional array. The code is easily modifiable for more than two dimensions.]]></description>
			               <starttext><![CDATA[function arrayAppend2D(aName, value1, value2) {
	var theLen = arrayLen(aName);
		
	aName[theLen+1][1] = value1;
	aName[theLen+1][2] = value2;
		
	return aName;
}]]></starttext>
			               <endtext/>
			               <author>Minh Lee Goon</author>
			               <platforms/>
			               <created>03-21-2006</created>
			               <lastupdated>03-21-2006</lastupdated>
			          </snippet>
					
				 	<snippet id="283" template="cfm">
			               <name>ArrayAppendUnique</name>
			               <help><![CDATA[&lt;CFSCRIPT&gt;
aX=ArrayNew(1);
aX[1]=&quot;a&quot;;
aX[2]=&quot;b&quot;;
aX[3]=&quot;c&quot;;
aX=ArrayAppendUnique(aX, &quot;b&quot;); //should do nothing
aX=ArrayAppendUnique(aX, &quot;d&quot;); //insert d at index 4
&lt;/CFSCRIPT&gt; 
&lt;CFDUMP var=&quot;#aX#&quot;&gt;]]></help>
			               <description><![CDATA[Takes an Array and a Value as it arguments.  Returns an array with the value appended if the value does not already exist within the array.]]></description>
			               <starttext><![CDATA[function ArrayAppendUnique(a1,val) {
	if ((NOT IsArray(a1))) {
		writeoutput("Error in <Code>ArrayAppendUnique()</code>! Correct usage: ArrayAppendUnique(<I>Array</I>, <I>Value</I>) -- Appends <em>Value</em> to the array if <em>Value</em> does not already exist");
		return 0;
	}
	if (NOT ListFind(Arraytolist(a1), val)) {
		arrayAppend(a1, val);
	}
	return a1;
}]]></starttext>
			               <endtext/>
			               <author>Craig Fisher</author>
			               <platforms/>
			               <created>10-29-2001</created>
			               <lastupdated>10-29-2001</lastupdated>
			          </snippet>
					
				 	<snippet id="2025" template="cfm">
			               <name>arrayCollectionToQuery</name>
			               <help><![CDATA[&lt;cfset testData = [
{Num=2, String=&apos;fubar!&apos;, Bool=true, Date=CreateDate(2009,05,2)},
{Num=4.8, String=&apos;bufar!&apos;, Bool=false, Date=CreateDate(2009,06,1)},
{Num=6, String=&apos;futbol!&apos;, Bool=true, Date=CreateDate(2009,07,12)},
{Num=8, String=&apos;string!&apos;, Bool=false, Date=CreateDate(2009,08,9)},
{Num=10, String=&apos;data type!&apos;, Bool=true, Date=CreateDate(2009,09,18)},
{Num=12, String=&apos;yes&apos;, Bool=false, Date=CreateDate(2009,10,6)}
] /&gt;

&lt;cfdump var=&quot;#testData#&quot; label=&quot;data in&quot;&gt;
&lt;cfdump var=&quot;#arrayCollectionToQuery(testdata)#&quot; label=&quot;data out&quot;&gt;]]></help>
			               <description><![CDATA[For people that are more comfortable working with queries than arrayCollections, this should help.]]></description>
			               <starttext><![CDATA[function arrayCollectionToQuery(arrayColl){
	var qResult = 0;
	var columnList = structKeyList(arguments.arrayColl[1]);
	var typeList = '';
	var numericType = '';
	var k = 0;
	var i = 0;
	for ( k in arguments.arrayColl[1] ){
		if (isNumeric(arguments.arrayColl[1][k])){
			//decimal or integer?
			numericType = 'integer';
			for ( i = 1 ; i lte arrayLen(arguments.arrayColl) ; i = i + 1 ){
				if (arguments.arrayColl[i][k] - fix(arguments.arrayColl[i][k]) eq 0){
					numericType = 'decimal';
					break;
				}
		}
			typelist = listAppend(typeList, numericType);
		} else if (isSimpleValue(arguments.arrayColl[1][k])){
			typeList = listAppend(typeList, 'varchar');
		} else if (isBoolean(arguments.arrayColl[1][k])){
			typeList = listAppend(typeList, 'bit');
		} else if (isDate(arguments.arrayColl[1][k])){
			typeList = listAppend(typeList, 'date');
		} else {
			//we can't throw() in cf8, so uh...
			return "All keys in your array collection must be of one of the following types: Numeric (Int or Float), String, Boolean, Date. The following key contains data that is not one of these types: `#k#`";
		}
	}
	qResult = queryNew(columnList, typeList);
	for ( i = 1 ; i lte arrayLen(arguments.arrayColl) ; i = i + 1 ){
		queryAddRow(qResult);
		for (k in arguments.arrayColl[i]){
			if (not isNumeric(arguments.arrayColl[i][k]) and not isSimpleValue(arguments.arrayColl[i][k]) and not isBoolean(arguments.arrayColl[i][k]) and not isDate(arguments.arrayColl[i][k])){
				return "All keys in your array collection must be of one of the following types: Numeric (Int or Float), String, Boolean, Date. The following key contains data that is not one of these types: `#k#`";
			}
			querySetCell(qResult,k,arguments.arrayColl[i][k]);
		}
	}
	return qResult;
}]]></starttext>
			               <endtext/>
			               <author>Adam Tuttle</author>
			               <platforms/>
			               <created>03-03-2010</created>
			               <lastupdated>03-03-2010</lastupdated>
			          </snippet>
					
				 	<snippet id="1564" template="cfm">
			               <name>arrayCompact</name>
			               <help><![CDATA[&lt;!--- create the array ---&gt;
&lt;cfset tmp=arraynew(1)&gt;
&lt;cfset tmp[1]=&quot;a&quot;&gt;
&lt;cfset tmp[3]=&quot;c&quot;&gt;
&lt;cfset tmp[4]=&quot;d&quot;&gt;
&lt;!--- let&apos;s see it in all it&apos;s un-glory ---&gt;
&lt;cfdump var=&quot;#tmp#&quot; label=&quot;original array&quot;&gt;
&lt;!--- compacting - grindgrindgrind ---&gt;
&lt;cfset newTmp=arrayCompact(tmp)&gt;
&lt;!--- show me ---&gt;
&lt;cfdump var=&quot;#Newtmp#&quot; label=&quot;New Compacted array&quot;&gt;
&lt;!--- now, the pudding ---&gt;
&lt;cfoutput&gt;
Looping new Array&lt;br /&gt;
&lt;cfloop from=&quot;1&quot; to=&quot;#arraylen(newTmp)#&quot; index=&quot;i&quot;&gt;
index #i# = #newTmp[i]#&lt;br /&gt;
&lt;/cfloop&gt;
&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[This function is designed to remove undefined postions from an array.  Will not work in CF5, and would not recommend using it for large arrays.  Optional argument to pass in delimiter (default is Pipe symbol).]]></description>
			               <starttext><![CDATA[function arrayCompact(arr) {
	var delim="|";
	if(arraylen(arguments) gt 1) {delim=arguments[2];}
	return listtoarray(arraytolist(arr,delim),delim);
}]]></starttext>
			               <endtext/>
			               <author>M Gillespie for HOUCFUG</author>
			               <platforms/>
			               <created>03-02-2007</created>
			               <lastupdated>03-02-2007</lastupdated>
			          </snippet>
					
				 	<snippet id="1210" template="cfm">
			               <name>arrayCompare</name>
			               <help><![CDATA[&lt;cfset LeftStruct = structNew()&gt;
&lt;cfset LeftStruct.Email = &quot;test@Test.com&quot;&gt;
&lt;cfset LeftStruct.Name = &quot;test&quot;&gt;
&lt;cfset LeftStruct.Struct = structNew()&gt;
&lt;cfset LeftStruct.Struct.keys = arrayNew(1)&gt;
&lt;cfset LeftStruct.Struct.keys[1] = &quot;1&quot;&gt;
&lt;cfset LeftStruct.Struct.keys[2] = &quot;2&quot;&gt;
&lt;cfset LeftStruct.Array = arrayNew(1)&gt;
&lt;cfset LeftStruct.Array[1] = structNew()&gt;
&lt;cfset LeftStruct.Array[1].id = &quot;1&quot;&gt;
&lt;cfset LeftStruct.Array[1].name = &quot;test&quot;&gt;
&lt;cfset LeftStruct.Array[2] = &quot;321&quot;&gt;

&lt;cfset RightStruct = structNew()&gt;
&lt;cfset RightStruct.Name = &quot;test&quot;&gt;
&lt;cfset RightStruct.Email = &quot;test@Test.com&quot;&gt;
&lt;cfset RightStruct.Struct = structNew()&gt;
&lt;cfset RightStruct.Struct.keys = arrayNew(1)&gt;
&lt;cfset RightStruct.Struct.keys[1] = &quot;1&quot;&gt;
&lt;cfset RightStruct.Struct.keys[2] = &quot;2&quot;&gt;
&lt;cfset RightStruct.Array = arrayNew(1)&gt;
&lt;cfset RightStruct.Array[1] = structNew()&gt;
&lt;cfset RightStruct.Array[1].id = &quot;1&quot;&gt;
&lt;cfset RightStruct.Array[1].name = &quot;test&quot;&gt;
&lt;cfset RightStruct.Array[2] = &quot;321&quot;&gt;

&lt;cfdump var=&quot;#LeftStruct#&quot;&gt;
&lt;cfdump var=&quot;#RightStruct#&quot;&gt;
&lt;cfoutput&gt;#structCompare(LeftStruct,RightStruct)#&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Recursive functions to compare structures and arrays. The root structure or array may contain nested structures and arrays.]]></description>
			               <starttext><![CDATA[function arrayCompare(LeftArray,RightArray) {
	var result = true;
	var i = "";
	
	//Make sure both params are arrays
	if (NOT (isArray(LeftArray) AND isArray(RightArray))) return false;
	
	//Make sure both arrays have the same length
	if (NOT arrayLen(LeftArray) EQ arrayLen(RightArray)) return false;
	
	// Loop through the elements and compare them one at a time
	for (i=1;i lte arrayLen(LeftArray); i = i+1) {
		//elements is a structure, call structCompare()
		if (isStruct(LeftArray[i])){
			result = structCompare(LeftArray[i],RightArray[i]);
			if (NOT result) return false;
		//elements is an array, call arrayCompare()
		} else if (isArray(LeftArray[i])){
			result = arrayCompare(LeftArray[i],RightArray[i]);
			if (NOT result) return false;
		//A simple type comparison here
		} else {
			if(LeftArray[i] IS NOT RightArray[i]) return false;
		}
	}
	
	return true;
}]]></starttext>
			               <endtext/>
			               <author>Ja Carter</author>
			               <platforms/>
			               <created>09-23-2004</created>
			               <lastupdated>09-23-2004</lastupdated>
			          </snippet>
					
				 	<snippet id="265" template="cfm">
			               <name>ArrayConcat</name>
			               <help><![CDATA[&lt;CFSCRIPT&gt;
a1=ArrayNew(1);
a1[1]=1;
a1[2]=2;
a1[3]=3;
a1[4]=4;
a1[5]=5;
a1[6]=6;
a2=ArrayNew(1);
a2[1]=&quot;a&quot;;
a2[2]=structNew();
a2[2].cheese=&quot;fgfgfg&quot;;
a2[3]=&quot;c&quot;;
a2[4]=&quot;d&quot;;
a3=ArrayConcat(a1, a2);
&lt;/cfscript&gt;
a1:
&lt;CFDUMP var=&quot;#a1#&quot;&gt;
a2:
&lt;CFDUMP var=&quot;#a2#&quot;&gt;
a3:
&lt;CFDUMP var=&quot;#a3#&quot;&gt;]]></help>
			               <description><![CDATA[Take two arguments, Array1 and Array2. Concatenates Array2 to the end of Array1.]]></description>
			               <starttext><![CDATA[function ArrayConcat(a1, a2){
	var i=1;
	if ((NOT IsArray(a1)) OR (NOT IsArray(a2))) {
		writeoutput("Error in <Code>ArrayConcat()</code>! Correct usage: ArrayConcat(<I>Array1</I>, <I>Array2</I>) -- Concatenates Array2 to the end of Array1");
		return 0;
	}
	for (i=1;i LTE ArrayLen(a2);i=i+1) {
		ArrayAppend(a1, Duplicate(a2[i]));
	}
	return a1;
}]]></starttext>
			               <endtext/>
			               <author>Craig Fisher</author>
			               <platforms/>
			               <created>09-13-2001</created>
			               <lastupdated>09-13-2001</lastupdated>
			          </snippet>
					
				 	<snippet id="820" template="cfm">
			               <name>ArrayContains</name>
			               <help><![CDATA[&lt;cfset arrN = arrayNew(1)&gt;
&lt;cfset arrN[1] = &quot;A&quot;&gt;
&lt;cfset arrN[2] = &quot;AP&quot;&gt;
&lt;cfset arrN[3] = &quot;B&quot;&gt;
&lt;cfset arrN[4] = &quot;APPLE&quot;&gt;
&lt;cfset arrN[5] = &quot;BOY&quot;&gt;
&lt;cfset arrN[6] = &quot;BOUGHT&quot;&gt;

&lt;cfoutput&gt;#ArrayContains(arrN,&quot;OU&quot;)#&lt;/cfoutput&gt;

Output:
6]]></help>
			               <description><![CDATA[Returns the index of the first item that contains a specified substring. The search is case-sensitive. If the substring is not found in an Array, it  returns zero (0).]]></description>
			               <starttext><![CDATA[function ArrayContains(arrayToSearch,valueToFind){
	var arrayList = "";

	arrayList = ArrayToList(arrayToSearch);
	return ListContains(arrayList,valueToFind);				
}]]></starttext>
			               <endtext/>
			               <author>Sudhir Duddella</author>
			               <platforms/>
			               <created>03-31-2003</created>
			               <lastupdated>03-31-2003</lastupdated>
			          </snippet>
					
				 	<snippet id="821" template="cfm">
			               <name>ArrayContainsNoCase</name>
			               <help><![CDATA[&lt;cfset arrN = arrayNew(1)&gt;
&lt;cfset arrN[1] = &quot;A&quot;&gt;
&lt;cfset arrN[2] = &quot;AP&quot;&gt;
&lt;cfset arrN[3] = &quot;B&quot;&gt;
&lt;cfset arrN[4] = &quot;APPLE&quot;&gt;
&lt;cfset arrN[5] = &quot;BOY&quot;&gt;
&lt;cfset arrN[6] = &quot;BOUGHT&quot;&gt;

&lt;cfoutput&gt;#ArrayContainsNoCase(arrN,&quot;oU&quot;)#&lt;/cfoutput&gt;

Output:
6]]></help>
			               <description><![CDATA[Returns the index of the first item that contains a specified substring. The search is case-insensitive. If the substring is not found in an Array, it  returns zero (0).]]></description>
			               <starttext><![CDATA[function ArrayContainsNoCase(arrayToSearch,valueToFind){
	var arrayList = "";

	arrayList = ArrayToList(arrayToSearch);
	return ListContainsNoCase(arrayList,valueToFind);				
}]]></starttext>
			               <endtext/>
			               <author>Sudhir Duddella</author>
			               <platforms/>
			               <created>03-31-2003</created>
			               <lastupdated>03-31-2003</lastupdated>
			          </snippet>
					
				 	<snippet id="632" template="cfm">
			               <name>ArrayDefinedAt</name>
			               <help><![CDATA[&lt;cfscript&gt;
a = arrayNew(1);
a[1] = &quot;d&quot;;
a[2] = &quot;e&quot;;
a[4] = &quot;f&quot;;
for(i = 1; i lte arrayLen(a); i=i+1) {
	if(arrayDefinedAt(a,i)) writeOutput(&quot;a#i# is #a[i]#&lt;br&gt;&quot;);
	else writeOutput(&quot;a#i# is undefined&lt;br&gt;&quot;);
}
&lt;/cfscript&gt;]]></help>
			               <description><![CDATA[Returns true if a specified array position is defined.]]></description>
			               <starttext><![CDATA[function arrayDefinedAt(arr,pos) {
	var temp = "";
	try {
		temp = arr[pos];
		return true;
	} 
	catch(coldfusion.runtime.UndefinedElementException ex) {
		return false;
	}
	catch(coldfusion.runtime.CfJspPage$ArrayBoundException ex) {
		return false;
	}
}]]></starttext>
			               <endtext/>
			               <author>Raymond Camden</author>
			               <platforms/>
			               <created>10-24-2003</created>
			               <lastupdated>10-24-2003</lastupdated>
			          </snippet>
					
				 	<snippet id="1815" template="cfm">
			               <name>arrayDeleteArray</name>
			               <help><![CDATA[&lt;cfset myArray = ListToArray( &quot;Charlie,Jack,Kate,Libby,Sawyer&quot; )&gt;
&lt;cfset deleteArray = ListToArray( &quot;Charlie,Libby&quot; )&gt;
&lt;cfset myArray = arrayDeleteArray( myArray, deleteArray )&gt;]]></help>
			               <description><![CDATA[Remove elements from one array which exist in another array. Uses Java's array.removeAll(str)]]></description>
			               <starttext><![CDATA[function arrayDeleteArray( baseArray, deleteArray ) {
	arguments.baseArray.removeAll(arguments.deleteArray);
	return arguments.baseArray;
}]]></starttext>
			               <endtext/>
			               <author>Jason Rushton</author>
			               <platforms/>
			               <created>04-11-2008</created>
			               <lastupdated>04-11-2008</lastupdated>
			          </snippet>
					
				 	<snippet id="1171" template="cfm">
			               <name>ArrayDeleteAtList</name>
			               <help><![CDATA[&lt;cfset myArr=ArrayNew(1)&gt;
&lt;cfset myArr[1]=&quot;1st&quot;&gt;
&lt;cfset myArr[2]=&quot;2nd&quot;&gt;
&lt;cfset myArr[3]=&quot;3rd&quot;&gt;
&lt;cfset myArr[4]=&quot;4th&quot;&gt;
&lt;cfset myArr[5]=&quot;5th&quot;&gt;
&lt;cfdump var=&quot;#myArr#&quot; label=&quot;Original array&quot;&gt;
&lt;cfset list=&apos;1,5&apos;&gt;
To delete: &lt;br /&gt;
&lt;cfoutput&gt;#list#&lt;/cfoutput&gt;&lt;br /&gt;
&lt;cfdump var=&quot;#ArrayDeleteAtList(myArr,list)#&quot; label=&quot;parsedArray&quot;&gt;]]></help>
			               <description><![CDATA[Deletes elements from an array passing the list of positions.
Similar to ArrayDeleteAt but the position value could be a list of positions.]]></description>
			               <starttext><![CDATA[function ArrayDeleteAtList(a,l) {
	var i=1;
	l = listSort(l, "numeric", "desc");
	for(i=1; i lte listLen(l); i=i+1) arrayDeleteAt(a, listGetAt(l,i));
	return a;
}]]></starttext>
			               <endtext/>
			               <author>Giampaolo Bellavite</author>
			               <platforms/>
			               <created>01-21-2005</created>
			               <lastupdated>01-21-2005</lastupdated>
			          </snippet>
					
				 	<snippet id="1572" template="cfm">
			               <name>arrayDiff</name>
			               <help><![CDATA[&lt;cfscript&gt;
aSmaller = arrayNew(1);
aSmaller[1] = &apos;a&apos;;
aSmaller[2] = &apos;b&apos;;
aBigger = arrayNew(1); 
aBigger[1] = &apos;a&apos;;
aBigger[2] = &apos;c&apos;;
aBigger[3] = &apos;b&apos;;
aBigger[4] = &apos;d&apos;;
&lt;/cfscript&gt;

Smaller Array:
&lt;cfdump var=&quot;#aSmaller#&quot;&gt;&lt;br /&gt;
Bigger Array:
&lt;cfdump var=&quot;#aBigger#&quot;&gt;&lt;br /&gt;
Difference between the two:
&lt;cfset aDifferences = arrayDiff(aSmaller,aBigger)&gt;
&lt;Ccfdump var=&quot;#aDifferences#&quot;&gt;]]></help>
			               <description><![CDATA[This function compares 2 one-demensional arrays (a &amp; b) with simple values and returns an array with the values found in one array (a) but not in the other (b).]]></description>
			               <starttext><![CDATA[function arrayDiff(smallerArray,biggerArray) {
	var i = "";
	var result = arrayNew(1);
	var s = arrayToList(arguments.smallerArray);
	for (i=1;i lte arrayLen(arguments.biggerArray); i=i+1) if (listFind(s, arguments.biggerArray[i]) is 0) arrayAppend(result, arguments.biggerArray[i]);
	return result;
}]]></starttext>
			               <endtext/>
			               <author>Greg Nettles</author>
			               <platforms/>
			               <created>03-13-2007</created>
			               <lastupdated>03-13-2007</lastupdated>
			          </snippet>
					
				 	<snippet id="1463" template="cfm">
			               <name>arrayExcludeNumeric</name>
			               <help><![CDATA[&lt;cfset aTest = arrayNew(1) /&gt;
&lt;cfset aTest[1] = &quot;Marcos&quot; /&gt;
&lt;cfset aTest[2] = &quot;Placona&quot; /&gt;
&lt;cfset aTest[3] = 22 /&gt;
&lt;cfset aTest[4] = &quot;www.cfdevelopers.com.br&quot;&gt;

&lt;cfdump var=&quot;#arrayExcludeNumeric(aTest)#&quot;&gt;]]></help>
			               <description><![CDATA[Excludes all the numerical items inside an one dimensional array returning a new &quot;non numeric&quot; array.]]></description>
			               <starttext><![CDATA[<cffunction name="arrayExcludeNumeric" returntype="array">
	<cfargument name="aObj" type="array" required="Yes">
	<cfset var ii = "">
	
	<!--- Looping through the array --->
	<cfloop to="1" from="#arrayLen(aObj)#" index="ii" step="-1">
		<!--- Checking if it's a number --->
		<cfif isNumeric(aObj[ii])>
			<cfset arrayDeleteAt(arguments.aObj, ii) />
		</cfif>
	</cfloop>
	
	<cfreturn aObj />
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Marcos Placona</author>
			               <platforms/>
			               <created>07-06-2006</created>
			               <lastupdated>07-06-2006</lastupdated>
			          </snippet>
					
				 	<snippet id="1465" template="cfm">
			               <name>arrayExcludeString</name>
			               <help><![CDATA[&lt;cfset aTest = arrayNew(1) /&gt;
&lt;cfset aTest[3] = 22 /&gt;
&lt;cfset aTest[1] = &quot;Marcos&quot; /&gt;
&lt;cfset aTest[2] = &quot;Placona&quot; /&gt;
&lt;cfset aTest[3] = 22 /&gt;
&lt;cfset aTest[4] = &quot;www.cfdevelopers.com.br&quot;&gt;
&lt;cfset aTest[5] = 55&gt;
&lt;cfset aTest[6] = &quot;test&quot;&gt;
&lt;cfset aTest[7] = &quot;11&quot;&gt;
&lt;cfset aTest[8] = &quot;135&quot;&gt;
&lt;cfset aTest[9] = &quot;test&quot;&gt;
&lt;cfset aTest[10] = &quot;25&quot;&gt;


&lt;cfdump var=&quot;#arrayExcludeNumeric(aTest)#&quot;&gt;]]></help>
			               <description><![CDATA[This UDF is to be used when you need to remove all the string values from your array. It removes them and return a clean array with just numbers.]]></description>
			               <starttext><![CDATA[<cffunction name="arrayExcludeString" returntype="array">
	<cfargument name="aObj" type="array" required="Yes">
	<cfset var ii = "">
	
	<!--- Looping through the array --->
	<cfloop to="1" from="#arrayLen(aObj)#" index="ii" step="-1">
		<!--- Checking if it's a number --->
		<cfif not isNumeric(aObj[ii])>
			<cfset arrayDeleteAt(arguments.aObj, ii) />
		</cfif>
	</cfloop>
	
	<cfreturn aObj />
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Marcos Placona</author>
			               <platforms/>
			               <created>07-11-2006</created>
			               <lastupdated>07-11-2006</lastupdated>
			          </snippet>
					
				 	<snippet id="898" template="cfm">
			               <name>ArrayFilter</name>
			               <help><![CDATA[&lt;cfscript&gt;
function noBerry(str) {
	return not findNoCase(&quot;berry&quot;,str);
}
&lt;/cfscript&gt;

&lt;cfset fruit = listToArray(&quot;apple,banana,orange,pear,lemon,lime,cherry,strawberry,blueberry&quot;)&gt;
&lt;cfdump var=&quot;#arrayFilter(fruit,noBerry)#&quot;&gt;]]></help>
			               <description><![CDATA[Applies a filter to an array (based on array_filter from PHP). For example, taking an array of numbers, you can write a filter UDF that will remove all numbers less than 10.]]></description>
			               <starttext><![CDATA[function arrayFilter(array,filter) {
	var newA = arrayNew(1);
	var i = 1;
	
	for(;i lte arrayLen(array); i=i+1) {
		if(filter(array[i])) arrayAppend(newA,array[i]);
	}
	
	return newA;
}]]></starttext>
			               <endtext/>
			               <author>Raymond Camden</author>
			               <platforms/>
			               <created>03-31-2003</created>
			               <lastupdated>03-31-2003</lastupdated>
			          </snippet>
					
				 	<snippet id="1626" template="cfm">
			               <name>arrayFind</name>
			               <help><![CDATA[&lt;cfset arry = listToArray(&quot;tom, dick, harry, phred&quot;)&gt;

&lt;cfset test = arrayFind(arry,&quot;tom&quot;)&gt;

returns a 1

&lt;cfset test2 = arrayFind(arry,&quot;Tom&quot;)&gt;

returns a 0 (not found)]]></help>
			               <description><![CDATA[The arrayFind function performs a case sensitive search to find the index number of a value in a single dimension array using the java.util.List indexOf method. 

Because this function performs a case sensitive search, Harry or hArry etc., would not be found (if the item is harry). Also since java arrays start at 0, I modified the returned value to conform to CFMX array index values.]]></description>
			               <starttext><![CDATA[<cffunction name="arrayFind" access="public" hint="returns the index number of an item if it is in the array" output="false" returntype="numeric">

<cfargument name="array" required="true" type="array">
<cfargument name="valueToFind" required="true" type="string">

<cfreturn (arguments.array.indexOf(arguments.valueToFind)) + 1>
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Larry C. Lyons</author>
			               <platforms/>
			               <created>04-30-2008</created>
			               <lastupdated>04-30-2008</lastupdated>
			          </snippet>
					
				 	<snippet id="1137" template="cfm">
			               <name>ArrayFindByDimension</name>
			               <help><![CDATA[&lt;cfscript&gt;
arr = arrayNew(2);
arr[1][1] = &quot;apple&quot;;
arr[1][2] = &quot;pear&quot;;
arr[1][3] = &quot;orange&quot;;
arr[2][1] = &quot;star&quot;;
arr[2][2] = &quot;nova&quot;;
arr[2][3] = &quot;moon&quot;;

writeOutput(arrayFindByDimension(arr,&quot;star&quot;,1) &amp; &quot;&lt;br&gt;&quot;);			
writeOutput(arrayFindByDimension(arr,&quot;star&quot;,2) &amp; &quot;&lt;br&gt;&quot;);			

&lt;/cfscript&gt;]]></help>
			               <description><![CDATA[Extends Nathan Dintenfass' ArrayFindNoCase() by adding ability to search a specified dimension of a multidimensional array.  Returns numeric array position of first dimension if element found, otherwise returns 0.]]></description>
			               <starttext><![CDATA[<cffunction name="ArrayFindByDimension" access="public" returntype="numeric" output="false">
	<cfargument name="arrayToSearch" type="array" required="Yes">
	<cfargument name="valueToFind" type="string" required="Yes">
	<cfargument name="dimensionToSearch" type="numeric" required="Yes">
	<cfscript>
		var ii = 1;
		
		//loop through the array, looking for the value
		for(; ii LTE arrayLen(arguments.arrayToSearch); ii = ii + 1){
			//if this is the value, return the index
			if(NOT compareNoCase(arguments.arrayToSearch[ii][arguments.dimensionToSearch], arguments.valueToFind))
				return ii;
		}
		//if we've gotten this far, it means the value was not found, so return 0
		return 0;
	</cfscript>
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Grant Szabo</author>
			               <platforms/>
			               <created>09-23-2004</created>
			               <lastupdated>09-23-2004</lastupdated>
			          </snippet>
					
				 	<snippet id="716" template="cfm">
			               <name>ArrayFindNoCase</name>
			               <help><![CDATA[&lt;cfscript&gt;
	anArray = arrayNew(1);
	anArray[1] = &quot;Camden&quot;;
	anArray[2] = &quot;Archibald&quot;;
	anArray[3] = &quot;Mueller&quot;;
	anArray[4] = &quot;Dintenfass&quot;;
&lt;/cfscript&gt;

&lt;cfoutput&gt;#arrayFindNoCase(anArray,&quot;MUELLER&quot;)#&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Returns the index in an array containing a given (case-insensitive) value.  It is analagous to listFind(), but with arrays.  See also arrayFind().]]></description>
			               <starttext><![CDATA[function ArrayFindNoCase(arrayToSearch,valueToFind){
	//a variable for looping
	var ii = 0;
	//loop through the array, looking for the value
	for(ii = 1; ii LTE arrayLen(arrayToSearch); ii = ii + 1){
		//if this is the value, return the index
		if(NOT compareNoCase(arrayToSearch[ii],valueToFind))
			return ii;
	}
	//if we've gotten this far, it means the value was not found, so return 0
	return 0;
}]]></starttext>
			               <endtext/>
			               <author>Nathan Dintenfass</author>
			               <platforms/>
			               <created>09-06-2002</created>
			               <lastupdated>09-06-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="150" template="cfm">
			               <name>arrayFindSorted</name>
			               <help><![CDATA[&lt;CFSET a1 = ListToArray(&quot;1,2,4,5,10,12&quot;)&gt;
&lt;CFOUTPUT&gt;
#arrayFindSorted(a1, &quot;10&quot;)# &lt;!--- displays 5 ---&gt;
&lt;/CFOUTPUT&gt;]]></help>
			               <description><![CDATA[Locate a value in an already-sorted array. Case-insensitive for strings. Code is useful since converting to a list would require finding a unique delimiter.]]></description>
			               <starttext><![CDATA[function arrayFindSorted(arrayX, value) 
{
	var m = 0;	
	var found = 0;
	var done = 0;
	var hi = arrayLen(arrayX)+1;
	var lo = 1;
	var i = 1;
	var maxtest = 500;
	do {
		m = (hi + lo) \ 2;
		if (arrayX[m] EQ value)
		{
			found = 1;
			done = 1;
		}
		else
		{
			if ((m EQ lo) or (m EQ hi))
				done = 1; /* not found */
			else
			{	
				if (value LT arrayX[m])
				{
				/* higher */
					hi = m;
				}
				else
				{
				/* lower */
					lo = m;
				}
			}
		}
		if (i EQ maxtest)
			{
			done = 1;
			writeoutput("Error! overflow in search");
			}
		else
			i = i + 1;
	} while (done EQ 0);
	if (found)
		return m;
	else
		return 0;
}]]></starttext>
			               <endtext/>
			               <author>Kenneth Fricklas</author>
			               <platforms/>
			               <created>09-30-2005</created>
			               <lastupdated>09-30-2005</lastupdated>
			          </snippet>
					
				 	<snippet id="2048" template="cfm">
			               <name>arrayGroupsOf</name>
			               <help><![CDATA[&lt;cfset ArrFruits = [&quot;Orange&quot;, &quot;Apple&quot;, &quot;Peach&quot;, &quot;Blueberry&quot;, 
					&quot;Blackberry&quot;, &quot;Strawberry&quot;, &quot;Grape&quot;, &quot;Mango&quot;, 
					&quot;Clementine&quot;, &quot;Cherry&quot;, &quot;Plum&quot;, &quot;Guava&quot;, 
					&quot;Cranberry&quot;]&gt;

&lt;table border=&quot;1&quot;&gt;
	&lt;cfoutput&gt;
		&lt;cfloop array=&quot;#arrayGroupsOf(ArrFruits, 5, &apos;not set&apos;)#&quot; index=&quot;arrFruitsIX&quot;&gt;
		  &lt;tr&gt;
			&lt;cfloop array=&quot;#arrFruitsIX#&quot; index=&quot;arrFruit&quot;&gt;
		    	&lt;td&gt;#arrFruit#&lt;/td&gt;
			&lt;/cfloop&gt;
		  &lt;/tr&gt;
		&lt;/cfloop&gt;
	&lt;/cfoutput&gt;
&lt;/table&gt;]]></help>
			               <description><![CDATA[Splits or iterates over the array in number of groups, 
padding any remaining slots with custom strings unless it is empty. It's a big helper for the presentation layer where sometimes it's necessary to display data broken down into columns.]]></description>
			               <starttext><![CDATA[<cffunction name="arrayGroupsOf" access="public" output="false" returntype="array">
	<cfargument name="arrObj" type="array" required="true" hint="An array object that will be split up in groups">
	<cfargument name="intGroup" type="numeric" required="true" hint="Number of items on each group">
	<cfargument name="padding" type="string" required="false" default=" " hint="What should it be filled with in case there's empty slots">
	
	<cfset var resArray = createObject("java", "java.util.ArrayList").Init(arguments.arrObj) />
	<cfset var arrGroup = arrayNew(1) />
	<cfset var arrObjGroup = arrayNew(1) />
	<cfset var arrObjSize = resArray.size()>
	<cfset var subStart = 0>
	<cfset var subEnd = arguments.intGroup>
	<cfset var ii = "">
	<cfset var difference = "">
	<cfset var jj = "">
	
	<cfset arrGroupSize = ceiling(arrObjSize / arguments.intGroup)>
	<cfset arrArrayGroupSize = arrGroupSize * arguments.intGroup>
	
	<cfif arrArrayGroupSize GT arrObjSize>
		<cfset difference = arrArrayGroupSize - arrObjSize>
		<cfloop from="1" to="#difference#" index="ii">
			<cfset resArray.add(arguments.padding) />
		</cfloop>
	</cfif>
	
	<cfloop from="1" to="#arrGroupSize#" index="jj">			
		<cfset arrGroup = resArray.subList(subStart, subEnd)>		
		<cfset arrayAppend(arrObjGroup, arrGroup)>
		
		<cfset subStart = subStart + arguments.intGroup>
		<cfset subEnd = subEnd  + arguments.intGroup>
		<cfset arrGroup = arrayNew(1) />
	</cfloop>
	
	<cfreturn arrObjGroup>

</cffunction>]]></starttext>
			               <endtext/>
			               <author>Marcos Placona</author>
			               <platforms/>
			               <created>02-04-2010</created>
			               <lastupdated>02-04-2010</lastupdated>
			          </snippet>
					
				 	<snippet id="264" template="cfm">
			               <name>ArrayInsertArrayAt</name>
			               <help><![CDATA[&lt;CFSCRIPT&gt;
a1=ArrayNew(1);
a1[1]=1;
a1[2]=2;
a1[3]=3;
a1[4]=4;
a1[5]=5;
a1[6]=6;
a2=ArrayNew(1);
a2[1]=&quot;a&quot;;
a2[2]=&quot;b&quot;;
a2[3]=&quot;c&quot;;
a2[4]=&quot;d&quot;;
a3=ArrayInsertArrayAt(a1, a2, 2);
&lt;/cfscript&gt;
&lt;CFDUMP VAR=&quot;#a1#&quot;&gt;
&lt;CFDUMP VAR=&quot;#a2#&quot;&gt;
&lt;CFDUMP var=&quot;#a3#&quot;&gt;]]></help>
			               <description><![CDATA[Inserts an array at specified position in another array.  Returns the resulting array.  If you secifiy a position one greater than the length of the first array the second array will be concatenated to the first.]]></description>
			               <starttext><![CDATA[function ArrayInsertArrayAt(a1, a2, pos) {
	var aNew = ArrayNew(1);
	var len1 = "";
	var len2 = "";
	var i = 1;
	if ((NOT isArray(a1)) OR (NOT isArray(a2)) OR (NOT IsNumeric(pos)) OR (pos LT 1) OR (pos GT ArrayLen(a1) +1) )  {
		writeoutput("Error in <Code>ArrayInsertArrayAt()</code>! Correct usage: ArrayInsertArrayAt(<I>Array1</I>, <I>Array2</I>,
<I>position</I>) -- Inserts <I>Array2</I> at <I>position</I> in
<I>Array2</I>");
		return 0;
	}
	pos=int(pos);
	len1=ArrayLen(a1);
	len2=ArrayLen(a2);
	aNew=Duplicate(a1);
	if (pos IS NOT Len1 + 1) {
		for (i=0; i LT len2; i=i+1) ArrayInsertAt(aNew, pos + i, Duplicate(a2[i+1]));
	}
	else {
		for (i=1;i LTE len2;i=i+1) ArrayAppend(aNew, Duplicate(a2[i]));
	}	
	return aNew;
}]]></starttext>
			               <endtext/>
			               <author>Craig Fisher</author>
			               <platforms/>
			               <created>09-13-2001</created>
			               <lastupdated>09-13-2001</lastupdated>
			          </snippet>
					
				 	<snippet id="923" template="cfm">
			               <name>ArrayListCompareNoCase</name>
			               <help><![CDATA[&lt;cfset l = &quot;a,b,c,d&quot;&gt;
&lt;cfset a = ArrayNew(1)&gt;
&lt;cfset a[1] = &quot;e&quot;&gt;
&lt;cfset a[2] = &quot;d&quot;&gt;
&lt;cfset a[3] = &quot;ab&quot;&gt;

&lt;cfoutput&gt;#ArrayListCompareNoCase(a, l)#&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Returns the index in an array containing one of the given (case-insensitive) list elements or 0 if none found.]]></description>
			               <starttext><![CDATA[function ArrayListCompareNoCase(arrayToSearch,listToFind){
	//a variable for looping
	var ii = 0;		// variable for looping through list
	var jj = 0;		// variable for looping through array
	var delimiter = ',';		// default delimiter
	

	// check to see if delimiters were passed
	if (ArrayLen(arguments) gt 2) delimiter = arguments[3];

	//loop through list
	for(ii = 1; ii LTE ListLen(listToFind, delimiter); ii = ii + 1) {
	//loop through the array, looking for the value
	for(jj = 1; jj LTE arrayLen(arrayToSearch); jj = jj + 1){
		//if this is the value, return the index
		if(NOT compareNoCase(arrayToSearch[jj],ListGetAt(listToFind, ii, delimiter)))
			return jj;
	}
	}
	//if we've gotten this far, it means the value was not found, so return 0
	return 0;
}]]></starttext>
			               <endtext/>
			               <author>Steve Robison, Jr</author>
			               <platforms/>
			               <created>03-28-2005</created>
			               <lastupdated>03-28-2005</lastupdated>
			          </snippet>
					
				 	<snippet id="1927" template="cfm">
			               <name>arrayOfObjectsToQuery</name>
			               <help><![CDATA[&lt;cfset test1 = CreateObject(&apos;component&apos;,&apos;someObj&apos;).init( &apos;foo&apos;, &apos;bar&apos; ) /&gt;
&lt;cfset test2 = CreateObject(&apos;component&apos;,&apos;someObj&apos;).init( &apos;foo1&apos;, &apos;bar1&apos; ) /&gt;
&lt;cfset myArray = ArrayNew(1) /&gt;
&lt;cfset arrayAppend(myArray,test1) /&gt;
&lt;cfset arrayAppend(myArray,test2) /&gt;

&lt;cfset QoQ = arrayOfObjectsToQuery(myArray)&gt;

&lt;cfdump var=&quot;#QoQ#&quot; /&gt;]]></help>
			               <description><![CDATA[Converts an array of objects to a CF Query Object. Only works with &quot;Bean&quot; style CFCs. Uses the result of all getX methods to populate the query. 

Based on arrayOfStructuresToQuery by David Crawford http://cflib.org/udf/ArrayOfStructuresToQuery]]></description>
			               <starttext><![CDATA[function arrayOfObjectsToQuery(theArray){
    var colNames = ArrayNew(1);
    var theQuery = queryNew("");
    var i=0;
    var j=0;
	var o=0;
	var functions = '';
    //if there's nothing in the array, return the empty query
    if(NOT arrayLen(theArray)) return theQuery;
	
	//get meta data for the first object in the array and set the functions
	functions = getMetaData(theArray[1]).functions;
    //get the column names into an array =    
	for(o=1; o LTE arrayLen(functions); o=o+1){
		if( REFindNoCase( 'get+', functions[o].NAME ) and functions[o].NAME IS NOT 'init' ) {
			arrayAppend(colNames, LCase(REReplaceNoCase(functions[o].NAME, "^get",'' )) );
		}
	}

	theQuery = queryNew(arrayToList(colNames));
	
    //add the right number of rows to the query
    queryAddRow(theQuery, arrayLen(theArray));
    //for each element in the array, loop through the columns, populating the query
    for(i=1; i LTE arrayLen(theArray); i=i+1){
        for(j=1; j LTE arrayLen(colNames); j=j+1){
			//bug out incase something isnt defined in the object
			try {
				querySetCell(theQuery, colNames[j], Evaluate('theArray[i].get#colNames[j]#()'), i);
			}
			catch(Any excpt) { }
        }
    }
    return theQuery;
}]]></starttext>
			               <endtext/>
			               <author>Don Quist</author>
			               <platforms/>
			               <created>06-11-2009</created>
			               <lastupdated>06-11-2009</lastupdated>
			          </snippet>
					
				 	<snippet id="1949" template="cfm">
			               <name>arrayOfStructsFind</name>
			               <help><![CDATA[&lt;cfset aOfStructs = arrayNew(1)&gt;
&lt;cfset arrayAppend(aOfStructs,structNew())&gt;
&lt;cfset aOfStructs[arrayLen(aOfStructs)].firstName = &quot;Jeff&quot;&gt;
&lt;cfset aOfStructs[arrayLen(aOfStructs)].lastName = &quot;Tapper&quot;&gt;
&lt;cfset aOfStructs[arrayLen(aOfStructs)].city = &quot;Astoria&quot;&gt;
&lt;cfset arrayAppend(aOfStructs,structNew())&gt;
&lt;cfset aOfStructs[arrayLen(aOfStructs)].firstName = &quot;Jon&quot;&gt;
&lt;cfset aOfStructs[arrayLen(aOfStructs)].lastName = &quot;Tapper&quot;&gt;
&lt;cfset aOfStructs[arrayLen(aOfStructs)].city = &quot;Brookline&quot;&gt;
&lt;cfset arrayAppend(aOfStructs,structNew())&gt;
&lt;cfset aOfStructs[arrayLen(aOfStructs)].firstName = &quot;Dan&quot;&gt;
&lt;cfset aOfStructs[arrayLen(aOfStructs)].lastName = &quot;Tapper&quot;&gt;
&lt;cfset aOfStructs[arrayLen(aOfStructs)].city = &quot;Suffield&quot;&gt;

&lt;cfoutput&gt;
#ArrayOfStructsFind(aOfStructs,&quot;lastName&quot;,&quot;Tapper&quot;)#&lt;BR&gt;
#ArrayOfStructsFind(aOfStructs,&quot;city&quot;,&quot;Suffield&quot;)#
&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[This function searches for an element in an array of structures, using the key name and a value as criteria.]]></description>
			               <starttext><![CDATA[function arrayOfStructsFind(Array, SearchKey, Value){
	var result = 0;
	var i = 1;
	var key = "";
	for (i=1;i lte arrayLen(array);i=i+1){
		for (key in array[i])
		{
			if(array[i][key]==Value and key == SearchKey){
				result = i;
				return result;
			}
		}
	}
    
    return result;
}]]></starttext>
			               <endtext/>
			               <author>Nath Arduini</author>
			               <platforms/>
			               <created>06-11-2009</created>
			               <lastupdated>06-11-2009</lastupdated>
			          </snippet>
					
				 	<snippet id="359" template="cfm">
			               <name>ArrayOfStructsSort</name>
			               <help><![CDATA[&lt;cfscript&gt;
	a = arraynew(1);
	a[1] = structnew();
	a[1].name = &quot;Dintenfass&quot;;
	a[1].number = 420;
	a[2] = structnew();
	a[2].name = &quot;Archibald&quot;;
	a[2].number = 999;	
	a[3] = structnew();
	a[3].name = &quot;Camden&quot;;
	a[3].number = 123;
&lt;/cfscript&gt;

UNSORTED:
&lt;cfdump var=&quot;#a#&quot;&gt;
SORTED BY NAME:
&lt;cfdump var=&quot;#arrayOfStructsSort(a,&quot;name&quot;)#&quot;&gt;	
SORTED BY NUMBER DESCENDING
&lt;cfdump var=&quot;#arrayOfStructsSort(a,&quot;number&quot;,&quot;desc&quot;,&quot;numeric&quot;)#&quot;&gt;]]></help>
			               <description><![CDATA[This function takes an array of structures and the name of a key in the structures and returns a new array of structures sorted by the key.]]></description>
			               <starttext><![CDATA[function arrayOfStructsSort(aOfS,key){
		//by default we'll use an ascending sort
		var sortOrder = "asc";		
		//by default, we'll use a textnocase sort
		var sortType = "textnocase";
		//by default, use ascii character 30 as the delim
		var delim = ".";
		//make an array to hold the sort stuff
		var sortArray = arraynew(1);
		//make an array to return
		var returnArray = arraynew(1);
		//grab the number of elements in the array (used in the loops)
		var count = arrayLen(aOfS);
		//make a variable to use in the loop
		var ii = 1;
		//if there is a 3rd argument, set the sortOrder
		if(arraylen(arguments) GT 2)
			sortOrder = arguments[3];
		//if there is a 4th argument, set the sortType
		if(arraylen(arguments) GT 3)
			sortType = arguments[4];
		//if there is a 5th argument, set the delim
		if(arraylen(arguments) GT 4)
			delim = arguments[5];
		//loop over the array of structs, building the sortArray
		for(ii = 1; ii lte count; ii = ii + 1)
			sortArray[ii] = aOfS[ii][key] & delim & ii;
		//now sort the array
		arraySort(sortArray,sortType,sortOrder);
		//now build the return array
		for(ii = 1; ii lte count; ii = ii + 1)
			returnArray[ii] = aOfS[listLast(sortArray[ii],delim)];
		//return the array
		return returnArray;
}]]></starttext>
			               <endtext/>
			               <author>Nathan Dintenfass</author>
			               <platforms/>
			               <created>12-10-2001</created>
			               <lastupdated>12-10-2001</lastupdated>
			          </snippet>
					
				 	<snippet id="974" template="cfm">
			               <name>ArrayOfStructsToList</name>
			               <help><![CDATA[&lt;cfset aOfStructs = arrayNew(1)&gt;
&lt;cfset arrayAppend(aOfStructs,structNew())&gt;
&lt;cfset aOfStructs[arrayLen(aOfStructs)].firstName = &quot;Jeff&quot;&gt;
&lt;cfset aOfStructs[arrayLen(aOfStructs)].lastName = &quot;Tapper&quot;&gt;
&lt;cfset aOfStructs[arrayLen(aOfStructs)].city = &quot;Astoria&quot;&gt;
&lt;cfset arrayAppend(aOfStructs,structNew())&gt;
&lt;cfset aOfStructs[arrayLen(aOfStructs)].firstName = &quot;Jon&quot;&gt;
&lt;cfset aOfStructs[arrayLen(aOfStructs)].lastName = &quot;Tapper&quot;&gt;
&lt;cfset aOfStructs[arrayLen(aOfStructs)].city = &quot;Brookline&quot;&gt;
&lt;cfset arrayAppend(aOfStructs,structNew())&gt;
&lt;cfset aOfStructs[arrayLen(aOfStructs)].firstName = &quot;Dan&quot;&gt;
&lt;cfset aOfStructs[arrayLen(aOfStructs)].lastName = &quot;Tapper&quot;&gt;
&lt;cfset aOfStructs[arrayLen(aOfStructs)].city = &quot;Suffield&quot;&gt;

&lt;cfoutput&gt;
#ArrayOfStructsToList(aOfStructs,&quot;firstName&quot;,&quot;&amp;&quot;)#&lt;BR&gt;
#ArrayOfStructsToList(aOfStructs,&quot;firstName&quot;)#&lt;BR&gt;
&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[More and more frequently, complex applications make use of Arrays of Structures.  Occasionally developers have a need to work with a list of values of a particular key within the embedded structure.  This UDF returns such a list.]]></description>
			               <starttext><![CDATA[function ArrayOfStructsToList(Array,Key){
	var delim = ",";
	var i = 0;
	var list = "";
	if(arrayLen(arguments) gt 2) delim = arguments[3];

	for (i=1;i lte arrayLen(array);i=i+1){
		list = listAppend(list,array[i][key],delim);
	}
	
	return list;
}]]></starttext>
			               <endtext/>
			               <author>jeff tapper</author>
			               <platforms/>
			               <created>10-20-2003</created>
			               <lastupdated>10-20-2003</lastupdated>
			          </snippet>
					
				 	<snippet id="1131" template="cfm">
			               <name>ArrayOfStructsToStructOfArrays</name>
			               <help><![CDATA[&lt;cfscript&gt;

ar = arrayNew(1);
ar[1] = structNew();
ar[1].name = &apos;nathan&apos;;
ar[1].date = &apos;1/1/2004&apos;;

ar[2] = structNew();
ar[2].name = &apos;zorro&apos;;
ar[2].date = &apos;2/3/2000&apos;;

ar[3] = structNew();
ar[3].name = &apos;lone ranger&apos;;
ar[3].date = &apos;4/8/2003&apos;;

&lt;/cfscript&gt;

&lt;cfdump var=&quot;#ar#&quot; label=&quot;Array Of Structs&quot;&gt;
&lt;cfdump var=&quot;#ArrayOfStructsToStructOfArrays(ar)#&quot; label=&quot;Struct Of Arrays&quot;&gt;]]></help>
			               <description><![CDATA[For those times when you're working with complex structures and arrays, here's a function that will rearrange your data. This changes a given array of structures to a structure of arrays.]]></description>
			               <starttext><![CDATA[function arrayOfStructsToStructOfArrays(ar) {
	var st = structNew();
	var arKeys = structKeyArray(ar[1]);
	var i=0;
	var j=0;
	var arLen = arrayLen(ar);
	for (i=1;i lte arrayLen(arKeys);i=i+1) {
		st[arKeys[i]] = arrayNew(1);
		for (j=1;j lte arLen;j=j+1) {
			st[arKeys[i]][j] = ar[j][arKeys[i]];
		}
	}
	return st;
}]]></starttext>
			               <endtext/>
			               <author>Nathan Strutz</author>
			               <platforms/>
			               <created>09-21-2004</created>
			               <lastupdated>09-21-2004</lastupdated>
			          </snippet>
					
				 	<snippet id="1929" template="cfm">
			               <name>arrayOfStructsToStructsOfStructs</name>
			               <help><![CDATA[&lt;cfset aArray = arrayNew(1)&gt;

&lt;cfset stStruct1 = structNew()&gt;
&lt;cfset stStruct1.name = &quot;Micheal&quot;&gt;
&lt;cfset stStruct1.age = 20&gt;

&lt;cfset stStruct2 = structNew()&gt;
&lt;cfset stStruct2.name = &quot;Smidt&quot;&gt;
&lt;cfset stStruct2.age = 25&gt;

&lt;cfset aArray[1] = stStruct1&gt;
&lt;cfset aArray[2] = stStruct2&gt;

&lt;cfset stStructOfStructs = ArrayOfStructsToStructsOfStructs(array=aArray,key=&quot;name&quot;))&gt;
&lt;cfdump var=&quot;#stStructofStructs#&quot;&gt;]]></help>
			               <description><![CDATA[This UDF accepts an array of structures and converts it to a structure of structures.

It accepts an array of structures and a key as mandatory arguments. The key must exist in all structures in the array]]></description>
			               <starttext><![CDATA[<cffunction name="ArrayOfStructsToStructsOfStructs" access="public" output="false" returntype="struct" hint="Converts an array of structs to an struct of structs">
		<cfargument name="array" type="array" required="true" hint="An array of structures">
		<cfargument name="key" type="string" required="true" hint="Key to use">
		
		<cfscript>
			var stStructOfStructs = structNew();
			var i = 0;
			
			// loop over array
			for(i=1;i lte arrayLen(arguments.array);i=i+1){
				stStructOfStructs[arguments.array[i][arguments.key]] = arguments.array[i];
			}
			
		    return stStructOfStructs;
		    
		</cfscript>		
	</cffunction>]]></starttext>
			               <endtext/>
			               <author>Tayo Akinmade</author>
			               <platforms/>
			               <created>06-11-2009</created>
			               <lastupdated>06-11-2009</lastupdated>
			          </snippet>
					
				 	<snippet id="287" template="cfm">
			               <name>ArrayOfStructuresToQuery</name>
			               <help><![CDATA[&lt;!--- create an array calledMyArray ---&gt;
&lt;CFSET Stooges = ArrayNew(1)&gt;
&lt;!--- create a structure as the first array element ---&gt;
&lt;CFSET Stooges[1] = StructNew()&gt;
&lt;CFSET Stooges[1].Name = &quot;Larry&quot;&gt;
&lt;CFSET Stooges[1].Age = &quot;34&quot;&gt;
&lt;!--- create a structure as the second array element ---&gt;
&lt;CFSET Stooges[2] = StructNew()&gt;
&lt;CFSET Stooges[2].Name = &quot;Moe&quot;&gt;
&lt;CFSET Stooges[2].Age = &quot;38&quot;&gt;
&lt;!--- create a structure as the third array element ---&gt;
&lt;CFSET Stooges[3] = StructNew()&gt;
&lt;CFSET Stooges[3].Name = &quot;Curly&quot;&gt;
&lt;CFSET Stooges[3].Age = &quot;33&quot;&gt;

&lt;CFSET StoogesQuery=ArrayOfStructuresToQuery(Stooges)&gt;
&lt;B&gt;Array of Structures:&lt;/B&gt;
&lt;CFDUMP Var=&quot;#Stooges#&quot;&gt;
&lt;P&gt;
&lt;B&gt;Query Object:&lt;/B&gt;
&lt;CFDUMP VAR=&quot;#StoogesQuery#&quot;&gt;]]></help>
			               <description><![CDATA[Converts an array of structures to a CF Query Object.  Mirror Image of Nathan Dintenfass' QueryToArrayOfStructures function.]]></description>
			               <starttext><![CDATA[function arrayOfStructuresToQuery(theArray){
	var colNames = "";
	var theQuery = queryNew("");
	var i=0;
	var j=0;
	//if there's nothing in the array, return the empty query
	if(NOT arrayLen(theArray))
		return theQuery;
	//get the column names into an array =	
	colNames = structKeyArray(theArray[1]);
	//build the query based on the colNames
	theQuery = queryNew(arrayToList(colNames));
	//add the right number of rows to the query
	queryAddRow(theQuery, arrayLen(theArray));
	//for each element in the array, loop through the columns, populating the query
	for(i=1; i LTE arrayLen(theArray); i=i+1){
		for(j=1; j LTE arrayLen(colNames); j=j+1){
			querySetCell(theQuery, colNames[j], theArray[i][colNames[j]], i);
		}
	}
	return theQuery;
}]]></starttext>
			               <endtext/>
			               <author>David Crawford</author>
			               <platforms/>
			               <created>03-19-2003</created>
			               <lastupdated>03-19-2003</lastupdated>
			          </snippet>
					
				 	<snippet id="307" template="cfm">
			               <name>ArrayReverse</name>
			               <help><![CDATA[&lt;CFSET Numbers = &quot;1,2,3,4,5&quot;&gt;
&lt;CFSET NumbersArray = ListToArray(Numbers)&gt;
&lt;CFSET NumbersArray = ArrayReverse(NumbersArray)&gt;

&lt;CFLOOP INDEX=&quot;I&quot; FROM=&quot;1&quot; TO=&quot;#ArrayLen(NumbersArray)#&quot;&gt;
&lt;CFOUTPUT&gt;
#NumbersArray[I]#&lt;BR&gt;
&lt;/CFOUTPUT&gt;
&lt;/CFLOOP&gt;]]></help>
			               <description><![CDATA[Reverses the order of elements in a one-dimensional array.  This function takes a one-dimensional array and returns a new one with the values from the first in reverse order.]]></description>
			               <starttext><![CDATA[function ArrayReverse(inArray){
	var outArray = ArrayNew(1);
	var i=0;
        var j = 1;
	for (i=ArrayLen(inArray);i GT 0;i=i-1){
		outArray[j] = inArray[i];
		j = j + 1;
	}
	return outArray;
}]]></starttext>
			               <endtext/>
			               <author>Raymond Simmons</author>
			               <platforms/>
			               <created>10-09-2001</created>
			               <lastupdated>10-09-2001</lastupdated>
			          </snippet>
					
				 	<snippet id="292" template="cfm">
			               <name>ArrayShuffle</name>
			               <help><![CDATA[&lt;cfset a=arrayNew(1)&gt;
&lt;cfloop index=&quot;i&quot; from=&quot;1&quot; to=&quot;10&quot;&gt;
	&lt;cfset a[i]=i&gt;
&lt;/cfloop&gt;
&lt;cfset a1=ArrayShuffle(a)&gt;&lt;br&gt;&lt;br&gt;

&lt;CFLOOP FROM=&quot;1&quot; TO=&quot;#ArrayLen(a1)#&quot; INDEX=&quot;i&quot;&gt;
&lt;CFOUTPUT&gt;
#a1[i]#&lt;BR&gt;
&lt;/CFOUTPUT&gt;
&lt;/CFLOOP&gt;]]></help>
			               <description><![CDATA[Shuffles the values in a one-dimensional array.  This functions takes a one-dimensional array and returns a new one with the values from the first randomly shuffled.]]></description>
			               <starttext><![CDATA[function ArrayShuffle(ar) {
	var ar1=ArrayNew(1);
	var i=1;
	var n=1;
	var len=ArrayLen(ar);
	if (NOT IsArray(ar,1)) {
		writeoutput("Error in <Code>ArrayShuffle()</code>! Correct usage: ArrayShuffle(<I>Array</I>) - Shuffles the values in one dimensional Array");
		return 0;
	}
	
	if (ArrayLen(ar) eq 0) {
		return ar1;
	}
	
	for (i=1; i lte len; i=i+1) {
		n = RandRange(1,ArrayLen(ar));
		ArrayAppend(ar1,ar[n]);
		ArrayDeleteAt(ar,n);
	}
	return ar1;
}]]></starttext>
			               <endtext/>
			               <author>Ivan Latunov</author>
			               <platforms/>
			               <created>10-09-2001</created>
			               <lastupdated>10-09-2001</lastupdated>
			          </snippet>
					
				 	<snippet id="1228" template="cfm">
			               <name>arraySlice</name>
			               <help><![CDATA[&lt;cfscript&gt;
	a = arrayNew(1);
	a[1] = &quot;this&quot;;
	a[2] = &quot;is&quot;;
	a[3] = &quot;the&quot;;
	a[4] = &quot;best&quot;;
	a[5] = &quot;udf&quot;;
	a[6] = &quot;that&quot;;
	a[7] = &quot;has&quot;;
	a[8] = &quot;ever&quot;;
	a[9] = &quot;been&quot;;
	a[10] = &quot;written&quot;;
&lt;/cfscript&gt;

&lt;cfdump var=&quot;#a#&quot;&gt;
&lt;cfdump var=&quot;#arrayslice(a, 2, 3)#&quot;&gt;
&lt;cfdump var=&quot;#arrayslice(a, 7)#&quot;&gt;
&lt;cfdump var=&quot;#arrayslice(a)#&quot;&gt;]]></help>
			               <description><![CDATA[Returns a slice of an array.]]></description>
			               <starttext><![CDATA[function arraySlice(ary) {
	var start = 1;
	var finish = arrayLen(ary);
	var slice = arrayNew(1);
	var j = 1;

	if (len(arguments[2])) { start = arguments[2]; };
	if (len(arguments[3])) { finish = arguments[3]; };

	for (j=start; j LTE finish; j=j+1) {
		arrayAppend(slice, ary[j]);
	}
	return slice;
}]]></starttext>
			               <endtext/>
			               <author>Darrell Maples</author>
			               <platforms/>
			               <created>07-13-2005</created>
			               <lastupdated>07-13-2005</lastupdated>
			          </snippet>
					
				 	<snippet id="1909" template="cfm">
			               <name>arraySlice2</name>
			               <help><![CDATA[&lt;cfset myArray = ArrayNew(1) /&gt;
&lt;cfloop index=&quot;i&quot; from=&quot;1&quot; to=&quot;100&quot;&gt;
	&lt;cfset myArray[i] = i /&gt;
&lt;/cfloop&gt;
&lt;cfdump var=&quot;#myArray#&quot;&gt;
&lt;cfset myArray2 = arraySlice2(myArray) /&gt;
&lt;cfdump var=&quot;#myArray2#&quot;&gt;
&lt;cfset myArray2 = arraySlice2(myArray, 90) /&gt;
&lt;cfdump var=&quot;#myArray2#&quot;&gt;
&lt;cfset myArray2 = arraySlice2(myArray, 99, 10) /&gt;
&lt;cfdump var=&quot;#myArray2#&quot;&gt;]]></help>
			               <description><![CDATA[An arraySlice using Java 1.4 ArrayList built-in method subList(int from, int to).]]></description>
			               <starttext><![CDATA[<cffunction name="arraySlice2" returntype="array" output="false">
	<cfargument name="thisArray" required="true" type="array" />
	<cfargument name="start" required="false" type="numeric" default="1" />
	<cfargument name="length" required="false" type="numeric" default="0" />
	<cfset var resArray = createObject("java", "java.util.ArrayList").Init(arguments.thisArray) />
	<cfset var thisArrayLen = ArrayLen(arguments.thisArray) />
	<cfset var finish = 0 />
	<cfif (arguments.length EQ 0) OR ((arguments.start + arguments.length - 1) GT thisArrayLen)>
		<cfset arguments.length = thisArrayLen - arguments.start + 1 />
	</cfif>
	<cfset finish = arguments.start + arguments.length - 1 />

	<cfreturn resArray.subList(JavaCast("int", arguments.start - 1), JavaCast("int", finish)) />
</cffunction>]]></starttext>
			               <endtext/>
			               <author>G.Arlington</author>
			               <platforms/>
			               <created>06-11-2009</created>
			               <lastupdated>06-11-2009</lastupdated>
			          </snippet>
					
				 	<snippet id="390" template="cfm">
			               <name>ArraySort2D</name>
			               <help><![CDATA[&lt;cfset startArray = ArrayNew(2)&gt;
&lt;cfset startArray[1][1] = 3&gt;
&lt;cfset startArray[1][2] = 5&gt;
&lt;cfset startArray[2][1] = 4&gt;
&lt;cfset startArray[2][2] = 2&gt;
&lt;cfset startArray[3][1] = 9&gt;
&lt;cfset startArray[3][2] = 1&gt;

&lt;cfoutput&gt;

&lt;cfloop from=&quot;1&quot; to=&quot;#ArrayLen(startArray)#&quot; index=&quot;i&quot;&gt;
	&lt;cfloop from=&quot;1&quot; to=&quot;#ArrayLen(startArray[i])#&quot; index=&quot;j&quot;&gt;
		startArray[#i#][#j#] is #startArray[i][j]#&lt;br&gt;	&lt;/cfloop&gt;
&lt;/cfloop&gt;
&lt;/p&gt;

&lt;cfset finalArray = #ArraySort2D(startArray, 2, &quot;numeric&quot;)#&gt;

&lt;p&gt;
&lt;cfloop from=&quot;1&quot; to=&quot;#ArrayLen(finalArray)#&quot; index=&quot;i&quot;&gt;
	&lt;cfloop from=&quot;1&quot; to=&quot;#ArrayLen(finalArray[i])#&quot; index=&quot;j&quot;&gt;
		finalArray[#i#][#j#] is #finalArray[i][j]#&lt;br&gt;
	&lt;/cfloop&gt;
&lt;/cfloop&gt;
&lt;/p&gt;
&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Takes an array, sortcolumn value, sort type (numeric, text, textnocase), and optional sort order (defaults to asc) as arguments. Returns an array sorted by the sortcolumn in the second dimension according to the type and order.]]></description>
			               <starttext><![CDATA[function ArraySort2D(arrayToSort, sortColumn, type) {
	var order = "asc";
	var i = 1;
	var j = 1;
	var thePosition = "";
	var theList = "";
	var arrayToReturn = ArrayNew(2);
	var sortArray = ArrayNew(1);
	var counter = 1;
	if (ArrayLen(Arguments) GT 3){
		order = Arguments[4];
	}
	for (i=1; i LTE ArrayLen(arrayToSort); i=i+1) {
		ArrayAppend(sortArray, arrayToSort[i][sortColumn]);
	}
	theList = ArrayToList(sortArray);
	ArraySort(sortArray, type, order);
	for (i=1; i LTE ArrayLen(sortArray); i=i+1) {
		thePosition = ListFind(theList, sortArray[i]);
		theList = ListDeleteAt(theList, thePosition);
		for (j=1; j LTE ArrayLen(arrayToSort[thePosition]); j=j+1) {
			arrayToReturn[counter][j] = arrayToSort[thePosition][j];
		}
		ArrayDeleteAt(arrayToSort, thePosition);
		counter = counter + 1;
	}
	return arrayToReturn;
}]]></starttext>
			               <endtext/>
			               <author>Robert West</author>
			               <platforms/>
			               <created>10-08-2002</created>
			               <lastupdated>10-08-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="379" template="cfm">
			               <name>Assert</name>
			               <help><![CDATA[&lt;cfset myage = 35&gt;
&lt;cfset myname = &quot;dean&quot;&gt;
&lt;CFOUTPUT&gt;
Given Assertion=&quot;myage as a: isnumeric(|a|); |a| gt 0; |a| lt 100 ! myname as b: isdefined(&apos;|b|&apos;); len(|b|) GT 3&quot;:&lt;BR&gt;
&lt;cfif assert(&quot;myage as a: isnumeric(|a|); |a| gt 0; |a| lt 100 ! myname as b: isdefined(&apos;|b|&apos;); len(|b|) GT 3&quot;)&gt;

Assertion  is correct
&lt;cfelse&gt;
Assertion is incorrect
&lt;/cfif&gt;
&lt;/CFOUTPUT&gt;]]></help>
			               <description><![CDATA[This function when passed an assertion rule string will validate assertions given, which enables the user to parse multiple variables against multiple rule sets.]]></description>
			               <starttext><![CDATA[function assert(assertion) {
	var result = 1;
	var loopvar1 = 0;
	var loopvar2 = 0;
	var variableassertion = "";
	var varsection = "";
	var varname = "";
	var varalias = "";
	var assertionsection = "";
	var anassertion = "";
	var assertnow = "";
	var doBreak = false;
	
	for(loopvar1 = 1; loopvar1 LTE listlen(assertion, "!"); loopvar1 = incrementvalue(loopvar1)) {
		variableassertion = listgetat(assertion, loopvar1, "!");
		varsection = trim(gettoken(variableassertion, 1, ":"));
		varname = trim(listfirst(varsection, " "));
		varalias = trim(listlast(varsection, " "));
		assertionsection = trim(gettoken(variableassertion, 2, ":"));
		
		for(loopvar2 = 1; loopvar2 LTE listlen(assertionsection, ";"); loopvar2 = incrementvalue(loopvar2)) {
			anassertion = listgetat(assertionsection, loopvar2, ";");
			
			if(not isdefined(varname)){
				result = 0;
				doBreak = true;
				break;
			} else {
				assertnow = replacenocase(anassertion, "|#varalias#|", varname, "ALL");
				
				if(not(evaluate(trim(assertnow)))){
					result = 0;
					doBreak = true;
					break;
				}
			}
		}
		
		if(doBreak){
			break;
		}
	}
	
	return result;
}]]></starttext>
			               <endtext/>
			               <author>Dean Chalk</author>
			               <platforms/>
			               <created>09-23-2004</created>
			               <lastupdated>09-23-2004</lastupdated>
			          </snippet>
					
				 	<snippet id="1440" template="cfm">
			               <name>booleanize</name>
			               <help><![CDATA[&lt;cfset one = &quot;true&quot;&gt;
&lt;cfset two = &quot;0&quot;&gt;
&lt;cfset new_one = 0&gt;
&lt;cfset new_two = 0&gt;

&lt;b&gt;default values:&lt;/b&gt;&lt;br&gt;
&lt;cfoutput&gt;
one = #one#&lt;br&gt;
two = #two#&lt;br&gt;
&lt;/cfoutput&gt;
&lt;cfoutput&gt;
&lt;b&gt;New Values:&lt;/b&gt;&lt;br&gt;
one = #booleanize(one)#&lt;br&gt;
two = #booleanize(two)#&lt;br&gt;
&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[This was to help deal with a problem of access/sql conversion and there were some yes/no values that did not match to boolean values. So had to create a script to simplify universal conversion to boolean values.]]></description>
			               <starttext><![CDATA[function booleanize(value) {
	if (not isboolean(value)) {
		value = replacenocase(value,'on',1);
		value = replacenocase(value,'off',0);
	}
	if (yesnoformat(value) eq 'Yes') value = 1;
	if (yesnoformat(value) eq 'No') value = 0;
	return value;
}]]></starttext>
			               <endtext/>
			               <author>Craig M. Rosenblum</author>
			               <platforms/>
			               <created>07-03-2006</created>
			               <lastupdated>07-03-2006</lastupdated>
			          </snippet>
					
				 	<snippet id="1120" template="cfm">
			               <name>cfquery</name>
			               <help><![CDATA[&lt;cfscript&gt;
	qry = cfquery(&quot;accessblogdev&quot;,&quot;id,title&quot;,&quot;SELECT TOP 100 id,title from tblblogentries&quot;);
&lt;/cfscript&gt;

&lt;cfdump var=&quot;#qry#&quot;&gt;]]></help>
			               <description><![CDATA[Allows for the use of a function for a database return rather than th CFQUERY tag.]]></description>
			               <starttext><![CDATA[function cfquery(dsn,col,sql) {
    var datasource = dsn;    
    var userName = "";
    var password = "";
    var adOpenStatic = 3;
    var adLockReadOnly=1;
    var adCmdTxt = 1;
    var adGetRowsRest = -1;
    var columns = listToArray(col); 
    var strSQL = sql;
    var objDataConn = CreateObject("COM", "ADODB.Connection");
    var objDataRst = "";
    var intRecordCount = "";
    var arrRst = "";
    var qry = queryNew(arrayToList(columns));
    var thisCol = "";
    var thisRow = "";

    objDataConn.Open(Datasource, userName, password, -1);
    objDataRst = CreateObject("COM", "ADODB.Recordset");
    objDataRst.open(strSQL, objDataConn, adOpenStatic, adLockReadOnly, adCmdTxt);  
    intRecordCount = objDataRst.RecordCount;
    arrRst = objDataRst.GetRows(adGetRowsRest);
	
    queryAddRow(qry,intRecordCount);
    for (thisCol=1; thisCol LTE arrayLen(columns); thisCol=thisCol+1) {
        for (thisRow=1; thisRow LTE arrayLen(arrRst[thisCol]); thisRow=thisRow+1) {
	    querySetCell(qry,columns[thisCol],arrRst[thisCol][thisRow],thisRow);
	}
    }
    objDataRST.close();
    objDataConn.close();
    return qry;
}]]></starttext>
			               <endtext/>
			               <author>Joe Nicora</author>
			               <platforms/>
			               <created>09-21-2004</created>
			               <lastupdated>09-21-2004</lastupdated>
			          </snippet>
					
				 	<snippet id="1175" template="cfm">
			               <name>clearStructureNested</name>
			               <help><![CDATA[&lt;cfset foo = structnew()&gt;
&lt;cfset foo.foo = structnew()&gt;
&lt;cfset foo.foo.foo = &quot;bar&quot;&gt;
&lt;cfset foo.test = &quot;bar&quot;&gt;
&lt;cfset clearStructureNested( foo )&gt;
&lt;cfdump var=&quot;#foo#&quot;&gt;]]></help>
			               <description><![CDATA[This function recurse through a structure and makes all fields as empty string]]></description>
			               <starttext><![CDATA[<cffunction name="clearStructureNested" returntype="void" output="false">
	<cfargument name="s" type="struct" required="true" />
	<cfset var i = "">
	<cfloop collection="#arguments.s#" item="i">
		<cfif isstruct(arguments.s[i])>
			<cfset clearStructureNested(arguments.s[i])>
		<cfelse>
			<cfset structupdate(arguments.s, i,"")>
		</cfif>
	</cfloop>
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Qasim Rasheed</author>
			               <platforms/>
			               <created>01-28-2005</created>
			               <lastupdated>01-28-2005</lastupdated>
			          </snippet>
					
				 	<snippet id="951" template="cfm">
			               <name>ColumnLoop</name>
			               <help><![CDATA[&lt;CFSET my_query = QueryNew(&quot;URL,Hits&quot;)&gt;
&lt;CFSET QueryAddRow(my_query, 1)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;URL&quot;, &quot;http://www.cflib.org/index.cfm&quot;)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Hits&quot;,&quot;1000&quot;)&gt;
&lt;CFSET QueryAddRow(my_query, 1)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;URL&quot;, &quot;http://www.cflib.org/about.cfm&quot;)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Hits&quot;,&quot;100&quot;)&gt;
&lt;CFSET QueryAddRow(my_query, 1)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;URL&quot;, &quot;http://www.cflib.org/resources.cfm&quot;)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Hits&quot;,&quot;200&quot;)&gt;

Query:&lt;br&gt;
&lt;br&gt;
&lt;CFDUMP VAR=&quot;#my_query#&quot;&gt;
&lt;br&gt;
&lt;br&gt;

Modify with ColumnLoop(&quot;my_query&quot;, &quot;Url&quot;, &quot;x=ReplaceNoCase(x, &quot;&quot;http://www.cflib.org&quot;&quot;, &quot;&quot;&quot;&quot;, &quot;&quot;ALL&quot;&quot;)&quot;):&lt;br&gt;
&lt;br&gt;
&lt;cfset my_query2 = ColumnLoop(duplicate(my_query), &quot;Url&quot;, &quot;x=ReplaceNoCase(x, &quot;&quot;http://www.cflib.org&quot;&quot;, &quot;&quot;&quot;&quot;, &quot;&quot;ALL&quot;&quot;)&quot;)&gt;
&lt;CFDUMP VAR=&quot;#my_query2#&quot;&gt;]]></help>
			               <description><![CDATA[Applies the passed evaluation to every cell in the specified query column. Allows versatile conversions, calculations, formatting and other alterations to an entire query column in one step. Use the variable &quot;x&quot; in the passed evaluation to denote the cell's original value. Especially useful for pre-processing a query before passing it to &lt;cfchart&gt;.]]></description>
			               <starttext><![CDATA[function ColumnLoop(query, columnName, theEval) {
	var row = 0;
	var x = "";
	var rec_count = query.recordCount;
	for(row=1; row LTE rec_count; row=row+1) {
		x = query[columnName][row];
		querySetCell(query,columnname,evaluate(theEval),row);
	}
	return query;
}]]></starttext>
			               <endtext/>
			               <author>Shawn Seley</author>
			               <platforms/>
			               <created>09-12-2003</created>
			               <lastupdated>09-12-2003</lastupdated>
			          </snippet>
					
				 	<snippet id="887" template="cfm">
			               <name>columnTotal</name>
			               <help><![CDATA[&lt;cfset foo = queryNew(&quot;total&quot;)&gt;
&lt;cfset queryAddRow(foo,10)&gt;

&lt;cfloop index=&quot;x&quot; from=1 to=10&gt;
	&lt;cfset querySetCell(foo,&quot;total&quot;,x,x)&gt;
&lt;/cfloop&gt;

&lt;cfoutput&gt;#columnTotal(&quot;foo.total&quot;)#&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[With this UDF, you can get the total of all rows for any given query column. Assuming of course that the column you specify contains numbers! :-)]]></description>
			               <starttext><![CDATA[function columnTotal(qryColumn){
	return arraySum(listToArray(evaluate("valueList(" & qryColumn & ")")));
}]]></starttext>
			               <endtext/>
			               <author>Scott Barber</author>
			               <platforms/>
			               <created>05-13-2003</created>
			               <lastupdated>05-13-2003</lastupdated>
			          </snippet>
					
				 	<snippet id="900" template="cfm">
			               <name>component</name>
			               <help><![CDATA[// same as createObject(&quot;component&quot;, 
//          &quot;normal.dot.notation&quot;);
component(&quot;normal.dot.notation&quot;);

// invoke a component from a sub
// directory off the current web
// directory
component(&quot;./sub/directory/com.cfc&quot;);

// invoke a component on another drive
component(&quot;d:\components\com.cfc&quot;, &quot;absolute&quot;);]]></help>
			               <description><![CDATA[This UDF will create an instance of a CFC based upon a relative or absolute path or even upon the standard dot notation used in the createObject(&quot;component&quot;) function. 

I tried to make the &quot;type&quot; argument somewhat intelligent and it'll probably work correctly 99% of the time for you, but if you want to be absolutely sure you get the expected behavior, specify the type argument for the function.]]></description>
			               <starttext><![CDATA[function component(path){
	var sPath=Arguments.path;var oProxy="";var oFile="";var sType="";
	if( arrayLen(Arguments) gt 1 ) sType = lCase(Arguments[2]);

	// determine a default type	
	if( len(sType) eq 0 ){
		if( (sPath DOES NOT CONTAIN ".") OR ((sPath CONTAINS ".") AND (sPath DOES NOT CONTAIN "/") AND (sPath DOES NOT CONTAIN "\")) ) sType = "component";
		else sType = "relative";
	}
	
	// create the component
	switch( left(sType,1) ){
		case "c":
			return createObject("component", sPath);
		break;

		default:
			if( left(sType, 1) neq "a" ) sPath = expandPath(sPath);
			oProxy = createObject("java", "coldfusion.runtime.TemplateProxy");
			oFile = createObject("java", "java.io.File");
			oFile.init(sPath);
			return oProxy.resolveFile(getPageContext(), oFile);
		break;
	}
}]]></starttext>
			               <endtext/>
			               <author>Dan G. Switzer, II</author>
			               <platforms/>
			               <created>05-13-2003</created>
			               <lastupdated>05-13-2003</lastupdated>
			          </snippet>
					
				 	<snippet id="1580" template="cfm">
			               <name>convertDotNetDataset</name>
			               <help><![CDATA[&lt;cfinvoke webservice=&quot;http://www.example.com/query.asmx?WSDL&quot; method=&quot;NameSearch&quot; returnvariable=&quot;data&quot;&gt;
	&lt;cfinvokeargument name=&quot;LastName&quot; value=&quot;xxxx&quot;/&gt;
	&lt;cfinvokeargument name=&quot;FirstName&quot; value=&quot;xxxx&quot;/&gt;
	&lt;cfinvokeargument name=&quot;MidName&quot; value=&quot;xxxx&quot;/&gt;
&lt;/cfinvoke&gt;
&lt;cfdump var=&quot;#convertDotNetDataset(data)#&quot;&gt;]]></help>
			               <description><![CDATA[Originally written by Joe Reinhart, so give him the credit. I just found this function useful and fixed a bug so it could be submitted.

It will take a .Net Dataset and convert it to a CF structure of queries.]]></description>
			               <starttext><![CDATA[<cffunction name="convertDotNetDataset" access="public" returnType="struct" output="false"
			hint="takes a .Net dataset and converts it to a CF structure of queries">
	<cfargument name="dataset" required="true">
	<cfset var Local = StructNew()>
	<cfset Local.result = structNew() />
	<cfset Local.aDataset = arguments.dataset.get_any() />
	<cfset Local.xSchema  = xmlParse(Local.aDataset[1]) />
	<cfset Local.xData  = xmlParse(Local.aDataset[2]) />

	<!--- Create Queries --->
	<cfset Local.xTables = Local.xSchema["xs:schema"]["xs:element"]["xs:complexType"]["xs:choice"] />
	<cfloop from="1" to="#arrayLen(Local.xTables.xmlChildren)#" index="Local.i">
		<cfset Local.tableName = Local.xTables.xmlChildren[Local.i].xmlAttributes.name />
		<cfset Local.xColumns = Local.xTables.xmlChildren[Local.i].xmlChildren[1].xmlChildren[1].xmlChildren/>
		<cfset Local.result[Local.tableName] = queryNew("") />
		<cfloop from="1" to="#arrayLen(Local.xColumns)#" index="Local.j">
			<cfset queryAddColumn(Local.result[Local.tableName], Local.xColumns[Local.j].xmlAttributes.name, arrayNew(1)) />
		</cfloop>
	</cfloop>

	<!--- see if there are any row of data, if not exit --->
	<cfif NOT StructKeyExists(Local.xData["diffgr:diffgram"], "NewDataSet")>
		<cfreturn Local.result>
	</cfif>

	<!--- Populate Queries --->
	<cfset Local.xRows = Local.xData["diffgr:diffgram"]["NewDataSet"] />
	<cfloop from="1" to="#arrayLen(Local.xRows.xmlChildren)#" index="Local.i">
		<cfset Local.thisRow = Local.xRows.xmlChildren[Local.i] />
		<cfset Local.tableName = Local.thisRow.xmlName />
		<cfset queryAddRow(Local.result[Local.tableName], 1) />
		<cfloop from="1" to="#arrayLen(Local.thisRow.xmlChildren)#" index="Local.j">
			<cfset querySetCell(Local.result[Local.tableName], Local.thisRow.xmlChildren[Local.j].xmlName, Local.thisRow.xmlChildren[Local.j].xmlText, Local.result[Local.tableName].recordCount) />
		</cfloop>
	</cfloop>

	<cfreturn Local.result>
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Anthony Petruzzi</author>
			               <platforms/>
			               <created>05-17-2007</created>
			               <lastupdated>05-17-2007</lastupdated>
			          </snippet>
					
				 	<snippet id="598" template="cfm">
			               <name>CounterMinusMinus</name>
			               <help><![CDATA[&lt;cfset i=2&gt;
&lt;cfset aArray = arrayNew(1)&gt;
&lt;cfset aArray[counterMinusMinus(&quot;i&quot;)]=&quot;Hans&quot;&gt;
&lt;cfset aArray[counterMinusMinus(&quot;i&quot;)]=&quot;Otto&quot;&gt;

&lt;cfoutput&gt;
#i#
&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Simulate the c functionality of i--. Decrements a counter and returns the value of the counter before it was decremeted.]]></description>
			               <starttext><![CDATA[function counterMinusMinus(intCounter) {	
	var temp = evaluate(intCounter);
	"#intCounter#" = temp - 1;
	return temp;
}]]></starttext>
			               <endtext/>
			               <author>Stephan Scheele</author>
			               <platforms/>
			               <created>04-19-2002</created>
			               <lastupdated>04-19-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="596" template="cfm">
			               <name>CounterPlusPlus</name>
			               <help><![CDATA[&lt;cfset i=1&gt;
&lt;cfset aArray = arrayNew(1)&gt;
&lt;cfset aArray[counterPlusPlus(&quot;i&quot;)]=&quot;Hans&quot;&gt;
&lt;cfset aArray[counterPlusPlus(&quot;i&quot;)]=&quot;Otto&quot;&gt;

&lt;cfoutput&gt;
#i#
&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Simulate the c functionality of i++. Increments a counter and returns the value of the counter before it was incremeted.]]></description>
			               <starttext><![CDATA[function counterPlusPlus(intCounter){
	var temp = evaluate(intCounter);
	"#intCounter#" = temp + 1;
	return temp;
}]]></starttext>
			               <endtext/>
			               <author>Stephan Scheele</author>
			               <platforms/>
			               <created>04-17-2002</created>
			               <lastupdated>04-17-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="404" template="cfm">
			               <name>CSVFormat</name>
			               <help><![CDATA[&lt;cfscript&gt;
mytestquery = QueryNew(&apos;FirstName,LastName,Title&apos;);
QueryAddRow(mytestquery, 3);
QuerySetCell(mytestquery, &apos;FirstName&apos;, &apos;Steve&apos;, 1);
QuerySetCell(mytestquery, &apos;LastName&apos;, &apos;Drucker&apos;, 1);
QuerySetCell(mytestquery, &apos;Title&apos;, &apos;CEO&apos;, 1);
QuerySetCell(mytestquery, &apos;FirstName&apos;, &apos;Dave&apos;, 2);
QuerySetCell(mytestquery, &apos;LastName&apos;, &apos;Watts&apos;, 2);
QuerySetCell(mytestquery, &apos;Title&apos;, &apos;CTO&apos;, 2);
QuerySetCell(mytestquery, &apos;FirstName&apos;, &apos;Dave&apos;, 3);
QuerySetCell(mytestquery, &apos;LastName&apos;, &apos;Gallerizzo&apos;, 3);
QuerySetCell(mytestquery, &apos;Title&apos;, &apos;VP&apos;, 3);
&lt;/cfscript&gt;

&lt;cfoutput&gt;
&lt;pre&gt;
#CSVFormat(mytestquery, &quot;&apos;&quot;)#
&lt;/pre&gt;
&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[CSVFormat accepts the name of an existing query and converts it to CSV format, using the column names as headers.  It can wrap each column value with an optional qualifier. Very handy for use inside a cffile tag to create Excel files from queries.]]></description>
			               <starttext><![CDATA[function CSVFormat(query) {
  var returnValue = ArrayNew(1);
  var rowValue = '';
  var columns = query.columnlist;
  var qualifier = '';
  var i = 1;
  var j = 1;
  if(ArrayLen(Arguments) GTE 2) qualifier = Arguments[2];
  if(ArrayLen(Arguments) GTE 3 AND Len(Arguments[3])) columns = Arguments[3];
  returnValue[1] = ListQualify(columns, qualifier);
  ArrayResize(returnValue, query.recordcount + 1);
  columns = ListToArray(columns);
  for(i = 1; i LTE query.recordcount; i = i + 1)
  {
    rowValue = ArrayNew(1);
    ArrayResize(rowValue, ArrayLen(columns));
    for(j = 1; j LTE ArrayLen(columns); j = j + 1)
      rowValue[j] = qualifier & query[columns[j]][i] & qualifier;
    returnValue[i + 1] = ArrayToList(rowValue);
  }		
  returnValue = ArrayToList(returnValue, Chr(13));
  return returnValue;
}]]></starttext>
			               <endtext/>
			               <author>Jeff Howden</author>
			               <platforms/>
			               <created>08-26-2008</created>
			               <lastupdated>08-26-2008</lastupdated>
			          </snippet>
					
				 	<snippet id="1236" template="cfm">
			               <name>CSVToQuery</name>
			               <help><![CDATA[&lt;cfsavecontent variable=&quot;newCSV&quot;&gt;col1,col2,col3
row1val1,row1val2
row2val1,row2val2,row2val3
&lt;/cfsavecontent&gt;

&lt;cfdump var=&quot;#CSVToQuery(newCSV)#&quot;&gt;]]></help>
			               <description><![CDATA[Takes a CSV (comma separated values) formatted string with option row and column delimiters and transforms into a query object. The first row of the CSV string must contain the column headers.]]></description>
			               <starttext><![CDATA[function csvToQuery(csvString){
	var rowDelim = chr(10);
	var colDelim = ",";
	var numCols = 1;
	var newQuery = QueryNew("");
	var arrayCol = ArrayNew(1);
	var i = 1;
	var j = 1;
	
	csvString = trim(csvString);
	
	if(arrayLen(arguments) GE 2) rowDelim = arguments[2];
	if(arrayLen(arguments) GE 3) colDelim = arguments[3];

	arrayCol = listToArray(listFirst(csvString,rowDelim),colDelim);
	
	for(i=1; i le arrayLen(arrayCol); i=i+1) queryAddColumn(newQuery, arrayCol[i], ArrayNew(1));
	
	for(i=2; i le listLen(csvString,rowDelim); i=i+1) {
		queryAddRow(newQuery);
		for(j=1; j le arrayLen(arrayCol); j=j+1) {
			if(listLen(listGetAt(csvString,i,rowDelim),colDelim) ge j) {
				querySetCell(newQuery, arrayCol[j],listGetAt(listGetAt(csvString,i,rowDelim),j,colDelim), i-1);
			}
		}
	}
	return newQuery;
}]]></starttext>
			               <endtext/>
			               <author>Tony Brandner</author>
			               <platforms/>
			               <created>09-30-2005</created>
			               <lastupdated>09-30-2005</lastupdated>
			          </snippet>
					
				 	<snippet id="600" template="cfm">
			               <name>DeepStructCount</name>
			               <help><![CDATA[&lt;cfset x = structNew()&gt;
&lt;cfset x.firstname = &quot;ray&quot;&gt;
&lt;cfset x.lastname = &quot;camden&quot;&gt;
&lt;cfset x.child = arrayNew(1)&gt;
&lt;cfset x.child[1] = structNew()&gt;
&lt;cfset x.child[1].firstName = &quot;jacob&quot;&gt;
&lt;cfset x.child[1].lastName = &quot;camden&quot;&gt;
&lt;cfset x.child[2] = structNew()&gt;
&lt;cfset x.child[2].firstName = &quot;lynn&quot;&gt;
&lt;cfset x.child[2].lastName = &quot;camden&quot;&gt;

&lt;cfoutput&gt;
#deepstructcount(x)#
&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[I needed a way to count the number of keys in a structure that contained other structures.  This UDF will parse all the way through and return the count.   So far I have tested it to 5 nested deep. If an array is encountered, each element in the array will be tested to see if it is a structure. (However, the UDF still requires that the top level value be a structure.)

Note - the count will not include a key that is a structure.]]></description>
			               <starttext><![CDATA[function deepStructCount(myStruct) {
    var deepCount=0;
    var x = "";
    var i = "";
        
    for (x in myStruct) { 
        if(isArray(myStruct[x])) {
            for(i=1; i lte arrayLen(myStruct[x]); i=i+1) {
                if(isStruct(myStruct[x][i])) deepCount = deepCount+deepStructCount(myStruct[x][i]);
            }
        } else if (isStruct(myStruct[x])) {
            deepCount=deepCount+deepStructCount(myStruct[x]);
        } else {
            deepCount=deepCount+1;
        }
    }
	return deepCount;
}]]></starttext>
			               <endtext/>
			               <author>Galen Smallen</author>
			               <platforms/>
			               <created>08-23-2002</created>
			               <lastupdated>08-23-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="548" template="cfm">
			               <name>DumpVar</name>
			               <help><![CDATA[&lt;cfscript&gt;
	simple = &quot;simple variable&quot;;
	
	array = ArrayNew(1);
	array[1] = &quot;element1&quot;;
	array[2] = &quot;element2&quot;;
	
	struct = StructNew();
	struct.key1=simple;
	struct.key2=&quot;value2&quot;;
	struct.array=array;
	struct.q = QueryNew(&quot;col1,col2,col3&quot;);
	QueryAddRow(struct.q,2);
	QuerySetCell(struct.q,&quot;col1&quot;,&quot;col1val&quot;,1);
    QuerySetCell(struct.q,&quot;col2&quot;,&quot;col2val&quot;,1);
    QuerySetCell(struct.q,&quot;col3&quot;,&quot;col3val&quot;,1);
	QuerySetCell(struct.q,&quot;col1&quot;,&quot;col1val row 2&quot;,2);
    QuerySetCell(struct.q,&quot;col2&quot;,&quot;col2val row 2&quot;,2);
    QuerySetCell(struct.q,&quot;col3&quot;,&quot;col3val row 2&quot;,2);
&lt;/cfscript&gt;
&lt;cfoutput&gt;#dumpvar(struct)#&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[This function simulates the &lt;cfdump&gt; tag except you can use it inside cfscript.  It accepts any variable and returns a string representing the data, formatted in a color coded table.  This UDF currently does not display WDDX data.]]></description>
			               <starttext><![CDATA[function DumpVar(varToProcess){
		var structLoopCount = 0;
		var LoopCount = 0;
		var ObjSize = 0;
		var key = "";
        var keys = "";
		var numOfColumns = 0;
        var count2 = 0;
        
		var StartString = "";
		var EndString = "</table>#chr(10)#";
		if(isSimpleValue(varToProcess)){
			if(isWDDX(varToProcess)){
				StartString = "#chr(10)#<table bordercolor='black' border='1' cellspacing='0' cellpadding='1'>#chr(10)#";
				
				return StartString & "<tr>#chr(10)#<td>WDDX currently not displayable</td>#chr(10)#</tr>#chr(10)#" & EndString;
			}else{
				return varToProcess;
			}
		}else if(isArray(varToProcess)){
			StartString = "#chr(10)#<table bordercolor='##008000' border='1' cellspacing='0' cellpadding='1'>#chr(10)#";
			ObjSize = ArrayLen(varToProcess);
			
			for(LoopCount = 1;LoopCount LTE ObjSize;LoopCount = LoopCount + 1){
				StartString = StartString & "<tr>#chr(10)#<td bgcolor='##cceecc' valign='top'>#LoopCount#</td><td>#dumpVar(varToProcess[LoopCount])#</td>#chr(10)#</tr>#chr(10)#";
			}
			return StartString & EndString;
		}else if(isStruct(varToProcess)){
			StartString = "#chr(10)#<table bordercolor='blue' border='1' cellspacing='0' cellpadding='1'>#chr(10)#";
			
			for(key in varToProcess){
				StartString = StartString & "<tr>#chr(10)#<td bgcolor='##aaaaee' valign='top'>#key#</td>#chr(10)#<td>#dumpVar(varToProcess[key])#</td>#chr(10)#</tr>#chr(10)#";
			}
			return StartString & EndString;
		}else if(isQuery(varToProcess)){
			StartString = "#chr(10)#<table bordercolor='red' border='1' cellspacing='0' cellpadding='1'>#chr(10)#";
			ObjSize = varToProcess.recordCount;
			Keys = varToProcess.columnList;
			numOfColumns = ListLen(Keys);
			StartString = StartString & "<tr>#chr(10)#";
			
			for(count2 = 1;count2 LTE numOfColumns;count2 = count2 + 1){
				StartString = StartString & "<td bgcolor='##eeaaaa'>#listGetAt(Keys,count2)#</td>#chr(10)#";
			}
			StartString = StartString & "</tr>#chr(10)#";
			
			for(LoopCount = 1;LoopCount LTE ObjSize;LoopCount = LoopCount + 1){
				StartString = StartString & "<tr>#chr(10)#";
				for(count2 = 1;count2 LTE numOfColumns;count2 = count2 + 1){
					StartString = StartString & "<td>#varToProcess[listGetAt(Keys,count2)][loopCount]#</td>#chr(10)#";
				}
				StartString = StartString & "</tr>#chr(10)#";
			}
			return StartString & EndString;
		}else{
			return " ";
		}
}]]></starttext>
			               <endtext/>
			               <author>Chris Benson</author>
			               <platforms/>
			               <created>04-23-2002</created>
			               <lastupdated>04-23-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="745" template="cfm">
			               <name>DynamicValueList</name>
			               <help><![CDATA[&lt;cfset test = queryNew(&quot;name,age&quot;)&gt;
&lt;cfloop index=&quot;x&quot; from=1 to=5&gt;
	&lt;cfset queryAddRow(test)&gt;
	&lt;cfset querySetCell(test,&quot;name&quot;,&quot;Random Name #randRange(1,10000)#&quot;)&gt;
	&lt;cfset querySetCell(test,&quot;age&quot;,&quot;#randRange(1,100)#&quot;)&gt;
&lt;/cfloop&gt;
&lt;cfdump var=&quot;#test#&quot;&gt;
&lt;cfdump var=&quot;#DynamicValueList(test,&quot;name&quot;)#&quot;&gt;]]></help>
			               <description><![CDATA[The CFML function, ValueList, does not allow you to grab a column dynamically unless you use the evaluate function. This UDF allows you to grab a list of values from one particular column.]]></description>
			               <starttext><![CDATA[function DynamicValueList(query,col) {
	var delim = ",";
	if(arrayLen(arguments) gte 3) delim = arguments[3];
	return arrayToList(query[col],delim);
}]]></starttext>
			               <endtext/>
			               <author>Raymond Camden</author>
			               <platforms/>
			               <created>08-14-2002</created>
			               <lastupdated>08-14-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="888" template="cfm">
			               <name>FirstInFirstOut</name>
			               <help><![CDATA[&lt;cfset myArray = ArrayNew(1)&gt;

&lt;cfset myArray[1] = &quot;First In&quot;&gt; 
&lt;cfset myArray[2] = &quot;Second In&quot;&gt; 
&lt;cfset myArray[3] = &quot;Third In&quot;&gt; 
&lt;cfset myArray[4] = &quot;Fourth In&quot;&gt;

&lt;cfoutput&gt;
Before:&lt;br&gt;
&lt;cfloop from=&quot;1&quot; to=&quot;#ArrayLen(myArray)#&quot; index=&quot;i&quot;&gt;
   #myArray[i]#&lt;br&gt;
&lt;/cfloop&gt;
&lt;/cfoutput&gt;

&lt;cfset myArray = FirstInFirstOut( myArray, &quot;New Value&quot; )&gt;

&lt;cfoutput&gt;
&lt;br&gt;After:&lt;br&gt;
&lt;cfloop from=&quot;1&quot; to=&quot;#ArrayLen(myArray)#&quot; index=&quot;i&quot;&gt;
   #myArray[i]#&lt;br&gt;
&lt;/cfloop&gt;
&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Deletes the first element in a given array, then inserts a new element at the end of the array, creating a first in first out effect.]]></description>
			               <starttext><![CDATA[function FirstInFirstOut( array, valueToAdd ) {

	// Delete element at index 1
	ArrayDeleteAt( array, 1 );
	
	// Add new element at last index plus one
	array[ArrayLen( array ) + 1] = valueToAdd;
	
	return array;
	
}]]></starttext>
			               <endtext/>
			               <author>Adrian Lynch</author>
			               <platforms/>
			               <created>05-13-2003</created>
			               <lastupdated>05-13-2003</lastupdated>
			          </snippet>
					
				 	<snippet id="1715" template="cfm">
			               <name>fixedWidthToQuery</name>
			               <help><![CDATA[&lt;cffile action=&quot;READ&quot; file=&quot;50102-new.txt&quot; variable=&quot;fileData&quot;&gt;&lt;/cffile&gt;
&lt;cfset columNames = &quot;stockNo,year,make,model,vehicleTrim,extcolor,vin,price&quot;&gt;
&lt;cfset columnWidth = &quot;11,5,16,16,21,16,19,8&quot;&gt;
&lt;cfset recordSet = fixedWidthToQuery(columNames,columnWidth,fileData)&gt;]]></help>
			               <description><![CDATA[Converts any type of fixed width string to a ColdFusion query object.]]></description>
			               <starttext><![CDATA[<cffunction name="fixedWidthToQuery" hint="I turn fixed width data to query">
	<cfargument name="columnNames" required="Yes" type="string">
	<cfargument name="widths" required="Yes" type="string">
	<cfargument name="data" required="Yes" type="string">
	<cfargument name="customRegex" required="No" type="string">
	<cfset var tempQuery = QueryNew(arguments.columnNames)>
	<cfset var regEx = "">
	<cfset var findResults = "">
	<cfset var i = "">
	<cfset var line = "">
	<cfset var x = "">
	
	<!--- build our regex --->
	<cfif NOT isDefined("arguments.customRegEx")>
		<cfloop list="#arguments.widths#" index="i">
			<cfset regex = regex & "(.{" & i & "})">
		</cfloop>
	<cfelse>
		<cfset regEx = arguments.customRegex>
	</cfif>
	
	<!--- fix newlines for different os --->
	<cfset arguments.data = replace(arguments.data,chr(10),chr(13),"all")>
	<cfset arguments.data = replace(arguments.data,chr(13)&chr(13),chr(13),"all")>
	
	<!--- loop the data --->
	<cfloop list="#arguments.data#" delimiters="#chr(13)#" index="line">
		<!--- run our regex --->
		<cfset findResults = refind(regEx, line, 1, true)>
		<!--- find our that our match records equals number of columns plus one. --->
		<cfif arrayLen(findResults.pos) eq listLen(arguments.columnNames)+1>
			<cfset QueryAddRow(tempQuery)>
			<!--- loop the find resuls array from postion 2... 
			      and get the column name x-1 as our regex results are number of columsn plus 1
				  and load that data into the query  --->
			<cfloop from="2" to="#arrayLen(findResults.pos)#" index="x">
				<cfset QuerySetCell(tempQuery, listGetAt(arguments.columnNames, x-1), trim(mid(line, findResults.pos[x], findResults.len[x])))> 
			</cfloop>
		</cfif>
	</cfloop>
	<cfreturn tempQuery>
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Umer Farooq</author>
			               <platforms/>
			               <created>12-20-2007</created>
			               <lastupdated>12-20-2007</lastupdated>
			          </snippet>
					
				 	<snippet id="1867" template="cfm">
			               <name>flattenStruct</name>
			               <help><![CDATA[&lt;cfscript&gt;
	stTest = structNew();
	stTest[&apos;test_root_val&apos;] = 1;
	stTest[&apos;EC&apos;] = structNew();
	stTest[&apos;EC&apos;].bCreateBeanFile = true;
	stTest[&apos;EC&apos;].bCreateColdSpringFile = true;
	stTest[&apos;EC&apos;].sConfigBeanObjPath = &apos;models.GlobalConfig&apos;;
	stTest[&apos;EC&apos;].sColdSpringDefFilePath = &apos;/config/GlobalConfigColdspring.xml.cfm&apos;;
	stTest[&apos;EC&apos;].sECDefinitionFilePath = &apos;/config/environment.xml.cfm&apos;;
	stTest[&apos;EC&apos;].sub = structNew();
	stTest[&apos;EC&apos;][&apos;sub&apos;].test_sub_val = &apos;test&apos;;
&lt;/cfscript&gt;

&lt;cfdump var=&quot;#flattenStruct(stTest)#&quot; label=&quot;result&quot;&gt;]]></help>
			               <description><![CDATA[Recursively loops through a structure with nested structures and builds nested keys and values into a single struct.

http://tomdeman.com/blog/UDFs]]></description>
			               <starttext><![CDATA[<cffunction name="flattenStruct" access="public" output="false" returntype="struct">
	<cfargument name="stObject"  required="true"  type="struct" />
	<cfargument name="delimiter" required="false" type="string" default="." />
	<cfargument name="prefix" 	 required="false" type="string" default="" />
	<cfargument name="stResult"  required="false" type="struct" default="#structNew()#" />
	<cfargument name="addPrefix" required="false" type="boolean" default="true" />
	
	<cfset var sKey = '' />
	
	<cfloop collection="#arguments.stObject#" item="sKey">		
		<cfif isSimpleValue(arguments.stObject[sKey])>
			<cfif arguments.addPrefix and len(arguments.prefix)>
				<cfset arguments.stResult[arguments.prefix & arguments.delimiter & sKey] = arguments.stObject[sKey] />
			<cfelse>
				<cfset arguments.stResult[sKey] = arguments.stObject[sKey] />
			</cfif>
		<cfelseif isStruct(arguments.stObject[sKey])>
			<cfset flattenStruct(arguments.stObject[sKey],arguments.delimiter,sKey,arguments.stResult) />	
		</cfif>
	</cfloop>
	<cfreturn arguments.stResult />
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Tom de Manincor</author>
			               <platforms/>
			               <created>08-26-2008</created>
			               <lastupdated>08-26-2008</lastupdated>
			          </snippet>
					
				 	<snippet id="531" template="cfm">
			               <name>Form2QS</name>
			               <help><![CDATA[&lt;cfset form.foo = 1&gt;
&lt;cfset form.goo = &quot;Jacob Camden&quot;&gt;
&lt;cfoutput&gt;foo.cfm?id=1#form2qs()#&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Creates a standard query string (list of name value pairs, separated by =, delimited by &amp;) from all of the form variables.]]></description>
			               <starttext><![CDATA[function form2qs() {
	var str = "";
	var field = "";
	for(key in form) {
		str = str & "&#key#=" & urlEncodedFormat(form[key]);
	}
	return str;	
}]]></starttext>
			               <endtext/>
			               <author>Billy Cravens</author>
			               <platforms/>
			               <created>06-26-2002</created>
			               <lastupdated>06-26-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="801" template="cfm">
			               <name>Get</name>
			               <help><![CDATA[&lt;!---
&lt;cffile action=&quot;READBINARY&quot; file=&quot;file name&quot; variable=&quot;Data&quot;&gt;
&lt;CFLOOP index=&quot;loop&quot; from=&quot;1&quot; to=&quot;100&quot;&gt;
	&lt;CFOUTPUT&gt;#Chr(Get(Data,loop))#&lt;/CFOUTPUT&gt;
&lt;/CFLOOP&gt;
---&gt;]]></help>
			               <description><![CDATA[This UDF will return the ASCII value of a specified character in a BINARY file.

(Get is a throwback to the BASIC days of GET/POKE for fetching/changing bytes in memory.)

Note: You may not change any value stored in the binary array - an error will occur.]]></description>
			               <starttext><![CDATA[function Get(BVar,loc) {
	if (isBinary(BVar) EQ "No") return 0;
	if (BVar[loc] GTE 0) return BVar[loc];
	return BVar[loc] + 256;
}]]></starttext>
			               <endtext/>
			               <author>John Bartlett</author>
			               <platforms/>
			               <created>11-15-2002</created>
			               <lastupdated>11-15-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="1094" template="cfm">
			               <name>getComponentProps</name>
			               <help><![CDATA[&lt;cfset whatever = createobject(&apos;component&apos;, &apos;foo.bar&apos;)&gt;
&lt;cfset dummyArray = getComponentProps( getMetaData( whatever ))&gt;
&lt;cfdump var=&quot;#dummyArray#&quot; /&gt;]]></help>
			               <description><![CDATA[Pass in the result from getMetaData() and returns all properties within the cfc and those it extends. It is recursive. (I didn't find any true time difference and this seemed cleaner). This does not include the base 'component' tag in it's search. I couldn't see anyone putting properties there anyways. A special value will be added to each propery, foundIn, that represents which CFC a property was found in. This is useful in case both a child and parent CFC share the same property.]]></description>
			               <starttext><![CDATA[function getComponentProps(object) {
	var propArray = arrayNew(1);
	var internalArray = arrayNew(1);
	var i = ''; 
	var j = '';
	
	if (structKeyExists(object,'properties')) {
		for (i=1; i lte arraylen(object.properties);i = i+1) {
			arrayappend(propArray,object.properties[i]);
			propArray[arrayLen(propArray)].foundin = object.name;
		}
	}
	if (listlast(object.extends.name,'.' ) neq 'component'){
		internalArray = getComponentProps(object.extend );
		for (j=1;j lte arraylen(internalArray);j = j+1){
			arrayappend(propArray,internalArray[j]);
		}
	}
	return propArray;
}]]></starttext>
			               <endtext/>
			               <author>Robby Lansaw</author>
			               <platforms/>
			               <created>08-18-2004</created>
			               <lastupdated>08-18-2004</lastupdated>
			          </snippet>
					
				 	<snippet id="1937" template="cfm">
			               <name>getQueryMetadata</name>
			               <help><![CDATA[&lt;cfquery datasource=&quot;mydsn&quot; name=&quot;myquery&quot;&gt;
select * from mytable
&lt;/cfquery&gt;
&lt;cfdump var=&quot;#getQueryMetadata(myquery)#&quot;&gt;]]></help>
			               <description><![CDATA[CF7 introduced the ability to run getMetadata() on a query, which returns an array of structures containing datatype information. This UDF replicates this functionality for CFMX6.1

If run on CFMX7+, it uses CF's built-in function.]]></description>
			               <starttext><![CDATA[<cffunction name="getQueryMetadata" access="public" returntype="array" hint="Replicates the CF7 getMetadata(query) functionality for MX6.1+">
		<cfargument name="query" type="query" required="true"/>
		<cfset var metadata = ArrayNew(1)>
		<cfset var columns = ArrayNew(1)>
		<cfset var col = 1>
		<cfset var map = StructNew()>
		<cfif listFirst(server.ColdFusion.ProductVersion) GT 6>
			<cfreturn getMetadata(arguments.query)>
		</cfif>
		
		<cfset columns = arguments.query.getMetaData().getColumnLabels() />
		
		<cfloop from="1" to="#ArrayLen(columns)#" index="col">
			<cfset map = StructNew()>
			<cfset map.name = columns[col]>
			<cfset map.IsCaseSensitive = arguments.query.getMetaData().isCaseSensitive( javacast("int",col))>
			<cfset map.TypeName = arguments.query.getMetadata().getColumnTypeName(javacast("int",col))>
			<cfset ArrayAppend(metadata,map)>
		</cfloop>
		
		<cfreturn metadata>
	</cffunction>]]></starttext>
			               <endtext/>
			               <author>Marc Esher</author>
			               <platforms/>
			               <created>05-30-2010</created>
			               <lastupdated>05-30-2010</lastupdated>
			          </snippet>
					
				 	<snippet id="804" template="cfm">
			               <name>GetXmlAttribute</name>
			               <help><![CDATA[&lt;cfxml variable=&quot;XmlScheme&quot;&gt;
&lt;cfoutput&gt;
&lt;xmlscheme&gt;
	&lt;xmlnode oneatt=&quot;1&quot; threeatt=&quot;3&quot;&gt;Some Content&lt;/xmlnode&gt;
&lt;/xmlscheme&gt;
&lt;/cfoutput&gt;
&lt;/cfxml&gt;
&lt;cfdump var=&quot;#XmlScheme#&quot;&gt;
&lt;cfscript&gt;
	oneVar=GetXmlAttribute(XmlScheme.XmlRoot.XmlChildren[1],&quot;oneatt&quot;);
	WriteOutput(oneVar);
	twoVar=GetXmlAttribute(XmlScheme.XmlRoot.XmlChildren[1],&quot;twoatt&quot;,0);
	WriteOutput(twoVar);
&lt;/cfscript&gt;]]></help>
			               <description><![CDATA[This tag will allow you to retrieve an XML attribute from an XML node. Furthermore, if you are in the habit of needing default values in case the attribute's value is empty or the attribute does not exist, you can specify that as well.]]></description>
			               <starttext><![CDATA[<cffunction name="GetXmlAttribute" output="false" returntype="any">
	<cfargument name="node" type="any" required="yes">
	<cfargument name="attribute" type="string" required="Yes">
	<cfargument name="default" type="string" default="" required="false">
	<cfset var myResult="#arguments.default#">
	<cfif StructKeyExists(node.XmlAttributes, attribute)>
		<cfset myResult=node.XmlAttributes["#attribute#"]>
	</cfif>
	<cfreturn myResult>
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Kreig Zimmerman</author>
			               <platforms/>
			               <created>12-23-2002</created>
			               <lastupdated>12-23-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="705" template="cfm">
			               <name>GuidToString</name>
			               <help><![CDATA[&lt;!--- Non Working Example
&lt;cfquery name=&quot;source&quot; datasource=&quot;#ds#&quot;&gt;
   SELECT ID
   FROM RepID_Source
&lt;/cfquery&gt;

&lt;cfoutput&gt;#guidToString(source.ID)#&lt;/cfoutput&gt;
---&gt;]]></help>
			               <description><![CDATA[Useful when returning GUIDs (16-byte globally unique identifier, aka Replication ID's) from a database in CFMX. CF5 returned the GUIDs as a string when retrieved from a database and as such could easily be copied into SQL for another database call.  However, CFMX returns byte arrays and they need to be converted before they can be inserted into SQL.]]></description>
			               <starttext><![CDATA[function guidToString(guidByteArray) {
   var hexString='';
   
   if (IsArray(guidByteArray) AND ArrayLen(guidByteArray) GTE 16) {
     hexString=hexString & guidByteToHex(guidByteArray[4]);
     hexString=hexString & guidByteToHex(guidByteArray[3]);
     hexString=hexString & guidByteToHex(guidByteArray[2]);
     hexString=hexString & guidByteToHex(guidByteArray[1]);
     hexString=hexString & "-";
     hexString=hexString & guidByteToHex(guidByteArray[6]);
     hexString=hexString & guidByteToHex(guidByteArray[5]);
     hexString=hexString & "-";
     hexString=hexString & guidByteToHex(guidByteArray[8]);
     hexString=hexString & guidByteToHex(guidByteArray[7]);
     hexString=hexString & "-";
     hexString=hexString & guidByteToHex(guidByteArray[9]);
     hexString=hexString & guidByteToHex(guidByteArray[10]);
     hexString=hexString & "-";
     hexString=hexString & guidByteToHex(guidByteArray[11]);
     hexString=hexString & guidByteToHex(guidByteArray[12]);
     hexString=hexString & guidByteToHex(guidByteArray[13]);
     hexString=hexString & guidByteToHex(guidByteArray[14]);
     hexString=hexString & guidByteToHex(guidByteArray[15]);
     hexString=hexString & guidByteToHex(guidByteArray[16]);
   }
   
   return hexString;
}

function guidByteToHex(guidByte) {
   // Accepts a single byte and converts it to a two digit Hex number.
   
   var hexByte=Ucase(Right(FormatBaseN(guidByte, 16),2));
   if (Len(hexByte) IS 0) {
      hexByte='00';
   } else if (Len(hexByte) IS 1) {
      hexByte='0' & hexByte;
   }
   
   return hexByte;
}]]></starttext>
			               <endtext/>
			               <author>Samuel Neff</author>
			               <platforms/>
			               <created>09-06-2002</created>
			               <lastupdated>09-06-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="1367" template="cfm">
			               <name>isBit</name>
			               <help><![CDATA[&lt;cfset var1 = 1 /&gt;
&lt;cfset var2 = &quot;1&quot; /&gt;
&lt;cfset var3 = &quot;test string&quot; /&gt;
&lt;cfset var4 = &quot;-0&quot; /&gt;
&lt;cfset var5 = 000 /&gt;
&lt;cfset var6 = arrayNew(1) /&gt;
&lt;cfset var7 = 0 /&gt;

&lt;cfoutput&gt;
#isBit(var1)# - true&lt;br /&gt;
#isBit(var2)# - true&lt;br /&gt;
#isBit(var3)# - false&lt;br /&gt;
#isBit(var4)# - false&lt;br /&gt;
#isBit(var5)# - false&lt;br /&gt;
#isBit(var6)# - false&lt;br /&gt;
#isBit(var7)# - true&lt;br /&gt;
&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[isBit checks to see if a value is 1 or 0. This comes in handy when checking radio button values where you have two radio buttons with bit values. While this does not save a lot of typing, it does help, especially when your form has an abundance of radio buttons, etc.]]></description>
			               <starttext><![CDATA[function isBit(x){
   if(isSimpleValue(x) and len(x) eq 1 and (x eq 0 or x eq 1))
      return true;
   else
      return false;
}]]></starttext>
			               <endtext/>
			               <author>Mike Tangorre</author>
			               <platforms/>
			               <created>02-14-2006</created>
			               <lastupdated>02-14-2006</lastupdated>
			          </snippet>
					
				 	<snippet id="1202" template="cfm">
			               <name>isCachedQuery</name>
			               <help><![CDATA[&lt;cfquery name=&quot;test&quot; cachedwithin=&quot;#createtimespan(0,0,1,0)#&quot;&gt;
your query...
&lt;/cfquery&gt;

&lt;cfset isCached = isCachedQuery( &apos;test&apos; )&gt;]]></help>
			               <description><![CDATA[This UDF make use of service Factory to check wehther the queryname passed was run as a cached query.]]></description>
			               <starttext><![CDATA[<cffunction name="isCachedQuery" returntype="boolean" output="false">
	<cfargument name="queryname" required="true" type="string" />
	
	<cfset var events = "">
	<cfset var result = false>	
	<cfset var temp = "">
	
	<cfif isdebugmode()>
		<cfset events = createobject('java','coldfusion.server.ServiceFactory').getDebuggingService().getDebugger().getData()>
		<cfquery name="temp" dbtype="query">
			select	cachedquery
			from	events
			WHERE 	type='SqlQuery' 
					and name='#arguments.queryname#'
		</cfquery>
		<cfset result = yesnoformat(temp.cachedquery)>
	</cfif>

	<cfreturn result />
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Qasim Rasheed</author>
			               <platforms/>
			               <created>02-11-2005</created>
			               <lastupdated>02-11-2005</lastupdated>
			          </snippet>
					
				 	<snippet id="743" template="cfm">
			               <name>IsCFC</name>
			               <help><![CDATA[&lt;cfscript&gt;
	cfc = createObject(&quot;component&quot;,&quot;cflib.udf&quot;);
	str = createObject(&quot;java&quot;,&quot;java.lang.String&quot;);
&lt;/cfscript&gt;

&lt;cfoutput&gt;
	isCFC(cfc) = #isCFC(cfc)#&lt;br&gt;
	isCFC(str) = #isCFC(str)#&lt;br&gt;
	isCFC(structNew()) = #isCFC(structNew())#&lt;br&gt;
&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Pass it any CF variable, it returns a boolean value to tell you if it is a CFC instance.]]></description>
			               <starttext><![CDATA[function IsCFC(objectToCheck){
	//get the meta data of the object we're inspecting
	var metaData = getMetaData(arguments.objectToCheck);
	//if it's an object, let's try getting the meta Data
	if(isObject(arguments.objectToCheck)){
		//if it has a type, and that type is "component", then it's a component
		if(structKeyExists(metaData,"type") AND metaData.type is "component"){
			return true;
		}
	}	
	//if we've gotten here, it must not have been a contentObject			
	return false;		
}]]></starttext>
			               <endtext/>
			               <author>Nathan Dintenfass</author>
			               <platforms/>
			               <created>10-16-2002</created>
			               <lastupdated>10-16-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="838" template="cfm">
			               <name>IsCFCType</name>
			               <help><![CDATA[&lt;cfscript&gt;
	//create a component instance
	myCFC = createObject(&quot;component&quot;,&quot;CFIDE.componentutils.utils&quot;);
	//which types shall we check?
	typesToCheck = arrayNew(1);
	typesToCheck[1] = &quot;utils&quot;;
	typesToCheck[2] = &quot;CFIDE.componentutils.utils&quot;;
	typesToCheck[3] = &quot;banana&quot;;
	typesToCheck[4] = &quot;org.bacfug.utils&quot;;
&lt;/cfscript&gt;

&lt;!--- loop through the types to check, checking each one ---&gt;
&lt;cfloop from=&quot;1&quot; to=&quot;#arrayLen(typesToCheck)#&quot; index=&quot;ii&quot;&gt;
	&lt;cfset thisType = typesToCheck[ii]&gt;
	&lt;cfoutput&gt;
		Is myCFC a &lt;em&gt;#thisType#&lt;/em&gt;?: #yesNoFormat(isCFCType(myCFC,thisType))#&lt;br /&gt;
	&lt;/cfoutput&gt;
&lt;/cfloop&gt;

&lt;hr&gt;
&lt;cfdump var=&quot;#getMetaData(myCFC)#&quot;&gt;]]></help>
			               <description><![CDATA[Given a variable and a type to check for, this UDF returns a boolean value for whether the given variable is a component of the given type.

You can use either &quot;long notation&quot; (i.e.: &quot;org.bacfug.myCFC&quot;), which will check for the complete component type, or you can use &quot;short notation&quot; (i.e.: &quot;myCFC&quot;), which will check only the name of the component, without concern for where it sits in the directory hierarchy.

If you want to force full name checking, regardles off using long or short notation, pass a boolean value as an optional third argument.]]></description>
			               <starttext><![CDATA[function isCFCType(objectToCheck,type){
	//get the meta data of the object we're inspecting (we use duplicate so we don't mess with the instance)
	var metaData = getMetaData(arguments.objectToCheck);
	//are we going to check for a full name, or just the end?
	var checkFullName = true;
	//which component are we checking? (used to allow traversing the "extends" for extended components)
	var metaToCheck = metaData;
	//which name shall we check?
	var nameToCheck = metaData.name;
	//if the arguments.type has no periods, don't check the full name
	if(listLen(arguments.type,".") LTE 1)
		checkFullName = false;
	//allow a third argument to force the checkFullName
	if(structCount(arguments) GT 2)
		checkFullName = arguments[3];
	//if it's an object, see if it's the right kind of component
	if(isObject(arguments.objectToCheck)){
		//if it has a type, and that type is "component", then it's a component, so we then look at the type
		if(structKeyExists(metaData,"type") AND metaData.type is "component"){	
			//do a while loop to be sure we see if this component extends the type we want
			while(structKeyExists(metaToCheck,"extends")){
				//if we are not checking the full name, then take only the last element in the full name
				if(NOT checkFullName)
					nameToCheck = listLast(metaToCheck.name,".");
				else
					nameToCheck = metaToCheck.name;
				//if the name of the component we're looking at is the type we're looking for, return true
				if(nameToCheck is arguments.type)
					return true;
				//set this to the extends of the current component to traverse the meta data tree	
				metaToCheck = metaToCheck.extends;	
			}
		}
	}	
	//if we've gotten here, it must not have been a the right kind of object
	return false;		
}]]></starttext>
			               <endtext/>
			               <author>Nathan Dintenfass</author>
			               <platforms/>
			               <created>12-23-2002</created>
			               <lastupdated>12-23-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="968" template="cfm">
			               <name>isDefinedValue</name>
			               <help><![CDATA[&lt;cfset request.box = structnew()&gt;
&lt;cfset MyNewArray[1] = &quot;test&quot;&gt; 
&lt;cfset MyNewArray[2] = &quot;&quot;&gt; 
&lt;CFPARAM name = &quot;request.box.side&quot; DEFAULT = &quot;&quot;&gt;
&lt;CFPARAM name = &quot;simplevalue&quot; DEFAULT = &quot;#Now()#&quot;&gt;
&lt;cfparam name=&quot;URL.name&quot; default=&quot;&quot;&gt;
 &lt;cfparam name=&quot;url.test&quot; type=&quot;boolean&quot; default=&quot;1&quot;&gt;
     &lt;cfoutput&gt;#isDefinedValue(&quot;url.test&quot;)# &lt;/cfoutput&gt;

&lt;br&gt;&lt;br&gt; simplevalue
&lt;cfif isDefinedValue(&quot;simplevalue&quot;)&gt;
  &lt;br&gt; happy &lt;cfdump var=&quot;#simplevalue#&quot;&gt; 
&lt;cfelse&gt;
 &lt;br&gt; no joy simplevalue
&lt;/cfif&gt; 

&lt;br&gt;&lt;br&gt;Structure.Key
 &lt;cfif isDefinedValue(&quot;request.box.side&quot;)&gt;
  &lt;br&gt; happy &lt;cfdump var=&quot;#request.box#&quot;&gt; 
&lt;cfelse&gt;
  &lt;br&gt; no joy Structure Key
&lt;/cfif&gt; 

&lt;br&gt;&lt;br&gt;Structure 
&lt;cfif isDefined(&quot;request.box&quot; )&gt;
 &lt;br&gt;happy  &lt;cfdump var=&quot;#request.box#&quot;&gt; 
&lt;cfelse&gt;
  &lt;br&gt; no joy Structure
&lt;/cfif&gt; 



&lt;br&gt;&lt;br&gt; MyNewArray [1]
&lt;cfif isDefinedValue(&quot;MyNewArray[1]&quot;)&gt;
 &lt;br&gt; happy &lt;cfdump var=&quot;#MyNewArray#&quot;&gt;

&lt;cfelse&gt;
  &lt;br&gt; no joy MyNewArray
&lt;/cfif&gt; 

&lt;br&gt;&lt;br&gt; MyNewArray [2]
&lt;cfif isDefinedValue(&quot;MyNewArray[2]&quot;)&gt;
 &lt;br&gt; happy &lt;cfdump var=&quot;#MyNewArray#&quot;&gt;
&lt;cfelse&gt;
  &lt;br&gt; no joy MyNewArray
&lt;/cfif&gt; 

&lt;br&gt;&lt;br&gt; URL.name
&lt;cfif isDefinedValue(&quot;URL.name&quot;)&gt;
 &lt;br&gt; happy &lt;cfdump var=&quot;#URL.name#&quot;&gt;
&lt;cfelse&gt;
  &lt;br&gt; no joy URL.name
&lt;/cfif&gt; 
&lt;!--- make a query on the snippets datasource ---&gt;
&lt;br&gt;&lt;br&gt; With No Query
&lt;cfif IsDefinedValue(&quot;qGetEmployees&quot;)&gt; 
   &lt;br&gt; &lt;cfdump var=&quot;#qGetEmployees#&quot;&gt; 
&lt;cfelse&gt;
  &lt;br&gt; no joy qGetEmployees
&lt;/cfif&gt; 

&lt;br&gt;&lt;br&gt; With Results Query
&lt;cfdirectory action=&quot;list&quot; directory=&quot;#expandPath(&quot;/WEB-INF/debug/&quot;)#&quot; name=&quot;getFiles&quot;&gt;


&lt;P&gt;
&lt;cfdump var=&quot;#getFiles#&quot;&gt;

&lt;br&gt;&lt;br&gt; With Results Query&lt;br&gt;
&lt;cfif IsDefinedValue(&quot;getFiles&quot;)&gt; 
   Yes, the query exists and is not empty
&lt;/cfif&gt;  

&lt;br&gt;&lt;br&gt; With Results Query on field
&lt;cfif IsDefinedValue(&quot;getFiles.size&quot;)&gt; 
   &lt;br&gt; Yes, the field &quot;size&quot; is defined in the query &quot;getFiles&quot;
&lt;/cfif&gt;  

&lt;br&gt;&lt;br&gt; With No Results Query
&lt;cfquery name = &quot;getFilesFiltered&quot; dbType=&quot;query&quot;&gt;
    SELECT *
    FROM getFiles
    WHERE name = &apos;IDoNotExist&apos;
&lt;/cfquery&gt; 

&lt;cfif NOT IsDefinedValue(&quot;getFilesFiltered&quot;)&gt; 
   &lt;br&gt; No, this query is empty
&lt;/cfif&gt;]]></help>
			               <description><![CDATA[Checks that a variable is defined and  that  the variable  is not an empty value.  Optionally allows you to specify the &quot;correct&quot; value of the variable.
 
Use like isDefined function to confirm the variable has a value that is not empty. 
For a variable name:
- if defined and has value returns true
- if not defined returns false
- if is defined and has empty value returns false

varname is a string value like isDefined. 

 Checks arrays, structures, queries and simple variables.
  A checked value must be a simple value.
  A &quot;&quot; value will return false

Usage Notes. 
1) Array indexes, like myArray[1]. are checked by first removing the index to confirm the array is defined, then checks the indexed location for a simple value.    If  the index  is missing or bogus, the function throws an error.
2) Query record set results, like qGetEmployees.FirstName,  check the first record?s value, not the entire record  set.
3) Queries results with a zero record count return false.

 Simple Example: 
 &lt;cfparam name=&quot;url.test&quot; type=&quot;boolean&quot; default=&quot;1&quot;&gt;
     isDefinedValue(&quot;url.test&quot;) returns 1
          
  &lt;cfparam name=&quot;url.test&quot; type=&quot;string&quot; default=&quot;&quot;&gt;
   isDefinedValue(&quot;url.test&quot;) returns 0]]></description>
			               <starttext><![CDATA[function isDefinedValue(varname)
{
  var value = "";
    if (IsDefined(listfirst(Arguments[1],"[")))
     { 
     value = evaluate(Arguments[1]);
     if (IsSimpleValue(value))
        { 
            if (ArrayLen(Arguments) EQ 2 )
                { if ( value EQ Arguments[2]){return 1;}
                else return 0; 
                }
            else if ( find(value,"" )) {return 0;}  
            else return 1;  // something is there, just not testing for it.
        } 
     else if (IsStruct(value))
        { 
            if (StructIsEmpty(value)) { return 0;} 
            else {return 1;}
        }
     else if (IsArray(value))
        { 
            if (ArrayIsEmpty(value)) {return 0;} 
            else {return 1;}
        }
     else if (IsQuery(value))
        { 
            if (YesNoFormat(value.recordcount)) {return 1;} 
            else {return 0;}
        }
    return 0;
      }
return 0;
}]]></starttext>
			               <endtext/>
			               <author>Joseph Flanigan</author>
			               <platforms/>
			               <created>08-18-2003</created>
			               <lastupdated>08-18-2003</lastupdated>
			          </snippet>
					
				 	<snippet id="990" template="cfm">
			               <name>isDefinedValueMX</name>
			               <help><![CDATA[&lt;cfset request.box = structnew()&gt;
&lt;cfset MyNewArray[1] = &quot;test&quot;&gt; 
&lt;cfset MyNewArray[2] = &quot;&quot;&gt; 
&lt;CFPARAM name = &quot;request.box.side&quot; DEFAULT = &quot;&quot;&gt;
&lt;CFPARAM name = &quot;simplevalue&quot; DEFAULT = &quot;#Now()#&quot;&gt;
&lt;cfparam name=&quot;URL.name&quot; default=&quot;&quot;&gt;
&lt;cfparam name=&quot;url.test&quot; type=&quot;boolean&quot; default=&quot;1&quot;&gt;
&lt;cfoutput&gt;#isDefinedValue(&quot;url.test&quot;)# &lt;/cfoutput&gt;

&lt;br&gt;&lt;br&gt; simplevalue
&lt;cfif isDefinedValueMX(&quot;simplevalue&quot;)&gt;
&lt;br&gt; happy &lt;cfdump var=&quot;#simplevalue#&quot;&gt; 
&lt;cfelse&gt;
&lt;br&gt; no joy simplevalue
&lt;/cfif&gt; 

&lt;br&gt;&lt;br&gt;Structure.Key
&lt;cfif isDefinedValueMX(&quot;request.box.side&quot;)&gt;
&lt;br&gt; happy &lt;cfdump var=&quot;#request.box#&quot;&gt; 
&lt;cfelse&gt;
&lt;br&gt; no joy Structure Key
&lt;/cfif&gt; 

&lt;br&gt;&lt;br&gt;Structure 
&lt;cfif isDefinedMX(&quot;request.box&quot; )&gt;
&lt;br&gt;happy &lt;cfdump var=&quot;#request.box#&quot;&gt; 
&lt;cfelse&gt;
&lt;br&gt; no joy Structure
&lt;/cfif&gt; 


&lt;br&gt;&lt;br&gt; MyNewArray [1]
&lt;cfif isDefinedValueMX(&quot;MyNewArray[1]&quot;)&gt;
&lt;br&gt; happy &lt;cfdump var=&quot;#MyNewArray#&quot;&gt;

&lt;cfelse&gt;
&lt;br&gt; no joy MyNewArray
&lt;/cfif&gt; 

&lt;br&gt;&lt;br&gt; MyNewArray [2]
&lt;cfif isDefinedValueMX(&quot;MyNewArray[2]&quot;)&gt;
&lt;br&gt; happy &lt;cfdump var=&quot;#MyNewArray#&quot;&gt;
&lt;cfelse&gt;
&lt;br&gt; no joy MyNewArray
&lt;/cfif&gt; 

&lt;br&gt;&lt;br&gt; URL.name
&lt;cfif isDefinedValueMX(&quot;URL.name&quot;)&gt;
&lt;br&gt; happy &lt;cfdump var=&quot;#URL.name#&quot;&gt;
&lt;cfelse&gt;
&lt;br&gt; no joy URL.name
&lt;/cfif&gt; 
&lt;!--- make a query on the snippets datasource ---&gt;
&lt;br&gt;&lt;br&gt; With No Query
&lt;cfif IsDefinedValueMX(&quot;qGetEmployees&quot;)&gt; 
&lt;br&gt; &lt;cfdump var=&quot;#qGetEmployees#&quot;&gt; 
&lt;cfelse&gt;
&lt;br&gt; no joy qGetEmployees
&lt;/cfif&gt; 

&lt;br&gt;&lt;br&gt; With Results Query
&lt;cfdirectory action=&quot;list&quot; directory=&quot;#expandPath(&quot;/WEB-INF/debug/&quot;)#&quot; name=&quot;getFiles&quot;&gt;


&lt;P&gt;
&lt;cfdump var=&quot;#getFiles#&quot;&gt;

&lt;br&gt;&lt;br&gt; With Results Query&lt;br&gt;
&lt;cfif IsDefinedValueMX(&quot;getFiles&quot;)&gt; 
Yes, the query exists and is not empty
&lt;/cfif&gt; 

&lt;br&gt;&lt;br&gt; With Results Query on field
&lt;cfif IsDefinedValueMX(&quot;getFiles.size&quot;)&gt; 
&lt;br&gt; Yes, the field &quot;size&quot; is defined in the query &quot;getFiles&quot;
&lt;/cfif&gt; 

&lt;br&gt;&lt;br&gt; With No Results Query
&lt;cfquery name = &quot;getFilesFiltered&quot; dbType=&quot;query&quot;&gt;
SELECT *
FROM getFiles
WHERE name = &apos;IDoNotExist&apos;
&lt;/cfquery&gt; 

&lt;cfif NOT IsDefinedValueMX(&quot;getFilesFiltered&quot;)&gt; 
&lt;br&gt; No, this query is empty
&lt;/cfif&gt;]]></help>
			               <description><![CDATA[Use like isDefined for variables plus confirm the variable has an assigned value. For a named variable,  if it is defined and has value returns 1,  if it is not defined returns 0; if it is defined and has empty value returns 0.  Optionally, allows specifying a check value to test the named variable for a specific value. This extends the function by, if it is defined and has this value, then return 1. A checked value must be a simple value or an empty string.
isDefinedValueMX improves on the isDefinedValue CF5 version and built-in isDefined by returning a 0 on error conditions. 
Usage Notes. 1) Array indexes, like myArray[1]. are checked by first removing the index to confirm the array is defined, then checks the indexed location for a simple value. If the index is missing or bogus, the function returns 0. 2) Query record set results, checks the first record?s value, not the entire record set. 3) Queries results with a zero record count return 0. 
Example: &lt;cfparam name=&quot;url.test&quot; default=&quot;1&quot;&gt; isDefinedValue(&quot;url.test&quot;) returns 1 &lt;cfparam name=&quot;url.test&quot; default=&quot;&quot;&gt; isDefinedValue(&quot;url.test&quot;) returns 0 and isDefinedValue(&quot;url.test&quot;,??) returns 1]]></description>
			               <starttext><![CDATA[function isDefinedValueMX(varname)
{
  var varvalue = "";
    try{
    if (IsDefined(listfirst(Arguments[1],"[")))
     { 
     varvalue = evaluate(Arguments[1]);

     if (IsSimpleValue(varvalue))
        { 
            if (ArrayLen(Arguments) EQ 2 )
                { if ( varvalue EQ Arguments[2]){return 1;}
                else return 0; 
                }
            else if ( find(varvalue,"" )) {return 0;}  
            else return 1;  // something is there, just not testing for it.
        } 
     else if (IsStruct(varvalue))
        { 
            if (StructIsEmpty(varvalue)) { return 0;} 
            else {return 1;}
        }
     else if (IsArray(varvalue))
        { 
            if (ArrayIsEmpty(varvalue)) {return 0;} 
            else {return 1;}
        }
     else if (IsQuery(varvalue))
        { 
            if (YesNoFormat(varvalue.recordcount)) {return 1;} 
            else {return 0;}
        }
    return 0; // not defined
      }
     } //try
     catch(Any excpt)
      { return 0;} // return excpt.Message;
return 0; 
}]]></starttext>
			               <endtext/>
			               <author>Joseph Flanigan</author>
			               <platforms/>
			               <created>10-20-2003</created>
			               <lastupdated>10-20-2003</lastupdated>
			          </snippet>
					
				 	<snippet id="420" template="cfm">
			               <name>IsEmpty</name>
			               <help><![CDATA[&lt;cfset myVar = 1&gt;
&lt;cfset myVar3 = arrayNew(1)&gt;
&lt;cfset myVar4 = arrayNew(1)&gt;
&lt;cfset myVar4[1] = &quot;e&quot;&gt;
&lt;cfset myVar5 = structNew()&gt;
&lt;cfset myVar6 = structNew()&gt;
&lt;cfset myVar6.name = &quot;ray&quot;&gt;
&lt;cfset myVar7 = queryNew(&quot;F&quot;)&gt;
&lt;cfset myVar8 = queryNew(&quot;F&quot;)&gt;
&lt;cfset queryAddRow(myVar8,1)&gt;

&lt;cfoutput&gt;
IsEmpty(&quot;myvar&quot;) = #isEmpty(&quot;myVar&quot;)#&lt;br&gt;
IsEmpty(&quot;myvar2&quot;) = #isEmpty(&quot;myVar2&quot;)#&lt;br&gt;
IsEmpty(&quot;myvar3&quot;) = #isEmpty(&quot;myVar3&quot;)#&lt;br&gt;
IsEmpty(&quot;myvar4&quot;) = #isEmpty(&quot;myVar4&quot;)#&lt;br&gt;
IsEmpty(&quot;myvar5&quot;) = #isEmpty(&quot;myVar5&quot;)#&lt;br&gt;
IsEmpty(&quot;myvar6&quot;) = #isEmpty(&quot;myVar6&quot;)#&lt;br&gt;
IsEmpty(&quot;myvar7&quot;) = #isEmpty(&quot;myVar7&quot;)#&lt;br&gt;
IsEmpty(&quot;myvar8&quot;) = #isEmpty(&quot;myVar8&quot;)#&lt;br&gt;
&lt;/cfoutput&gt;

&lt;cfif isEmpty(&quot;myVar&quot;)&gt;
&lt;cfset myVar = &quot;Pippo&quot;&gt;
&lt;/cfif&gt;]]></help>
			               <description><![CDATA[Check if a variable is set and has a value. This UDF will check to see if the variable is an array, structure, or query. If so, it will check to see if any data exists in the variable, and if not, will return true.]]></description>
			               <starttext><![CDATA[function isEmpty(varName) {
	var ptr = "";
	
	if(not isDefined(varName)) return true;
	ptr = evaluate(varName);
	
	if(isSimpleValue(ptr)) {
		if(not len(ptr)) return true;
	} else if(isArray(ptr)) {
		if(arrayIsEmpty(ptr)) return true;
	} else if(isStruct(ptr)) {
		if(structIsEmpty(ptr)) return true;
	} else if(isQuery(ptr)) {
		if(not ptr.recordCount) return true;
	}
		
	return false;
}]]></starttext>
			               <endtext/>
			               <author>Fabio Serra</author>
			               <platforms/>
			               <created>07-10-2003</created>
			               <lastupdated>07-10-2003</lastupdated>
			          </snippet>
					
				 	<snippet id="644" template="cfm">
			               <name>IsNull</name>
			               <help><![CDATA[&lt;cfparam name=&quot;DieSizeX&quot; Default = &quot;&quot;&gt;
&lt;cfoutput&gt;
Is DieSizeX NULL: #IsNull(DieSizeX)#
&lt;/cfoutput&gt;
&lt;p&gt;
Here&apos;s what it would look like in an SP:
&lt;p&gt;
cfprocparam type=&quot;In&quot; cfsqltype=&quot;CF_SQL_VARCHAR&quot; dbvarname=&quot;@pack&quot; value=&quot;#Attributes.package_type#&quot; maxlength=&quot;25&quot; null=&quot;#IsNull(Attributes.package_type)#&quot;]]></help>
			               <description><![CDATA[Returns True if the value passed to it represents &quot;NULL&quot;.  Useful for setting NULLs in the NULL attribute of CFPROCPARAM.]]></description>
			               <starttext><![CDATA[function IsNull(val){
  var NullIdentifier = "";
  if (ArrayLen(Arguments) gte 2) 
    NullIdentifier = Arguments[2];
  if (val is NullIdentifier) {
    return True;
  }
  else {
    return False;
  }
}]]></starttext>
			               <endtext/>
			               <author>Rob Brooks-Bilson</author>
			               <platforms/>
			               <created>05-01-2002</created>
			               <lastupdated>05-01-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="633" template="cfm">
			               <name>IsSafeArray</name>
			               <help><![CDATA[&lt;cfscript&gt;
a = arrayNew(1);
a[1] = &quot;d&quot;;
a[2] = &quot;e&quot;;
a[4] = &quot;f&quot;;
writeOutput(&quot;Is a complete? &quot; &amp; IsSafeArray(a));
&lt;/cfscript&gt;]]></help>
			               <description><![CDATA[Returns true if all positions in an array are defined.]]></description>
			               <starttext><![CDATA[function IsSafeArray(arr) {
	var i=1;
	var temp = "";
	
	for(i=1; i lte arrayLen(arr); i=i+1) {
		try {
			temp = arr[i];
		} catch(coldfusion.runtime.UndefinedElementException ex) {
			return false;
		}		
	}
	
	return true;
}]]></starttext>
			               <endtext/>
			               <author>Raymond Camden</author>
			               <platforms/>
			               <created>04-29-2002</created>
			               <lastupdated>04-29-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="993" template="cfm">
			               <name>IsXML</name>
			               <help><![CDATA[&lt;cfsavecontent variable=&quot;packet&quot;&gt;
&lt;foo&gt;&lt;/foo&gt;
&lt;/cfsavecontent&gt;

&lt;cfoutput&gt;
Is packet XML? #isXML(packet)#&lt;br&gt;
Is &quot;jedi&quot; a packet? #isXML(&quot;jedi&quot;)#
&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Checks to see if a string is valid XML.]]></description>
			               <starttext><![CDATA[<cffunction name="isXML" returnType="boolean" output="no">
   <cfargument name="data" type="string" required="yes">

   <!--- try catch block --->
   <cftry>
      <!--- try to parse the data as xml --->
      <cfset xmlparse(data)>
      <!--- if xmlparse() fails, it is not xml --->
      <cfcatch type="any">
         <cfreturn false>
      </cfcatch>
   </cftry>

   <cfreturn true>
   
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Ben Forta</author>
			               <platforms/>
			               <created>08-28-2003</created>
			               <lastupdated>08-28-2003</lastupdated>
			          </snippet>
					
				 	<snippet id="1160" template="cfm">
			               <name>LenStruct</name>
			               <help><![CDATA[&lt;cfscript&gt;
// Create test struct and set vars
test = StructNew();
test.a = &quot;a&quot;;
test.bb = &quot;bb&quot;;
test.ccc = &quot;ccc&quot;;
// With no optional ending or exludelist
test_len = LenStruct(test);
&lt;/cfscript&gt;

&lt;cfdump var=&quot;#test_len#&quot;&gt;]]></help>
			               <description><![CDATA[Computes the length of every key in the passed structure.  Optionally allows you to set the end stem of the returned struct. The return structure keys are the same as the passed structure keys plus the end stem is appended (default: &quot;_Len&quot;).  Also, allows you to pass an exclude list of keys not to return if you wish to only get lens on some of the passed structure.  This UDF will not process complex data types - simple values only.  Great to use on the form scope (which is a stucture itself) if you do len checking for data validation passed from forms.

Feel free to modify if you wish to recursively go through nested structures.

Thanks to Mike Gillespie and Raymond Camden and their TrimStruct UDF for giving me this idea.]]></description>
			               <starttext><![CDATA[function LenStruct(structIn) {
	var i = 0;
	var structIn_count = StructCount(structIn);
	var struct0ut = StructNew();
	var ending = "_Len";
	var excludeList = "";
	var key = "";
	
	// Check if excludeList was passed
	if(arrayLen(Arguments) GT 1) {
		excludeList = Arguments[2];
	} 
	
	// Check if different ending was passed
	if(arrayLen(Arguments) GT 2) {
		ending = Arguments[3];
	} 
	for (key IN structIn) {
		if (NOT listFindNoCase(excludeList,key) AND isSimpleValue(structIn[key])) {
			structOut[key&ending] = Len(structIn[key]);
		} 
	} 
	return structOut;
}]]></starttext>
			               <endtext/>
			               <author>Peter J. Farrell</author>
			               <platforms/>
			               <created>10-05-2004</created>
			               <lastupdated>10-05-2004</lastupdated>
			          </snippet>
					
				 	<snippet id="2007" template="cfm">
			               <name>listToQuery</name>
			               <help><![CDATA[&lt;cfset my_list = &apos;one,two&apos;&gt;
&lt;cfset my_query = listToQuery(my_list)&gt;
&lt;cfdump var=&quot;#my_query#&quot;&gt;]]></help>
			               <description><![CDATA[Converts a list to a single-column query.]]></description>
			               <starttext><![CDATA[<cffunction name="listToQuery" access="public" returntype="query" output="false" 
	hint="Converts a list to a single-column query.">
    <cfargument name="list" type="string" required="yes" hint="List to convert.">
    <cfargument name="delimiters" type="string" required="no" default="," hint="Things that separate list elements.">
    <cfargument name="column_name" type="string" required="no" default="column" hint="Name to give query column.">
    
    <cfset var query = queryNew(arguments.column_name)>
    <cfset var index = ''>
    
    <cfloop list="#arguments.list#" index="index" delimiters="#arguments.delimiters#">
        <cfset queryAddRow(query)>
        <cfset querySetCell(query,arguments.column_name,index)>
    </cfloop>
    
    <cfreturn query>
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Russ Spivey</author>
			               <platforms/>
			               <created>09-09-2009</created>
			               <lastupdated>09-09-2009</lastupdated>
			          </snippet>
					
				 	<snippet id="426" template="cfm">
			               <name>ListToStruct</name>
			               <help><![CDATA[&lt;CFSET MyList=&quot;key1=value1&amp;key2=value2&amp;key3=value3&quot;&gt;
&lt;CFSET x=ListToStruct(MyList, &quot;&amp;&quot;)&gt;
&lt;CFSET y=ListToStruct(&quot;a=1: b=2: c=3&quot;, &quot;:&quot;)&gt;

&lt;CFDUMP VAR=&quot;#x#&quot;&gt;
&lt;CFDUMP VAR=&quot;#y#&quot;&gt;]]></help>
			               <description><![CDATA[Converts a delimited list of key/value pairs to a structure.  This function gives you the equivalent of StructNew() with constructor support.]]></description>
			               <starttext><![CDATA[function listToStruct(list){
       var myStruct = StructNew();
       var i = 0;
       var delimiter = ",";
       var tempList = arrayNew(1);
       if (ArrayLen(arguments) gt 1) {delimiter = arguments[2];}
       tempList = listToArray(list, delimiter);
       for (i=1; i LTE ArrayLen(tempList); i=i+1){
               if (not structkeyexists(myStruct, trim(ListFirst(tempList[i], "=")))) {
                       StructInsert(myStruct, trim(ListFirst(tempList[i], "=")), trim(ListLast(tempList[i], "=")));
               }
       }
       return myStruct;
}]]></starttext>
			               <endtext/>
			               <author>Rob Brooks-Bilson</author>
			               <platforms/>
			               <created>04-01-2010</created>
			               <lastupdated>04-01-2010</lastupdated>
			          </snippet>
					
				 	<snippet id="1256" template="cfm">
			               <name>ListToStructRepeatKeys</name>
			               <help><![CDATA[&lt;cfset tempIn = &quot;a=1;b=2;b=3;c=4&quot;&gt;
&lt;cfdump var=&quot;#ListToStructRepeatKeys(tempIn,&quot;;&quot;)#&quot;&gt;]]></help>
			               <description><![CDATA[Based on ListToStruct() from Rob Brooks-Bilson, this one allows the structure key to be repeated. In the case of multiple values for a particular key, a comma-delimited list is created. Useful for parsing strings such as LDAP DNs, which may contain multiple values for a single key.]]></description>
			               <starttext><![CDATA[function listToStructRepeatKeys(list){
  var myStruct=StructNew();
  var i=0;
  var delimiter=",";
  var tempVar="";

  if(arrayLen(arguments) gt 1) delimiter = arguments[2];

  for(i=listLen(list, delimiter); i gt 0; i=i-1) {
  	tempVar = trim(listGetAt(list, i, delimiter));
  	if (structKeyExists(myStruct,listFirst(tempVar, "="))) {
		myStruct[listFirst(tempVar, "=")] = listAppend(myStruct[listFirst(tempVar, "=")],listLast(tempVar, "="));
	} else {
		myStruct[listFirst(tempVar, "=")] = listLast(tempVar, "=");
	}
  }
  return myStruct;
}]]></starttext>
			               <endtext/>
			               <author>Tony Brandner</author>
			               <platforms/>
			               <created>08-03-2005</created>
			               <lastupdated>08-03-2005</lastupdated>
			          </snippet>
					
				 	<snippet id="1188" template="cfm">
			               <name>maketree</name>
			               <help><![CDATA[&lt;cfscript&gt;
	q = querynew( &apos;id,text,parent&apos; );
	queryaddrow( q );
	querysetcell( q, &apos;id&apos;, 1 );
	querysetcell( q, &apos;text&apos;, &apos;One&apos; );
	querysetcell( q, &apos;parent&apos;, 0 );
	queryaddrow( q );
	querysetcell( q, &apos;id&apos;, 2 );
	querysetcell( q, &apos;text&apos;, &apos;Two&apos; );
	querysetcell( q, &apos;parent&apos;, 1 );
	queryaddrow( q );
	querysetcell( q, &apos;id&apos;, 3 );
	querysetcell( q, &apos;text&apos;, &apos;Three&apos; );
	querysetcell( q, &apos;parent&apos;, 0 );
&lt;/cfscript&gt;
&lt;cfset temp = maketree( q, &apos;id&apos;, &apos;parent&apos; )&gt;
&lt;cfdump var=&quot;#temp#&quot;&gt;]]></help>
			               <description><![CDATA[This function will take a query that is in a LEGAL parent/child relationship and sort it. The entire query will be sorted and an additional field called &quot;sortlevel&quot; will be added to specify the level of a particular item.]]></description>
			               <starttext><![CDATA[function maketree( query, unique, parent ){
	var current = 0;
	var path = 0;
	var i = 0;
	var j = 0;
	var items = "";
	var parents = "";
	var position = "";
	var column = "";
	var retQuery = querynew( query.columnlist & ',sortlevel' );
	for (i=1;i lte query.recordcount;i=i+1)
		items = listappend( items, query[unique][i] );
	for (i=1;i lte query.recordcount;i=i+1)
		parents = listappend( parents, query[parent][i] );
	
	for (i=1;i lte query.recordcount;i=i+1){
		queryaddrow( retQuery );
		position = listfind( parents, current );
		while (not position){
			path= listrest( path );
			current = listfirst( path );
			position = listfind( parents, current );
		}
		for (j=1;j lte listlen( query.columnlist ); j=j+1){
			column = listgetat( query.columnlist, j );
			querysetcell( retQuery, column, evaluate( 'query.'&column&'[position]') );
		}
		querysetcell( retQuery, 'sortlevel', listlen( path ) );
		current = listgetat( items, position );
		parents = listsetat( parents, position, '-' );
		path = listprepend( path, current);
	}
	return retQuery;
}]]></starttext>
			               <endtext/>
			               <author>Qasim Rasheed</author>
			               <platforms/>
			               <created>02-17-2005</created>
			               <lastupdated>02-17-2005</lastupdated>
			          </snippet>
					
				 	<snippet id="597" template="cfm">
			               <name>MinusMinusCounter</name>
			               <help><![CDATA[&lt;cfset i=3&gt;
&lt;cfset aArray = arrayNew(1)&gt;
&lt;cfset aArray[minusMinusCounter(&quot;i&quot;)]=&quot;Hans&quot;&gt;
&lt;cfset aArray[minusMinusCounter(&quot;i&quot;)]=&quot;Otto&quot;&gt;

&lt;cfoutput&gt;
#i#
&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Simulate the c functionality of --i. Decrements a counter and returns the dencremented counter.]]></description>
			               <starttext><![CDATA[function minusMinusCounter(intCounter){
	"#intCounter#" = evaluate(intCounter) - 1;
	return evaluate(intCounter);
}]]></starttext>
			               <endtext/>
			               <author>Stephan Scheele</author>
			               <platforms/>
			               <created>04-17-2002</created>
			               <lastupdated>04-17-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="1628" template="cfm">
			               <name>nullQuery</name>
			               <help><![CDATA[&lt;cfset taxes = queryNew(&quot;year,receipts,donations&quot;)&gt;
&lt;cfset taxes=nullQuery(Taxes,&quot;Year|Receipts|Donations&quot;,&quot;#Year(Now())#|0|0&quot;)&gt;
&lt;cfdump var=&quot;#taxes#&quot;&gt;]]></help>
			               <description><![CDATA[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.]]></description>
			               <starttext><![CDATA[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;
}]]></starttext>
			               <endtext/>
			               <author>John Bartlett</author>
			               <platforms/>
			               <created>08-10-2007</created>
			               <lastupdated>08-10-2007</lastupdated>
			          </snippet>
					
				 	<snippet id="595" template="cfm">
			               <name>PlusPlusCounter</name>
			               <help><![CDATA[&lt;cfset i=0&gt;
&lt;cfset aArray = arrayNew(1)&gt;
&lt;cfset aArray[plusPlusCounter(&quot;i&quot;)]=&quot;Hans&quot;&gt;
&lt;cfset aArray[plusPlusCounter(&quot;i&quot;)]=&quot;Otto&quot;&gt;

&lt;cfoutput&gt;
#i#
&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Simulate the c functionality of ++i. Increments a counter and returns the increment counter.]]></description>
			               <starttext><![CDATA[function plusPlusCounter(intCounter) {
	"#intCounter#" = evaluate(intCounter) + 1;
	return evaluate(intCounter);
}]]></starttext>
			               <endtext/>
			               <author>Stephan Scheele</author>
			               <platforms/>
			               <created>04-17-2002</created>
			               <lastupdated>04-17-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="560" template="cfm">
			               <name>Query2Excel</name>
			               <help><![CDATA[&lt;cfscript&gt;
	cols = &quot;sName,sAge&quot;;
	heads = &quot;First Name,Age&quot;;
	data = queryNew(cols);
	queryAddRow(data,2);
	querySetCell(data,&quot;sName&quot;,&quot;Joe&quot;,1);
	querySetCell(data,&quot;sAge&quot;,&quot;25&quot;,1);
	querySetCell(data,&quot;sName&quot;,&quot;John&quot;,2);
	querySetCell(data,&quot;sAge&quot;,&quot;30&quot;,2);
&lt;/cfscript&gt;
&lt;!--- Uncomment when testing.
&lt;CFHEADER NAME=&quot;Content-Disposition&quot; VALUE=&quot;inline; filename=foo.xls&quot;&gt;
&lt;cfcontent type=&quot;application/msexcel&quot;&gt;---&gt;&lt;cfoutput&gt;#Query2Excel(data,heads,cols,&quot;DDDDDD&quot;)#&lt;/cfoutput&gt;&lt;!---&lt;cfabort&gt;---&gt;]]></help>
			               <description><![CDATA[By passing in a query, list of query columns, and list of display headers and an alternating row color you can create content that can be saved directly with a .xls extension.  Must be able to use the CFCONTENT tag.]]></description>
			               <starttext><![CDATA[function Query2Excel(query) {
	var InputColumnList = query.columnList;
	var Headers = query.columnList;

	var AlternateColor = "FFFFFF";
	var header = "";
	var headerLen = 0;
	var col = "";
	var colValue = "";
	var colLen = 0;
	var i = 1;
	var j = 1;
	var k = 1;
	
	var HTMLData = "";
	
	if (arrayLen(arguments) gte 2) {
		Headers = arguments[2];
	}
	if (arrayLen(arguments) gte 3) {
		InputColumnList = arguments[3];
	}

	if (arrayLen(arguments) gte 4) {
		AlternateColor = arguments[4];
	}
	if (listLen(InputColumnList) neq listLen(Headers)) {
		return "Input Column list and Header list are not of equal length";
	}
	
	HTMLData = HTMLData & "<table border=1><tr bgcolor=""C0C0C0"">";
	for (i=1;i lte ListLen(Headers);i=i+1){
		header=listGetAt(Headers,i);
		headerLen=Len(header)*10;
		HTMLData = HTMLData & "<th width=""#headerLen#""><b>#header#</b></th>";
	}
	HTMLData = HTMLData & "</tr>";
	for (j=1;j lte query.recordcount;j=j+1){
		if (j mod 2) {
			HTMLData = HTMLData & "<tr bgcolor=""FFFFFF"">";
		} else {
			HTMLData = HTMLData & "<tr bgcolor=""#alternatecolor#"">";
		}
		for (k=1;k lte ListLen(InputColumnList);k=k+1) {
			col=ListGetAt(InputColumnList,k);
			colValue=query[trim(col)][j];
			colLength=Len(colValue)*10;
			if (NOT Len(colValue)) {
				colValue="&nbsp;";
			} 
			if (isNumeric(colValue) and Len(colValue) gt 10) {
				colValue="'#colValue#";
			} 
			HTMLData = HTMLData & "<td width=""#colLength#"">#colValue#</td>";
		}
	HTMLData = HTMLData & "</tr>";
	}
	HTMLData = HTMLData & "</table>";
	
	return HTMLData;
}]]></starttext>
			               <endtext/>
			               <author>Jesse Monson</author>
			               <platforms/>
			               <created>02-23-2005</created>
			               <lastupdated>02-23-2005</lastupdated>
			          </snippet>
					
				 	<snippet id="1299" template="cfm">
			               <name>queryAddColumnWithValue</name>
			               <help><![CDATA[&lt;cfset foo = queryNew(&quot;name&quot;)&gt;
&lt;cfloop index=&quot;x&quot; from=&quot;1&quot; to=&quot;10&quot;&gt;
	&lt;cfset queryAddRow(foo)&gt;
	&lt;cfset querySetCell(foo, &quot;name&quot;, &quot;Name #x#&quot;)&gt;
&lt;/cfloop&gt;

&lt;cfset queryAddColumnWithValue(foo, &quot;age&quot;, &quot;20&quot;)&gt;

&lt;cfdump var=&quot;#foo#&quot;&gt;]]></help>
			               <description><![CDATA[Adds a column filled with a value to a query object.]]></description>
			               <starttext><![CDATA[<cffunction name="queryAddColumnWithValue" returntype="boolean" output="false">
	<cfargument name="query" type="query" required="true" />
	<cfargument name="column_name" type="string" required="true" />
	<cfargument name="value" type="string" required="false" default="" />
	<cfset var arr=arrayNew(1) />
	
	<cfscript>
		arraySet(arr,1,arguments.query.recordCount,arguments.value);
		queryAddColumn(arguments.query, arguments.column_name, arr);
	</cfscript>

	<cfreturn true>
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Gabriele Bernuzzi</author>
			               <platforms/>
			               <created>12-13-2005</created>
			               <lastupdated>12-13-2005</lastupdated>
			          </snippet>
					
				 	<snippet id="1207" template="cfm">
			               <name>queryBeanToQuery</name>
			               <help><![CDATA[&lt;cfscript&gt;
	objQueryBean = createObject( &quot;java&quot;, &quot;coldfusion.xml.rpc.QueryBean&quot; );
	arrValues = arrayNew(1);
	arrColumns = arrayNew(1);
	arrColumns[1] = &quot;ID&quot;;
	arrColumns[2] = &quot;Name&quot;;
	// add a row
	arrValues[1] = arrayNew(1);
	arrValues[1][1] = &quot;my id&quot;;
	arrValues[1][2] = &quot;my name&quot;;
	// add a row
	arrValues[2] = arrayNew(1);
	arrValues[2][1] = &quot;your id&quot;;
	arrValues[2][2] = &quot;your name&quot;;
	// set up the QueryBean
	objQueryBean.setColumnList(arrColumns);
	objQueryBean.setData( arrValues );
&lt;/cfscript&gt;
&lt;cfoutput&gt;
	The QueryBean object:
&lt;/cfoutput&gt;
&lt;cfdump var=&quot;#objQueryBean#&quot;&gt;
&lt;cfoutput&gt;
	Converted to a query:
&lt;/cfoutput&gt;
&lt;cfset objMyQuery = queryBeanToQuery( objQueryBean ) /&gt;
&lt;Cfdump var=&quot;#objMyQuery#&quot; /&gt;]]></help>
			               <description><![CDATA[Pass it a Java QueryBean object, and it will return an equivalent ColdFusion query object - handy for dealing with complex data from webservices.

If the passed object is not a QueryBean, it will output a message and return an empty query.]]></description>
			               <starttext><![CDATA[function queryBeanToQuery(objQueryBean) {
	var qry_return = "";
	var arrColumns = ArrayNew(1);
	var arrRows = arrayNew(1);
	var thisRow = 0;
	var thisCol = 0;
	var numRows = 0;
	var thisVal = "";
	
	if( objQueryBean.getClass() EQ "class coldfusion.xml.rpc.QueryBean" ){
		arrColumns = objQueryBean.getColumnList();
		numCols = arrayLen( arrColumns );
		arrRows = objQueryBean.getData();
		numRows = arrayLen( arrRows );
		// create the return query object
		qry_return = QueryNew( ArrayToList(arrColumns) );
		// loop round each row
		for( thisRow = 1; thisRow LTE numRows; thisRow = thisRow + 1 ){
			QueryAddRow( qry_return );
			// loop round each column
			for( thisCol = 1; thisCol LTE numCols; thisCol = thisCol + 1 ){
				// empty columns seem to give rise to undefined array elements!
				try{
					thisVal = arrRows[thisRow][thisCol];
				} 
				catch(Any e) {
					thisVal = "";
				}
				QuerySetCell( qry_return, arrColumns[thisCol], thisVal );
			}
		}
		return qry_return;
		
	} else return queryNew("");
}]]></starttext>
			               <endtext/>
			               <author>Alistair Davidson</author>
			               <platforms/>
			               <created>05-20-2005</created>
			               <lastupdated>05-20-2005</lastupdated>
			          </snippet>
					
				 	<snippet id="1410" template="cfm">
			               <name>queryColumns</name>
			               <help><![CDATA[&lt;cfquery name=&quot;foo&quot; datasource=&quot;cflib&quot;&gt;
select id, Description, name
from tbludfs
&lt;/cfquery&gt;

&lt;cfoutput&gt;
#querycolumns(foo)#
&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Returns the columns in a query in the same order and case returned by the database. Note that you can get the same information in CFMX7 using the result attribute for cfquery.]]></description>
			               <starttext><![CDATA[function queryColumns(dbquery) {
	var queryFields = "";
	var metadata = dbquery.getMetadata();
	var i = 0;
	var col = "";
	
	for (i = 1; i lte metadata.getColumnCount(); i = i+1) {
		col = metadata.getColumnLabel(javaCast("int", i));
		queryFields = listAppend(queryFields,col);
	}

	return queryFields;
}]]></starttext>
			               <endtext/>
			               <author>John Bartlett</author>
			               <platforms/>
			               <created>03-17-2006</created>
			               <lastupdated>03-17-2006</lastupdated>
			          </snippet>
					
				 	<snippet id="967" template="cfm">
			               <name>queryColumnsToStruct</name>
			               <help><![CDATA[&lt;cfscript&gt;
	q = queryNew(&quot;id,name,group&quot;);
	queryAddRow(q,4);
	querySetCell(q,&quot;id&quot;,&quot;a&quot;,1);
	querySetCell(q,&quot;id&quot;,&quot;b&quot;,2);
	querySetCell(q,&quot;id&quot;,&quot;c&quot;,3);
	querySetCell(q,&quot;id&quot;,&quot;d&quot;,4);
	querySetCell(q,&quot;name&quot;,&quot;Raymond&quot;,1);
	querySetCell(q,&quot;name&quot;,&quot;Ben&quot;,2);
	querySetCell(q,&quot;name&quot;,&quot;Joel&quot;,3);
	querySetCell(q,&quot;name&quot;,&quot;Scott&quot;,4);
	querySetCell(q,&quot;group&quot;,&quot;marines&quot;,1);
	querySetCell(q,&quot;group&quot;,&quot;navy&quot;,2);
	querySetCell(q,&quot;group&quot;,&quot;airforce&quot;,3);
	querySetCell(q,&quot;group&quot;,&quot;marines&quot;,4);	
&lt;/cfscript&gt;

HERE&apos;S THE QUERY&lt;br /&gt;
&lt;cfdump var=&quot;#q#&quot;&gt;
&lt;br /&gt;
USING ONLY THE ID COLUMN:&lt;br /&gt;
&lt;cfdump var=&quot;#queryColumnsToStruct(q,&quot;id&quot;)#&quot;&gt;
&lt;br /&gt;
USING &quot;ID&quot; AS THE KEY, AND &quot;NAME&quot; AS THE VALUE:&lt;br /&gt;
&lt;cfdump var=&quot;#queryColumnsToStruct(q,&quot;id&quot;,&quot;name&quot;)#&quot;&gt;
&lt;br /&gt;
USING &quot;GROUP&quot; AS THE KEY, AND &quot;NAME&quot; AS THE VALUE:&lt;br /&gt;
&lt;cfdump var=&quot;#queryColumnsToStruct(q,&quot;group&quot;,&quot;name&quot;)#&quot;&gt;
&lt;br /&gt;
SAME AS ABOVE, BUT RUN IN REVERSE (notice a different &quot;marines&quot; value):&lt;br /&gt;
&lt;cfdump var=&quot;#queryColumnsToStruct(q,&quot;group&quot;,&quot;name&quot;,true)#&quot;&gt;]]></help>
			               <description><![CDATA[Creates a structure keyed off one column in a given query.  You can choose to either have the value be the same as the key or choose another column for the value.  Since this function uses only simple values as the values in the structure duplicate keys will be overwritten.  You can control this to some extent with the optional 4th argument, which you set to &quot;true&quot; if you want to go through the query in reverse order (which would result in the top-most value of a given key being used as opposed to the bottom-most value).  Typically, you'll use the primary key of the table in the query as the key in the struct, so it should not be an issue in most cases.]]></description>
			               <starttext><![CDATA[function queryColumnsToStruct(query,keyColumn){
	var valueColumn = keyColumn;
	var reverse = false;
	var struct = structNew();
	var increment = 1;
	var ii = 1;
	var rowsGotten = 0;
	//if there is a third argument, treat that as the valueColumn
	if(arrayLen(arguments) GT 2)
		valueColumn = arguments[3];
	//if there is a 4th argument, use that as the reverse
	if(arrayLen(arguments) GT 3)
		reverse = arguments[4];	
	//if reversing, we go backwards through the query
	if(reverse){
		ii = query.recordCount;
		increment = -1;
	}	
	//loop through the query, populating the struct
	//we do the while loop rather than a for loop because we don't know what direction we're going in
	while(rowsGotten LT query.recordCount){
		struct[query[keyColumn][ii]] = query[valueColumn][ii];
		ii = ii + increment;
		rowsGotten = rowsGotten + 1;		
	}
	return struct;
}]]></starttext>
			               <endtext/>
			               <author>Nathan Dintenfass</author>
			               <platforms/>
			               <created>07-09-2003</created>
			               <lastupdated>07-09-2003</lastupdated>
			          </snippet>
					
				 	<snippet id="1233" template="cfm">
			               <name>queryColumnToArray</name>
			               <help><![CDATA[&lt;cfset qry = QueryNew(&quot;things,stuff&quot;) /&gt;
&lt;cfset queryAddRow(qry)&gt;
&lt;cfset QuerySetCell(qry,&quot;things&quot;, &quot;A&quot;) /&gt;
&lt;cfset QuerySetCell(qry,&quot;stuff&quot;, &quot;a1&quot;) /&gt;
&lt;cfset queryAddRow(qry)&gt;
&lt;cfset QuerySetCell(qry,&quot;things&quot;, &quot;B&quot;) /&gt;
&lt;cfset QuerySetCell(qry,&quot;stuff&quot;, &quot;b2&quot;) /&gt;
&lt;cfset queryAddRow(qry)&gt;
&lt;cfset QuerySetCell(qry,&quot;things&quot;, &quot;C&quot;) /&gt;
&lt;cfset QuerySetCell(qry,&quot;stuff&quot;, &quot;c3&quot;) /&gt;

&lt;cfset my_array = queryColumnToArray(qry, &quot;things&quot;) /&gt;
&lt;cfdump var=&quot;#my_array#&quot; /&gt;]]></help>
			               <description><![CDATA[Takes a selected column of data from a query and converts it into an array.]]></description>
			               <starttext><![CDATA[function queryColumnToArray(qry, column) {
	var arr = arrayNew(1);
	var ii = "";
	var loop_len = arguments.qry.recordcount;
	for (ii=1; ii lte loop_len; ii=ii+1) {
		arrayAppend(arr, arguments.qry[arguments.column][ii]);
	} 
	return arr;
}]]></starttext>
			               <endtext/>
			               <author>Peter J. Farrell</author>
			               <platforms/>
			               <created>07-22-2005</created>
			               <lastupdated>07-22-2005</lastupdated>
			          </snippet>
					
				 	<snippet id="1411" template="cfm">
			               <name>queryColumnTypes</name>
			               <help><![CDATA[&lt;cfquery name=&quot;foo&quot; datasource=&quot;galaga&quot;&gt;
select *
from users
&lt;/cfquery&gt;

&lt;cfdump var=&quot;#queryColumnTypes(foo)#&quot;&gt;]]></help>
			               <description><![CDATA[Used in conjuction with QueryColumns(), will return a list of data types such as the following: INTEGER,VARCHAR,CHAR,TIMESTAMP. This can be done in CFMX using getMetaData on the query.]]></description>
			               <starttext><![CDATA[function queryColumnTypes(dbquery) {
	var columnTypes="";
	var metadata=dbquery.getMetadata();
	var i=0;
	var column="";

	for (i=1; i lte metadata.getColumnCount(); i=i+1) {
		column = metadata.getColumnLabel(javaCast("int",i));
		columnTypes = listAppend(columnTypes,dbquery.getColumnTypeName(metadata.getColumnType(dbquery.findColumn(column))));
	}

	return columnTypes;
}]]></starttext>
			               <endtext/>
			               <author>John Bartlett</author>
			               <platforms/>
			               <created>04-11-2006</created>
			               <lastupdated>04-11-2006</lastupdated>
			          </snippet>
					
				 	<snippet id="1093" template="cfm">
			               <name>queryCompare</name>
			               <help><![CDATA[&lt;cfset test = querynew(&quot;language,rating&quot;)&gt;
&lt;cfset queryaddrow(test,3)&gt;
&lt;cfset querysetcell(test,&quot;language&quot;,&quot;ColdFusion&quot;,&quot;1&quot;)&gt;
&lt;cfset querysetcell(test,&quot;language&quot;,&quot;ASP&quot;,&quot;2&quot;)&gt;
&lt;cfset querysetcell(test,&quot;language&quot;,&quot;Java&quot;,&quot;3&quot;)&gt;
&lt;cfset querysetcell(test,&quot;rating&quot;,&quot;10&quot;,&quot;1&quot;)&gt;
&lt;cfset querysetcell(test,&quot;rating&quot;,&quot;9&quot;,&quot;2&quot;)&gt;
&lt;cfset querysetcell(test,&quot;rating&quot;,&quot;8&quot;,&quot;3&quot;)&gt;

&lt;cfset test1 = querynew(&quot;language,rating&quot;)&gt;
&lt;cfset queryaddrow(test1,3)&gt;
&lt;cfset querysetcell(test1,&quot;language&quot;,&quot;ColdFusion&quot;,&quot;1&quot;)&gt;
&lt;cfset querysetcell(test1,&quot;language&quot;,&quot;ASP&quot;,&quot;2&quot;)&gt;
&lt;cfset querysetcell(test1,&quot;language&quot;,&quot;Java&quot;,&quot;3&quot;)&gt;
&lt;cfset querysetcell(test1,&quot;rating&quot;,&quot;10&quot;,&quot;1&quot;)&gt;
&lt;cfset querysetcell(test1,&quot;rating&quot;,&quot;9&quot;,&quot;2&quot;)&gt;
&lt;cfset querysetcell(test1,&quot;rating&quot;,&quot;7&quot;,&quot;3&quot;)&gt;
	
&lt;cfset temp = queryCompare(test,test1)&gt;
&lt;cfdump var=&quot;#temp#&quot;&gt;]]></help>
			               <description><![CDATA[This function will compare two queries and returns a struct with the following keys

in_query1_butnotin_query2 = A query which contains records from query 1 which are different than query 2.
in_query2_butnotin_query1 = A query which contains records from query 2 which are different than query 1.
message = a message which may be 1. Record are indential 2. Records do not match or 3. Query 1 had different nummber of columns than query 2.]]></description>
			               <starttext><![CDATA[<cffunction name="queryCompare" returntype="struct" output="false">
	<cfargument name="query1" type="query" required="true" />
	<cfargument name="query2" type="query" required="true" />
	
	<cfset var rStruct = StructNew()>
	<cfset var q1 = arguments.query1>
	<cfset var q2 = arguments.query2>
	<cfset var q3 = QueryNew( q1.columnlist )>
	<cfset var q4 = QueryNew( q2.columnlist )>
	<cfset var message = "">
	<cfset var rowch = false>
	<cfset var colArray = listtoarray(q1.columnlist)>
	<cfset var thisCol = "">
	<cfset var count = 1>
	<cfset var i = "">
	<cfset var j = "">
	
	<cfloop from="1" to="#listlen(q1.columnlist)#" index="thisCol">
		<cfif listfindnocase(q2.columnlist,listgetat(q1.columnlist,thisCol)) eq 0>
			<cfset message = "Columns in query1 (#q1.columnlist#) and query2 (#q2.columnlist#) doesn't match">
		</cfif>
	</cfloop>
	<cfif not len(trim(message))>
		<cfloop from="1" to="#listlen(q2.columnlist)#" index="thisCol">
			<cfif listfindnocase(q1.columnlist,listgetat(q2.columnlist,thisCol)) eq 0>
				<cfset message = "Columns in query1 (#q1.columnlist#) and query2 (#q2.columnlist#) doesn't match">
			</cfif>
		</cfloop>
	</cfif> 
	
	<cfif not len(trim(message))>
		<cfloop from="1" to="#q1.recordcount#" index="i">
			<cfset rowch = false>
			<cfloop from="1" to="#arraylen(colArray)#" index="j">
				<cfif comparenocase(q1[colArray[j]][i],q2[colArray[j]][i])>
					<cfset rowch = true>
				</cfif>
			</cfloop>
			<cfif rowch>
				<cfset queryaddrow(q3)>
				<cfloop from="1" to="#arraylen(colArray)#" index="k">
					<cfset querysetcell( q3, colArray[k], q1[colArray[k]][count] )>
				</cfloop>
			</cfif>
			<cfset count = count + 1>
		</cfloop>
		<cfset count = 1>
		<cfloop from="1" to="#q2.recordcount#" index="i">
			<cfset rowch = false>
			<cfloop from="1" to="#arraylen(colArray)#" index="j">
				<cfif comparenocase(q1[colArray[j]][i],q2[colArray[j]][i])>
					<cfset rowch = true>
				</cfif>
			</cfloop>
			<cfif rowch>
				<cfset queryaddrow(q4)>
				<cfloop from="1" to="#arraylen(colArray)#" index="k">
					<cfset querysetcell( q4, colArray[k], q2[colArray[k]][count] )>
				</cfloop>
			</cfif>
			<cfset count = count + 1>
		</cfloop>
		<cfif q4.recordcount OR q3.recordcount>
			<cfset message = "Records do not match">
		</cfif>
	</cfif>
	<cfif len(trim(message))>
		<cfset structinsert(rStruct,"message",message)>
		<cfset structinsert(rStruct,"in_query1_butnotin_query2",q3)>
		<cfset structinsert(rStruct,"in_query2_butnotin_query1",q4)>
	<cfelse>
		<cfset structinsert(rStruct,"message","Query 1 and Query 2 are identical")>
	</cfif>
	<cfreturn rStruct />
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Qasim Rasheed</author>
			               <platforms/>
			               <created>11-04-2005</created>
			               <lastupdated>11-04-2005</lastupdated>
			          </snippet>
					
				 	<snippet id="1376" template="cfm">
			               <name>queryConcat</name>
			               <help><![CDATA[cols = &quot;sName,sAge&quot;;
heads = &quot;First Name,Age&quot;;

q1 = queryNew(cols);
queryAddRow(q1,2);
querySetCell(q1,&quot;sName&quot;,&quot;Joe&quot;,1);
querySetCell(q1,&quot;sAge&quot;,&quot;25&quot;,1);
querySetCell(q1,&quot;sName&quot;,&quot;John&quot;,2);
querySetCell(q1,&quot;sAge&quot;,&quot;30&quot;,2);

q2 = queryNew(cols);
queryAddRow(q2,2);
querySetCell(q2,&quot;sName&quot;,&quot;Kassi&quot;,1);
querySetCell(q2,&quot;sAge&quot;,&quot;19&quot;,1);
querySetCell(q2,&quot;sName&quot;,&quot;Mary&quot;,2);
querySetCell(q2,&quot;sAge&quot;,&quot;20&quot;,2);
&lt;/cfscript&gt;

&lt;cfdump var=&quot;#q1#&quot;&gt;
&lt;cfdump var=&quot;#q2#&quot;&gt;
&lt;br&gt;&lt;br&gt;
Resulting query
&lt;br&gt;
&lt;cfset resultQuery = queryConcat(q1, q2)&gt;
&lt;cfdump var=&quot;#resultQuery#&quot;&gt;]]></help>
			               <description><![CDATA[Appends queryTwo to queryOne. Sorting is ignored - queryTwo is appended to the end of queryOne. Note that both queries must have the same columns.]]></description>
			               <starttext><![CDATA[function queryConcat(q1,q2) {
	var row = "";
	var col = "";

	if(q1.columnList NEQ q2.columnList) {
		return q1;
	}

	for(row=1; row LTE q2.recordCount; row=row+1) {
	 queryAddRow(q1);
	 for(col=1; col LTE listLen(q1.columnList); col=col+1)
		querySetCell(q1,ListGetAt(q1.columnList,col), q2[ListGetAt(q1.columnList,col)][row]);
	}
	return q1;
}]]></starttext>
			               <endtext/>
			               <author>Chris Dary</author>
			               <platforms/>
			               <created>02-23-2006</created>
			               <lastupdated>02-23-2006</lastupdated>
			          </snippet>
					
				 	<snippet id="758" template="cfm">
			               <name>queryDeDupe</name>
			               <help><![CDATA[&lt;cfscript&gt;
Test=QueryNew(&quot;key,value&quot;);
QueryAddRow(Test);
QuerySetCell(Test,&quot;key&quot;,1);
QuerySetCell(Test,&quot;value&quot;,&apos;One A&apos;);
QueryAddRow(Test);
QuerySetCell(Test,&quot;key&quot;,1);
QuerySetCell(Test,&quot;value&quot;,&apos;One B&apos;);
QueryAddRow(Test);
QuerySetCell(Test,&quot;key&quot;,2);
QuerySetCell(Test,&quot;value&quot;,&apos;Two&apos;);

NewQuery=QueryDeDupe(Test,&apos;key&apos;);

&lt;/cfscript&gt;

Original query:&lt;BR&gt;
&lt;cfdump var=&quot;#Test#&quot;&gt;
&lt;BR&gt;&lt;BR&gt;
Query with dupes removed:&lt;BR&gt;
&lt;cfset NewQuery=QueryDeDupe(test,&apos;key&apos;)&gt;
&lt;cfdump var=&quot;#NewQuery#&quot;&gt;]]></help>
			               <description><![CDATA[This function will find rows with duplicate entries in a given column. Useful for filtering Verity results containing database primary keys in CUSTOM1 or CUSTOM2 fields and anywhere else where duplicate database rows might be present.]]></description>
			               <starttext><![CDATA[function QueryDeDupe(theQuery,keyColumn) {
	var checkList='';
	var newResult=QueryNew(theQuery.ColumnList);
	var keyvalue='';
	var q = 1;
	var x = "";
	
	// loop through each row of the source query
	for (;q LTE theQuery.RecordCount;q=q+1) {

		keyvalue = theQuery[keycolumn][q];
		// see if the primary key value has already been used
		if (NOT ListFind(checkList,keyvalue)) {
			
			/* this is not a duplicate, so add it to the list and copy
			   the row to the destination query */
			checkList=ListAppend(checklist,keyvalue);
			QueryAddRow(NewResult);
			
			// copy all columns from source to destination for this row
			for (x=1;x LTE ListLen(theQuery.ColumnList);x=x+1) {
				QuerySetCell(NewResult,ListGetAt(theQuery.ColumnList,x),theQuery[ListGetAt(theQuery.ColumnList,x)][q]);
			}
		}
	}
	return NewResult;
}]]></starttext>
			               <endtext/>
			               <author>Matthew Fusfield</author>
			               <platforms/>
			               <created>12-19-2008</created>
			               <lastupdated>12-19-2008</lastupdated>
			          </snippet>
					
				 	<snippet id="11" template="cfm">
			               <name>QueryDeleteRows</name>
			               <help><![CDATA[&lt;CFSET Query = QueryNew(&quot;id,name,age&quot;)&gt;
&lt;CFLOOP INDEX=&quot;X&quot; FROM=1 TO=8&gt;
&lt;CFSET QueryAddRow(Query,1)&gt;
&lt;CFSET QuerySetCell(Query,&quot;ID&quot;,X,X)&gt;
&lt;CFSET QuerySetCell(Query,&quot;Name&quot;,&quot;Name #X#&quot;,X)&gt;
&lt;CFSET QuerySetCell(Query,&quot;Age&quot;,X+15,X)&gt;
&lt;/CFLOOP&gt;
Before deleting&lt;BR&gt;
&lt;CFDUMP VAR=&quot;#Query#&quot;&gt;
&lt;CFSET Query = QueryDeleteRows(Query,&quot;1,3&quot;)&gt;
&lt;P&gt;After removing rows 1 and 3&lt;BR&gt;
&lt;CFDUMP VAR=&quot;#Query#&quot;&gt;
&lt;P&gt;After removing row 3&lt;BR&gt;
&lt;CFSET Query = QueryDeleteRows(Query,3)&gt;
&lt;CFDUMP VAR=&quot;#Query#&quot;&gt;]]></help>
			               <description><![CDATA[This function will allow you to remove rows from a query. You can either remove one row or a list of rows.]]></description>
			               <starttext><![CDATA[function QueryDeleteRows(Query,Rows) {
	var tmp = QueryNew(Query.ColumnList);
	var i = 1;
	var x = 1;

	for(i=1;i lte Query.recordCount; i=i+1) {
		if(not ListFind(Rows,i)) {
			QueryAddRow(tmp,1);
			for(x=1;x lte ListLen(tmp.ColumnList);x=x+1) {
				QuerySetCell(tmp, ListGetAt(tmp.ColumnList,x), query[ListGetAt(tmp.ColumnList,x)][i]);
			}
		}
	}
	return tmp;
}]]></starttext>
			               <endtext/>
			               <author>Raymond Camden</author>
			               <platforms/>
			               <created>10-11-2001</created>
			               <lastupdated>10-11-2001</lastupdated>
			          </snippet>
					
				 	<snippet id="908" template="cfm">
			               <name>queryDiff</name>
			               <help><![CDATA[&lt;cfscript&gt;
	//BUILD TWO SAMPLE QUERIES
	q1 = queryNew(&quot;foo,bar,thing&quot;);
	q2 = queryNew(&quot;foo,bar,thing&quot;);
	
	queryAddRow(q1,3);
	queryAddRow(q2,4);
	
	querySetCell(q1,&quot;foo&quot;,&quot;1&quot;,1);
	querySetCell(q1,&quot;foo&quot;,&quot;2&quot;,2);
	querySetCell(q1,&quot;foo&quot;,&quot;3&quot;,3);
	querySetCell(q1,&quot;bar&quot;,&quot;a&quot;,1);
	querySetCell(q1,&quot;bar&quot;,&quot;b&quot;,2);
	querySetCell(q1,&quot;bar&quot;,&quot;c&quot;,3);
	querySetCell(q1,&quot;thing&quot;,&quot;w&quot;,1);
	querySetCell(q1,&quot;thing&quot;,&quot;x&quot;,2);
	querySetCell(q1,&quot;thing&quot;,&quot;y&quot;,3);
	
	querySetCell(q2,&quot;foo&quot;,&quot;1&quot;,1);
	querySetCell(q2,&quot;foo&quot;,&quot;new&quot;,2);
	querySetCell(q2,&quot;foo&quot;,&quot;3&quot;,3);
	querySetCell(q2,&quot;foo&quot;,&quot;4&quot;,4);
	querySetCell(q2,&quot;bar&quot;,&quot;aaa&quot;,1);
	querySetCell(q2,&quot;bar&quot;,&quot;b&quot;,2);
	querySetCell(q2,&quot;bar&quot;,&quot;c&quot;,3);	
	querySetCell(q2,&quot;bar&quot;,&quot;d&quot;,4);
	querySetCell(q2,&quot;thing&quot;,&quot;w&quot;,1);
	querySetCell(q2,&quot;thing&quot;,&quot;changed&quot;,2);
	querySetCell(q2,&quot;thing&quot;,&quot;y&quot;,3);
	querySetCell(q2,&quot;thing&quot;,&quot;z&quot;,4);
&lt;/cfscript&gt;

A DUMP OF THE ORIGINAL QUERIES:
&lt;table&gt;
	&lt;tr&gt;
		&lt;td valign=&quot;top&quot;&gt;&lt;cfdump var=&quot;#q1#&quot;&gt;&lt;/td&gt;
		&lt;td valign=&quot;top&quot;&gt;&lt;cfdump var=&quot;#q2#&quot;&gt;&lt;/td&gt;
	&lt;/tr&gt;
&lt;/table&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;hr&gt;
&lt;cfset diff = queryDiff(q1,q2)&gt;
Were any rows changed?: &lt;strong&gt;&lt;cfoutput&gt;#yesNoFormat(structCount(diff.changed))#&lt;/cfoutput&gt;&lt;/strong&gt;
&lt;br /&gt;
&lt;cfif structCount(diff.changed)&gt;
Which rows were changed?: &lt;cfoutput&gt;#structKeyList(diff.changed)#&lt;/cfoutput&gt;
&lt;br /&gt;
Show the columns that changed in each of those rows:
&lt;br /&gt;
&lt;cfoutput&gt;
&lt;cfloop collection=&quot;#diff.changed#&quot; item=&quot;rowIndex&quot;&gt;
	In Row &lt;strong&gt;#rowIndex#:&lt;/strong&gt;
	&lt;ul&gt;
	&lt;cfloop collection=&quot;#diff.changed[rowIndex]#&quot; item=&quot;colName&quot;&gt;
		&lt;li&gt;&lt;strong&gt;#colName#&lt;/strong&gt; was &lt;strong&gt;#diff.changed[rowIndex][colName].then#&lt;/strong&gt; and now is &lt;strong&gt;#diff.changed[rowIndex][colName].now#&lt;/strong&gt;
	&lt;/cfloop&gt;
	&lt;/ul&gt;
&lt;/cfloop&gt;
&lt;/cfoutput&gt;
&lt;/cfif&gt;
&lt;hr&gt;
Were any rows added?: &lt;strong&gt;&lt;cfoutput&gt;#yesNoFormat(structCount(diff.added))#&lt;/cfoutput&gt;&lt;/strong&gt;
&lt;cfif structCount(diff.added)&gt;
&lt;br /&gt;
How many rows were added?: &lt;strong&gt;&lt;cfoutput&gt;#structCount(diff.added)#&lt;/cfoutput&gt;&lt;/strong&gt;
&lt;br /&gt;
Show the rows that were added:
&lt;cfset cols = listToArray(diff.query1.columnList)&gt;
&lt;cfoutput&gt;
&lt;table border=1&gt;
	&lt;tr&gt;
		&lt;td&gt;&lt;em&gt;row&lt;/em&gt;&lt;/td&gt;
		&lt;cfloop from=&quot;1&quot; to=&quot;#arrayLen(cols)#&quot; index=&quot;ii&quot;&gt;
			&lt;td&gt;#cols[ii]#&lt;/td&gt;
		&lt;/cfloop&gt;
	&lt;/tr&gt;
	&lt;cfloop collection=&quot;#diff.added#&quot; item=&quot;rowIndex&quot;&gt;
	&lt;tr&gt;
		&lt;td&gt;&lt;em&gt;#rowIndex#&lt;/em&gt;&lt;/td&gt;
		&lt;cfloop from=&quot;1&quot; to=&quot;#arrayLen(cols)#&quot; index=&quot;ii&quot;&gt;
			&lt;cfset thisColName = cols[ii]&gt;
			&lt;td&gt;#diff.query2[thisColName][rowIndex]#&lt;/td&gt;
		&lt;/cfloop&gt;		
	&lt;/tr&gt;
	&lt;/cfloop&gt;
&lt;/table&gt;
&lt;/cfoutput&gt;
&lt;/cfif&gt;
&lt;br /&gt;
&lt;hr&gt;
Were any rows removed?: &lt;strong&gt;&lt;cfoutput&gt;#yesNoFormat(structCount(diff.removed))#&lt;/cfoutput&gt;&lt;/strong&gt;
&lt;cfif structCount(diff.removed)&gt;
&lt;br /&gt;
How many rows were added?: &lt;strong&gt;&lt;cfoutput&gt;#structCount(diff.removed)#&lt;/cfoutput&gt;&lt;/strong&gt;
&lt;br /&gt;
Show the rows that were removed:
&lt;cfset cols = listToArray(diff.query1.columnList)&gt;
&lt;cfoutput&gt;
&lt;table border=1&gt;
	&lt;tr&gt;
		&lt;td&gt;&lt;em&gt;row&lt;/em&gt;&lt;/td&gt;
		&lt;cfloop from=&quot;1&quot; to=&quot;#arrayLen(cols)#&quot; index=&quot;ii&quot;&gt;
			&lt;td&gt;#cols[ii]#&lt;/td&gt;
		&lt;/cfloop&gt;
	&lt;/tr&gt;
	&lt;cfloop collection=&quot;#diff.removed#&quot; item=&quot;rowIndex&quot;&gt;
	&lt;tr&gt;
		&lt;td&gt;&lt;em&gt;#rowIndex#&lt;/em&gt;&lt;/td&gt;
		&lt;cfloop from=&quot;1&quot; to=&quot;#arrayLen(cols)#&quot; index=&quot;ii&quot;&gt;
			&lt;cfset thisColName = cols[ii]&gt;
			&lt;td&gt;#diff.query1[thisColName][rowIndex]#&lt;/td&gt;
		&lt;/cfloop&gt;		
	&lt;/tr&gt;
	&lt;/cfloop&gt;
&lt;/table&gt;
&lt;/cfoutput&gt;
&lt;/cfif&gt;

&lt;br /&gt;
&lt;hr&gt;
SHOW A COMPLETE COMPARISON OF THE QUERIES:

&lt;cfset cols = listToArray(diff.query1.columnList)&gt;
&lt;cfoutput&gt;
&lt;table border=1&gt;
	&lt;tr&gt;
		&lt;td&gt;&lt;em&gt;row&lt;/em&gt;&lt;/td&gt;
		&lt;td colspan=&quot;#arrayLen(cols)#&quot;&gt;
			&lt;em&gt;ORIGINAL QUERY&lt;/em&gt;
		&lt;/td&gt;
		&lt;td&gt;.&lt;/td&gt;
		&lt;td colspan=&quot;#arrayLen(cols)#&quot;&gt;
			&lt;em&gt;NEW QUERY&lt;/em&gt;
		&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td&gt;&lt;/td&gt;
		&lt;cfloop from=&quot;1&quot; to=&quot;#arrayLen(cols)#&quot; index=&quot;ii&quot;&gt;
			&lt;td&gt;&lt;strong&gt;#cols[ii]#&lt;/strong&gt;&lt;/td&gt;
		&lt;/cfloop&gt;
			&lt;td&gt;.&lt;/td&gt;
		&lt;cfloop from=&quot;1&quot; to=&quot;#arrayLen(cols)#&quot; index=&quot;ii&quot;&gt;
			&lt;td&gt;&lt;strong&gt;#cols[ii]#&lt;/strong&gt;&lt;/td&gt;
		&lt;/cfloop&gt;		
	&lt;/tr&gt;
	&lt;cfloop from=&quot;1&quot; to=&quot;#iif(diff.query1.recordCount LT diff.query2.recordCount,diff.query2.recordCount,diff.query1.recordCount)#&quot; index=&quot;rowIndex&quot;&gt;
	&lt;tr&gt;
		&lt;td&gt;&lt;em&gt;#rowIndex#&lt;/em&gt;&lt;/td&gt;
		&lt;cfloop from=&quot;1&quot; to=&quot;#arrayLen(cols)#&quot; index=&quot;ii&quot;&gt;
			
			&lt;cfif rowIndex LTE diff.query1.recordCount&gt;
				&lt;cfset thisColName = cols[ii]&gt;
				&lt;td&gt;
				#diff.query1[thisColName][rowIndex]#
				&lt;/td&gt;
			&lt;cfelse&gt;
				&lt;td style=&quot;background:##cccccc;&quot;&gt;&lt;/td&gt;	
			&lt;/cfif&gt;
		&lt;/cfloop&gt;
		&lt;td&gt;.&lt;/td&gt;
		&lt;cfloop from=&quot;1&quot; to=&quot;#arrayLen(cols)#&quot; index=&quot;ii&quot;&gt;
			&lt;cfif rowIndex LTE diff.query2.recordCount&gt;
				&lt;cfscript&gt;
					thisColName = cols[ii];
					thisStyle = &quot;font-weight:normal;&quot;;
					//if it&apos;s a changed value, outline it in red
					if(structKeyExists(diff.changed,rowIndex) AND structKeyExists(diff.changed[rowIndex],thisColName)){
						thisStyle = &quot;border: 2px red dotted;&quot;;
					}
					if(structKeyExists(diff.added,rowIndex)){
						thisStyle = &quot;background: ##ffffcc;&quot;;
					}
				&lt;/cfscript&gt;			
				&lt;td style=&quot;#thisStyle#&quot;&gt;
				#diff.query2[thisColName][rowIndex]#
				&lt;/td&gt;
			&lt;cfelse&gt;
				&lt;td style=&quot;background:##cccccc;&quot;&gt;&lt;/td&gt;	
			&lt;/cfif&gt;	
		&lt;/cfloop&gt;		
	&lt;/tr&gt;
	&lt;/cfloop&gt;
&lt;/table&gt;
&lt;/cfoutput&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;hr&gt;
A DUMP OF THE RESULT OF queryDiff()
&lt;cfdump var=&quot;#diff#&quot;&gt;]]></help>
			               <description><![CDATA[Given two queries queryDiff() returns a structure with information about which rows/cells changed and which rows were added or removed. NOTE:  This version works ONLY with 2 queries with the same columns!

The resulting structures contains the following keys:

CHANGED: a structure of structures -- the top level keys are the row indexes, and the second level keys are the column names.  Each column keyed struct contains the following keys:

 - THEN: the value in q1
 - NOW: the value in q2
 - ROW: the row index
 - COL: the column name

ADDED: A struct where the keys and values are the row indexes in Q2 of rows that aren't in Q1

REMOVED: A struct where the keys and values are the row indexes in Q1 that aren't in Q2

QUERY1: a reference to the first query

QUERY2: a reference to the second query]]></description>
			               <starttext><![CDATA[function queryDiff(q1,q2){
	//vars for looping
	var ii = 0;
	var cc = 0;
	//a struct to hold the result
	var result = structNew();
	//grab the columns -- NOTE: THIS VERSION ASSUMES THEY HAVE THE SAME COLUMNS!!
	var cols = listToArray(q1.columnList);
	var thisCol = "";
	//we'll loop whichever query is shortest.  by default, we'll loop query1
	var shorterQuery = q1;
	var longerQuery = q2;
	var keyToUseForLonger = "added";
	var sameSize = true;
	var rowDiff = 0;
	//vars to use in the loop
	var q1Value = "";
	var q2Value = "";
	var thenNow = structNew();
	//make the standard keys in the result
	result.changed = structNew();
	result.added = structNew();
	result.removed = structNew();
	result.query1 = q1;
	result.query2 = q2;
	//if the queries are not the same size, indicate that
	if(q1.recordCount NEQ q2.recordCount){
		sameSize = false;
		//if q2 is shorter, use that instead
		if(q1.recordCount GT q2.recordCount){
			shorterQuery = q2;
			longerQuery = q1;
			keyToUseForLonger = "removed";
		}
	}
	//loop the correct query to get rows that are different in Q2 from Q1
	for(ii = 1; ii LTE shorterQuery.recordCount; ii = ii + 1){
		for(cc = 1; cc LTE arrayLen(cols); cc = cc + 1){
			thisCol = cols[cc];
			q1Value = q1[thisCol][ii];
			q2Value = q2[thisCol][ii];
			//if this col is different, grab the row index
			if(compare(q1Value,q2Value)){
				//if we don't already have this row in the changed group, put it there
				if(NOT structKeyExists(result.changed,ii))
					result.changed[ii] = structNew();
				thenNow = structNew();
				thenNow.then = q1Value;
				thenNow.now = q2Value;
				thenNow.row = ii;
				thenNow.col = thisCol;
				result.changed[ii][thisCol] = thenNow;
			}
		}
	}
	//if they are not the same size, add the row index to the appropriate key
	if(NOT sameSize){
		rowDiff = longerQuery.recordCount - shorterQuery.recordCount;
		for(ii = rowDiff + shorterQuery.recordCount; ii LTE longerQuery.recordCount; ii = ii + 1){
			result[keyToUseForLonger][ii] = ii;
		}
	}
	//return the result
	return result;
}]]></starttext>
			               <endtext/>
			               <author>Nathan Dintenfass</author>
			               <platforms/>
			               <created>05-26-2003</created>
			               <lastupdated>05-26-2003</lastupdated>
			          </snippet>
					
				 	<snippet id="587" template="cfm">
			               <name>QueryGetCellByKey</name>
			               <help><![CDATA[&lt;CFSET my_query = QueryNew(&quot;Username,Name,Age&quot;)&gt;
&lt;CFSET QueryAddRow(my_query, 1)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Username&quot;, &quot;CUser&quot;)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Name&quot;,&quot;Chris User&quot;)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Age&quot;, 30)&gt;
&lt;CFSET QueryAddRow(my_query, 1)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Username&quot;, &quot;AUser&quot;)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Name&quot;,&quot;Albert User&quot;)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Age&quot;, 10)&gt;
&lt;CFSET QueryAddRow(my_query, 1)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Username&quot;, &quot;BUser&quot;)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Name&quot;,&quot;Brad User&quot;)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Age&quot;, 20)&gt;

&lt;cfoutput&gt;
Query:&lt;br&gt;
&lt;br&gt;
&lt;CFDUMP VAR=&quot;#my_query#&quot;&gt;
&lt;br&gt;
&lt;br&gt;

Read from the query:&lt;br&gt;
&lt;br&gt;
BUser is &lt;b&gt;#QueryGetCellByKey(my_query, &quot;Username&quot;, &quot;BUser&quot;, &quot;Age&quot;)#&lt;/b&gt; years old.&lt;br&gt;
The 10 year old is named &lt;b&gt;#QueryGetCellByKey(my_query, &quot;Age&quot;, &quot;10&quot;, &quot;Name&quot;)#&lt;/b&gt;.&lt;br&gt;
&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Provides direct access to query cells by knowing the primary key (or any other identifying field value) within the same row. No need to keep track of row numbers. No need to loop through an entire query if you only need to get at a single row. Useful for effectively joining queries which may not be easily joined otherwise, and allows for more effective reuse of existing, cached, and/or server/application scoped queries. Throws an error if keyFieldValue is not found.]]></description>
			               <starttext><![CDATA[function QueryGetCellByKey(theQuery, keyField, keyFieldValue, columnName){
	var key_field_value_list  = Evaluate("ValueList(theQuery.#keyField#)");
	var row_number            = ListFindNoCase(key_field_value_list, keyFieldValue);

	return theQuery[columnName][row_number];

}]]></starttext>
			               <endtext/>
			               <author>Shawn Seley</author>
			               <platforms/>
			               <created>06-28-2002</created>
			               <lastupdated>06-28-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="1951" template="cfm">
			               <name>queryGetRow</name>
			               <help><![CDATA[&lt;cfset myQuery = QueryNew(&quot;Name, Time, Advanced&quot;, &quot;VarChar, Time, Bit&quot;)&gt;
&lt;cfset newRow = QueryAddRow(MyQuery, 2)&gt;
&lt;cfset QuerySetCell(myQuery, &quot;Name&quot;, &quot;The Wonderful World of CMFL&quot;, 1)&gt;
&lt;cfset QuerySetCell(myQuery, &quot;Time&quot;, &quot;9:15 AM&quot;, 1)&gt;
&lt;cfset QuerySetCell(myQuery, &quot;Advanced&quot;, False, 1)&gt;
&lt;cfset QuerySetCell(myQuery, &quot;Name&quot;, &quot;CFCs for Enterprise Applications&quot;, 2)&gt;
&lt;cfset QuerySetCell(myQuery, &quot;Time&quot;, &quot;12:15 PM&quot;, 2)&gt;
&lt;cfset QuerySetCell(myQuery, &quot;Advanced&quot;, True, 2)&gt;

The second row of the query is: &lt;cfdump var=&quot;#queryGetRow(myQuery,2)#&quot;&gt;]]></help>
			               <description><![CDATA[Given a numeric row id, this function will return the single row as a query object.]]></description>
			               <starttext><![CDATA[function queryGetRow(qry,row){
	var result = queryNew('');
	var cols = listToArray(arguments.qry.columnList);
	var i = '';

	for(i=1; i lte arrayLen(cols); i=i+1){
		queryAddColumn(result, cols[i], listToArray(arguments.qry[cols[i]][arguments.row]));
	}

	return result;
}]]></starttext>
			               <endtext/>
			               <author>Tony Felice</author>
			               <platforms/>
			               <created>02-14-2009</created>
			               <lastupdated>02-14-2009</lastupdated>
			          </snippet>
					
				 	<snippet id="1021" template="cfm">
			               <name>queryMerge</name>
			               <help><![CDATA[&lt;cfscript&gt;
cols = &quot;sName,sAge&quot;;
heads = &quot;First Name,Age&quot;;
sourcequery = queryNew(cols);
queryAddRow(sourcequery,2);
querySetCell(sourcequery,&quot;sName&quot;,&quot;Joe&quot;,1);
querySetCell(sourcequery,&quot;sAge&quot;,&quot;25&quot;,1);
querySetCell(sourcequery,&quot;sName&quot;,&quot;John&quot;,2);
querySetCell(sourcequery,&quot;sAge&quot;,&quot;30&quot;,2);
&lt;/cfscript&gt;
&lt;cfscript&gt;
cols = &quot;sName,sClass,sGrade&quot;;
heads = &quot;First Name,Class,Grade&quot;;
outputquery = queryNew(cols);
queryAddRow(outputquery,4);
querySetCell(outputquery,&quot;sName&quot;,&quot;Joe&quot;,1);
querySetCell(outputquery,&quot;sClass&quot;,&quot;Math&quot;,1);
querySetCell(outputquery,&quot;sGrade&quot;,&quot;A&quot;,1);
querySetCell(outputquery,&quot;sName&quot;,&quot;Joe&quot;,2);
querySetCell(outputquery,&quot;sClass&quot;,&quot;Gym&quot;,2);
querySetCell(outputquery,&quot;sGrade&quot;,&quot;C&quot;,2);
querySetCell(outputquery,&quot;sName&quot;,&quot;John&quot;,3);
querySetCell(outputquery,&quot;sClass&quot;,&quot;Gym&quot;,3);
querySetCell(outputquery,&quot;sGrade&quot;,&quot;C&quot;,3);
&lt;/cfscript&gt;
&lt;cfdump var=&quot;#sourcequery#&quot;&gt;
&lt;cfdump var=&quot;#outputquery#&quot;&gt;
&lt;br&gt;&lt;br&gt;
Resulting query
&lt;br&gt;
&lt;cfset temp = querymerge(sourcequery, outputquery, &apos;sName&apos;)&gt;
&lt;cfdump var=&quot;#outputquery#&quot;&gt;]]></help>
			               <description><![CDATA[Merge the columns from a source query into a second query. 

The merge is base on the value of the primary key identified by the parameter &quot;KeyColumn&quot;.  For each match of the primary the values contained in the source queury will be added to the output query; creating a merging effect.]]></description>
			               <starttext><![CDATA[function querymerge(querysource,queryoutput,keyColumn){
	var mergeColumn = querysource.columnlist;
	var valueArray = arrayNew(1);
	// define counters
	var i = 1;
	var iRow = 1;
	var jRow = 1;
	//if there is a 4th argument, use that as the mergeColumn
	if(arrayLen(arguments) GT 3) mergeColumn = arguments[4];	
	//loop through the merge column
	for(i=1; i lte listLen(mergeColumn,','); i=i+1) {
		if (listFindNoCase(queryoutput.columnlist,listGetAt(mergeColumn,i,','),',') eq 0) {
		    // loop through each row of queryoutput and add information from querysource
			found = listGetAt(mergeColumn,i,',');
		    for (iRow=1; iRow lte queryoutput.recordcount; iRow=iRow+1) {
			    // find the row in querysource that matches the value in keycolumn from queryoutput  
				jRow = 1;
				while (jRow lt querysource.recordcount and querysource[keyColumn][jRow] neq queryoutput[keycolumn][iRow]) {
				    jRow = jRow + 1;
				}
				if (querysource[keyColumn][jRow] eq queryoutput[keycolumn][iRow]) {
				    valueArray[iRow] = querysource[listGetAt(mergeColumn,i,',')][jRow];
				}
			}
		    // add the columnm
			queryaddcolumn(queryoutput,listGetAt(mergeColumn,i,','),valueArray);
		}
	}
	return queryoutput;
}]]></starttext>
			               <endtext/>
			               <author>Alain Blais</author>
			               <platforms/>
			               <created>07-21-2004</created>
			               <lastupdated>07-21-2004</lastupdated>
			          </snippet>
					
				 	<snippet id="524" template="cfm">
			               <name>QueryRandomRows</name>
			               <help><![CDATA[&lt;CFSET Foo = QueryNew(&quot;name,age,rank&quot;)&gt;
&lt;CFLOOP INDEX=&quot;X&quot; FROM=1 TO=10&gt;
&lt;CFSET QueryAddRow(Foo)&gt;
&lt;CFSET QuerySetCell(Foo,&quot;name&quot;,&quot;Random Name #X#&quot;)&gt;
&lt;CFSET QuerySetCell(Foo,&quot;age&quot;,RandRange(20,50))&gt;
&lt;CFSET QuerySetCell(Foo,&quot;rank&quot;,RandRange(1,10))&gt;
&lt;/CFLOOP&gt;
&lt;CFOUTPUT&gt;Original...&lt;/CFOUTPUT&gt;
&lt;CFDUMP VAR=&quot;#Foo#&quot;&gt;
&lt;CFSET Shorter = QueryRandomRows(Duplicate(Foo), 3)&gt;
&lt;br&gt;
&lt;CFOUTPUT&gt;3 Random Rows...&lt;/CFOUTPUT&gt;
&lt;CFDUMP VAR=&quot;#Shorter#&quot;&gt;]]></help>
			               <description><![CDATA[Returns a query object with a specified number of random records from the passed query. Some code based on QuerySlice() by Kevin Bridges (cyberswat@orlandoartistry.com)

Please note that results below will not be random due to caching at cflib.org.]]></description>
			               <starttext><![CDATA[function QueryRandomRows(theQuery, NumberOfRows) {
	var FinalQuery      = QueryNew(theQuery.ColumnList);
	var x				= 0;
	var y               = 0;
	var i               = 0;
	var random_element  = 0;
	var random_row      = 0;
	var row_list        = "";

	if(NumberOfRows GT theQuery.recordcount) NumberOfRows = theQuery.recordcount;

	QueryAddRow(FinalQuery, NumberOfRows);

	// build a list of rows from which we will "scratch off" the randomly selected values in order to avoid repeats
	for (i=1; i LTE theQuery.RecordCount; i=i+1) row_list = row_list & i & ",";

	// Build the new query
	for(x=1; x LTE NumberOfRows; x=x+1){
		// pick a random_row from row_list and delete that element from row_list (to prevent duplicates)
		random_element  = RandRange(1, ListLen(row_list));          // pick a random list element
		random_row      = ListGetAt(row_list, random_element);      // get the corresponding query row number
		row_list        = ListDeleteAt(row_list, random_element);   // delete the used element from the list
		for(y=1; y LTE ListLen(theQuery.ColumnList); y=y+1) {
			QuerySetCell(FinalQuery, ListGetAt(theQuery.ColumnList, y), theQuery[ListGetAt(theQuery.ColumnList, y)][random_row],x);
		}
	}

	return FinalQuery;
}]]></starttext>
			               <endtext/>
			               <author>Shawn Seley and John King</author>
			               <platforms/>
			               <created>07-10-2002</created>
			               <lastupdated>07-10-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="1196" template="cfm">
			               <name>queryRemoveColumns</name>
			               <help><![CDATA[&lt;cfset aQuery=QueryNew(&apos;first_column,second_column,third_column,fourth_column&apos;)&gt;
&lt;cfset QueryAddRow(aQuery,1)&gt;
&lt;cfset QuerySetCell(aQuery,&apos;first_column&apos;,1)&gt;
&lt;cfset QuerySetCell(aQuery,&apos;second_column&apos;,2)&gt;
&lt;cfset QuerySetCell(aQuery,&apos;third_column&apos;,3)&gt;
&lt;cfset QuerySetCell(aQuery,&apos;fourth_column&apos;,4)&gt;

&lt;cfdump var=&quot;#aQuery#&quot;&gt;	
&lt;cfdump var=&quot;#queryRemoveColumns(aQuery,&apos;second_column,third_column&apos;)#&quot;&gt;]]></help>
			               <description><![CDATA[Remove a list of columns from a specified query, using a query of query.]]></description>
			               <starttext><![CDATA[<cffunction name="queryRemoveColumns" output="false" returntype="query">
	<cfargument name="theQuery" type="query" required="yes">
	<cfargument name="columnsToRemove" type="string" required="yes">
	<cfset var columnList=theQuery.columnList>
	<cfset var columnPosition="">
	<cfset var c="">
	<cfset var newQuery="">
	<cfloop list="#arguments.columnsToRemove#" index="c">
		<cfset columnPosition=ListFindNoCase(columnList,c)>
		<cfif columnPosition NEQ 0>
			<cfset columnList=ListDeleteAt(columnList,columnPosition)>
		</cfif>
	</cfloop>
	<cfquery name="newQuery" dbtype="query">
		SELECT #columnList# FROM theQuery
	</cfquery>
	<cfreturn newQuery>
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Giampaolo Bellavite</author>
			               <platforms/>
			               <created>03-01-2005</created>
			               <lastupdated>03-01-2005</lastupdated>
			          </snippet>
					
				 	<snippet id="601" template="cfm">
			               <name>QueryReverse</name>
			               <help><![CDATA[&lt;CFSET Foo = QueryNew(&quot;name,age,rank&quot;)&gt;
&lt;CFLOOP INDEX=&quot;X&quot; FROM=1 TO=10&gt;
  &lt;CFSET QueryAddRow(Foo)&gt;
  &lt;CFSET QuerySetCell(Foo,&quot;name&quot;,&quot;Random Name #X#&quot;)&gt;
  &lt;CFSET QuerySetCell(Foo,&quot;age&quot;,RandRange(20,50))&gt;
  &lt;CFSET QuerySetCell(Foo,&quot;rank&quot;,RandRange(1,10))&gt;
&lt;/CFLOOP&gt;

Original...&lt;BR&gt;
&lt;CFDUMP VAR=&quot;#Foo#&quot;&gt;
&lt;P&gt;
&lt;CFSET Reverse = QueryReverse(Foo)&gt;
Reverse...&lt;BR&gt;
&lt;CFDUMP VAR=&quot;#Reverse#&quot;&gt;]]></help>
			               <description><![CDATA[Pass this function a query it will return a new one in reverse order (make first row the last and last row the first - in a new query).]]></description>
			               <starttext><![CDATA[function QueryReverse (qryOriginal) {
	
  // Reverse the order of qryOriginal
  // Make a new query using the same columns as qryOriginal
  var qryNew = QueryNew(qryOriginal.ColumnList);
  var row = 1;
  var column = 1;
  //Loop through qryOriginal in reverse order (last becomes first)
  for(row=qryOriginal.recordCount;row gte 1; row=row-1) {
    //Add a new row in the new query
    QueryAddRow(qryNew,1);
    //Get the values for each column in qryOriginal
    for(column=1;column lte ListLen(qryOriginal.ColumnList);column=column+1) {
      QuerySetCell(qryNew, ListGetAt(qryOriginal.ColumnList,column), qryOriginal[ListGetAt(qryOriginal.ColumnList,column)][row]);
    }
  }
  
  return qryNew;
  
}]]></starttext>
			               <endtext/>
			               <author>David Whiterod</author>
			               <platforms/>
			               <created>06-27-2002</created>
			               <lastupdated>06-27-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="586" template="cfm">
			               <name>QueryRowFromKey</name>
			               <help><![CDATA[&lt;CFSET my_query = QueryNew(&quot;Username,Name,Age&quot;)&gt;
&lt;CFSET QueryAddRow(my_query, 1)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Username&quot;, &quot;CUser&quot;)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Name&quot;,&quot;Chris User&quot;)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Age&quot;, 30)&gt;
&lt;CFSET QueryAddRow(my_query, 1)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Username&quot;, &quot;AUser&quot;)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Name&quot;,&quot;Albert User&quot;)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Age&quot;, 10)&gt;
&lt;CFSET QueryAddRow(my_query, 1)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Username&quot;, &quot;BUser&quot;)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Name&quot;,&quot;Brad User&quot;)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Age&quot;, 20)&gt;
&lt;cfoutput&gt;
Query:&lt;br&gt;
&lt;br&gt;
&lt;CFDUMP VAR=&quot;#my_query#&quot;&gt;
&lt;br&gt;
&lt;br&gt;
Row number with username of &quot;AUser&quot; = &lt;b&gt;#QueryRowFromKey(my_query, &quot;Username&quot;, &quot;AUser&quot;)#&lt;/b&gt;
&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Returns the first query row number that contains the specified key value. Useful when using functions that require a query's row number ... but you only have its primary key (or any other value that identifies the record). Returns zero if no matching keyFieldValue is found.]]></description>
			               <starttext><![CDATA[function QueryRowFromKey(theQuery, keyField, keyFieldValue){
	var key_field_value_list = Evaluate("ValueList(theQuery.#keyField#)");
	return ListFindNoCase(key_field_value_list, keyFieldValue);
}]]></starttext>
			               <endtext/>
			               <author>Shawn Seley</author>
			               <platforms/>
			               <created>06-28-2002</created>
			               <lastupdated>06-28-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="1101" template="cfm">
			               <name>queryRowToList</name>
			               <help><![CDATA[... any cfquery here name=&quot;qryExample&quot; ...

&lt;cfset listOfData = queryRowToList(qryExample)&gt;
&lt;cfset listOfData = queryRowToList(qryExample, 100)&gt;
&lt;cfset listOfData = queryRowToList(qryExample, 1000, &quot;|&quot;)&gt;]]></help>
			               <description><![CDATA[Use this function to take row of data from a query and create a simple list from that row. Useful when you are querying a text file as a datasource and the columns are listed in the first row.]]></description>
			               <starttext><![CDATA[function queryRowToList(query){
	var queryrow = 1;
	var j = 1;
	var querycols = listToArray(query.columnList);
	var delim = ",";
	var listReturn = "";
	if(arrayLen(arguments) GT 1) queryrow = arguments[2];
	if(arrayLen(arguments) GT 2) delim = arguments[3];
	for(j = 1; j lte arraylen(querycols); j = j + 1){
		listReturn = ListAppend(listReturn, query[querycols[j]][queryrow], delim);
	}		
	return listReturn;
}]]></starttext>
			               <endtext/>
			               <author>Tim Sloan</author>
			               <platforms/>
			               <created>08-06-2004</created>
			               <lastupdated>08-06-2004</lastupdated>
			          </snippet>
					
				 	<snippet id="358" template="cfm">
			               <name>QueryRowToStruct</name>
			               <help><![CDATA[&lt;cfscript&gt;
	q = querynew(&quot;id,name&quot;);
	queryAddRow(q);
	querySetCell(q,&quot;id&quot;,1);
	querySetCell(q,&quot;name&quot;,&quot;Nathan Dintenfass&quot;);
	queryAddRow(q);
	querySetCell(q,&quot;id&quot;,2);
	querySetCell(q,&quot;name&quot;,&quot;Ben Archibald&quot;);	
	queryAddRow(q);
	querySetCell(q,&quot;id&quot;,3);
	querySetCell(q,&quot;name&quot;,&quot;Raymond Camden&quot;);		
&lt;/cfscript&gt;

&lt;cfdump var=&quot;#queryRowToStruct(q)#&quot;&gt;
&lt;cfdump var=&quot;#queryRowToStruct(q,2)#&quot;&gt;]]></help>
			               <description><![CDATA[Convenience function for turning a given row of query into a structure.  By default, it uses the first row.]]></description>
			               <starttext><![CDATA[function queryRowToStruct(query){
	//by default, do this to the first row of the query
	var row = 1;
	//a var for looping
	var ii = 1;
	//the cols to loop over
	var cols = listToArray(query.columnList);
	//the struct to return
	var stReturn = structnew();
	//if there is a second argument, use that for the row number
	if(arrayLen(arguments) GT 1)
		row = arguments[2];
	//loop over the cols and build the struct from the query row	
	for(ii = 1; ii lte arraylen(cols); ii = ii + 1){
		stReturn[cols[ii]] = query[cols[ii]][row];
	}		
	//return the struct
	return stReturn;
}]]></starttext>
			               <endtext/>
			               <author>Nathan Dintenfass</author>
			               <platforms/>
			               <created>12-11-2001</created>
			               <lastupdated>12-11-2001</lastupdated>
			          </snippet>
					
				 	<snippet id="588" template="cfm">
			               <name>QuerySetCellByKey</name>
			               <help><![CDATA[&lt;CFSET my_query = QueryNew(&quot;Username,Name,Age&quot;)&gt;
&lt;CFSET QueryAddRow(my_query, 1)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Username&quot;, &quot;CUser&quot;)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Name&quot;,&quot;Chris User&quot;)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Age&quot;, 30)&gt;
&lt;CFSET QueryAddRow(my_query, 1)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Username&quot;, &quot;AUser&quot;)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Name&quot;,&quot;Albert User&quot;)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Age&quot;, 10)&gt;
&lt;CFSET QueryAddRow(my_query, 1)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Username&quot;, &quot;BUser&quot;)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Name&quot;,&quot;Brad User&quot;)&gt;
&lt;CFSET QuerySetCell(my_query,&quot;Age&quot;, 20)&gt;

&lt;cfoutput&gt;
Query:&lt;br&gt;
&lt;br&gt;
&lt;CFDUMP VAR=&quot;#my_query#&quot;&gt;
&lt;br&gt;
&lt;br&gt;

Modify with QuerySetCellByKey(my_query, &quot;Username&quot;, &quot;CUser&quot;, &quot;Age&quot;, &quot;31&quot;):&lt;br&gt;
&lt;br&gt;
&lt;cfset QuerySetCellByKey(my_query, &quot;Username&quot;, &quot;CUser&quot;, &quot;Age&quot;, &quot;31&quot;)&gt;
&lt;CFDUMP VAR=&quot;#my_query#&quot;&gt;
&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Allows changing of a query cell by knowing the primary key (or any other identifying field value) within the same row. This is useful for altering existing queries without having to keep track of (or manually finding) the respective row number. Throws an error if keyFieldValue is not found.]]></description>
			               <starttext><![CDATA[function QuerySetCellByKey(theQuery, keyField, keyFieldValue, columnName, newValue){
	var key_field_value_list  = Evaluate("ValueList(theQuery.#keyField#)");
	var row_number            = ListFindNoCase(key_field_value_list, keyFieldValue);
	querysetCell(theQuery,columnName,newValue,row_number);
}]]></starttext>
			               <endtext/>
			               <author>Shawn Seley</author>
			               <platforms/>
			               <created>06-28-2002</created>
			               <lastupdated>06-28-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="1317" template="cfm">
			               <name>querySetRow</name>
			               <help><![CDATA[&lt;!--- add (3) new rows to a query ---&gt;
&lt;cfset myQuery = QueryNew(&quot;UserID,FirstName,LastName,UserName&quot;)&gt;
&lt;cfset QuerySetRow(myQuery, &quot;UserID,FirstName,LastName,UserName&quot;, &quot;1,Amelia,Jones,ajones&quot;)&gt;
&lt;cfset QuerySetRow(myQuery, &quot;UserID,FirstName,LastName,UserName&quot;, &quot;2,Roberta,Freeman,rfreeman&quot;)&gt;
&lt;cfset QuerySetRow(myQuery, &quot;UserID,FirstName,LastName,UserName&quot;, &quot;3,Harriet, Adams ,hadams&quot;)&gt;
&lt;cfdump var=&quot;#myQuery#&quot;&gt;

&lt;!--- update the column values for row number (2) ---&gt;
&lt;cfset QuerySetRow(myQuery, &quot;FirstName,UserName&quot;, &quot;Alfred,AAfreeman&quot;, 2)&gt;
&lt;cfdump var=&quot;#myQuery#&quot;&gt;]]></help>
			               <description><![CDATA[This function allows you to set the values for multiple columns in the specified query row, with a single function call.  If a row number is not specified, the column values will be appended to the end of the query as a new row.  Useful for development.  Similar to using QueryAddRow() plus multiple QuerySetCell() calls.]]></description>
			               <starttext><![CDATA[<cffunction name="querySetRow" returntype="void" output="false">
	<cfargument name="query" type="query" required="true" />
	<cfargument name="columnList" type="string" required="true" />
	<cfargument name="valuesList" type="string" required="true" />
	<cfargument name="rowNumber" type="numeric" required="false" default="0" />
	<cfargument name="delimiter" type="string" required="false"  default="," />
	<cfargument name="trimElements" type="boolean" required="false"  default="true" />
	
	<cfset var i 	   	= 0>
	<cfset var col	   	= "">
	<cfset var value	= "">
	
	<cfif arguments.rowNumber gt 0 and arguments.rowNumber gt arguments.query.recordCount>
		<cfthrow type="InvalidArgument" message="Invalid rowNumber [#arguments.rowNumber#]. The specified query contains [#arguments.query.RecordCount#] records.">
	</cfif>	
	<cfif ListLen(arguments.columnList, arguments.delimiter) NEQ ListLen(arguments.valuesList, arguments.delimiter)>
		<cfthrow type="InvalidArgument" message="[columnList] and [valuesList] do not contain the same number of elements.">
	</cfif>	
	
	<cfscript>
		//by default, append new row to end of query
		if (val(arguments.rowNumber) lt 1) {
			QueryAddRow(arguments.query, 1);
			rowNumber = arguments.query.recordCount;
		}
		
		//set values for each column
		for (i = 1; i lte ListLen(arguments.columnList, arguments.delimiter); i = i + 1) {
			if (arguments.trimElements) {	
				col   = Trim(ListGetAt(arguments.columnList, i, arguments.delimiter));	
				value = Trim(ListGetAt(arguments.valuesList, i, arguments.delimiter));	
			}
			else {
				col   = ListGetAt(arguments.columnList, i, arguments.delimiter);	
				value = ListGetAt(arguments.valuesList, i, arguments.delimiter);	
			}
		    query[col][arguments.rowNumber] = value;
		}
	</cfscript>
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Ell Cord</author>
			               <platforms/>
			               <created>10-18-2005</created>
			               <lastupdated>10-18-2005</lastupdated>
			          </snippet>
					
				 	<snippet id="255" template="cfm">
			               <name>QuerySim</name>
			               <help><![CDATA[&lt;cfscript&gt;
people = querySim(&apos;
id , name , mail
1 | weed | weed@theflowerpot.not
2 | bill | bill@theflowerpot.not
3 | ben | ben@theflowerpot.not
&apos;);
&lt;/cfscript&gt;

People
&lt;cfdump var=&quot;#people#&quot;&gt;]]></help>
			               <description><![CDATA[Accepts a specifically formatted chunk of text, and returns it as a query object.  Based on QuerySim.cfm by hal.helms@TeamAllaire.com.

Pass in a block of text where the first line is a comma separated column list, and subequent lines represent records, with '|' delimited data cells.

Note that version 2 no longer accepts the queryname as the first line.]]></description>
			               <starttext><![CDATA[function querySim(queryData) {
	var fieldsDelimiter="|";
	var colnamesDelimiter=",";
	var listOfColumns="";
	var tmpQuery="";
	var numLines="";
	var cellValue="";
	var cellValues="";
	var colName="";
	var lineDelimiter=chr(10) & chr(13);
	var lineNum=0;
	var colPosition=0;

	// the first line is the column list, eg "column1,column2,column3"
	listOfColumns = Trim(ListGetAt(queryData, 1, lineDelimiter));
	
	// create a temporary Query
	tmpQuery = QueryNew(listOfColumns);

	// the number of lines in the queryData
	numLines = ListLen(queryData, lineDelimiter);
	
	// loop though the queryData starting at the second line
	for(lineNum=2;  lineNum LTE numLines;  lineNum = lineNum + 1) {
	    cellValues = ListGetAt(queryData, lineNum, lineDelimiter);

		if (ListLen(cellValues, fieldsDelimiter) IS ListLen(listOfColumns,",")) {
			QueryAddRow(tmpQuery);
			for (colPosition=1; colPosition LTE ListLen(listOfColumns); colPosition = colPosition + 1){
				cellValue = Trim(ListGetAt(cellValues, colPosition, fieldsDelimiter));
				colName   = Trim(ListGetAt(listOfColumns,colPosition));
				QuerySetCell(tmpQuery, colName, cellValue);
			}
		} 
	}
	
	return( tmpQuery );
	
}]]></starttext>
			               <endtext/>
			               <author>Bert Dawson</author>
			               <platforms/>
			               <created>12-18-2007</created>
			               <lastupdated>12-18-2007</lastupdated>
			          </snippet>
					
				 	<snippet id="117" template="cfm">
			               <name>QuerySlice</name>
			               <help><![CDATA[&lt;CFSET Foo = QueryNew(&quot;name,age,rank&quot;)&gt;
&lt;CFLOOP INDEX=&quot;X&quot; FROM=1 TO=10&gt;
	&lt;CFSET QueryAddRow(Foo)&gt;
	&lt;CFSET QuerySetCell(Foo,&quot;name&quot;,&quot;Random Name #X#&quot;)&gt;
	&lt;CFSET QuerySetCell(Foo,&quot;age&quot;,RandRange(20,50))&gt;
	&lt;CFSET QuerySetCell(Foo,&quot;rank&quot;,RandRange(1,10))&gt;
&lt;/CFLOOP&gt;
&lt;CFOUTPUT&gt;Original...&lt;/CFOUTPUT&gt;
&lt;CFDUMP VAR=&quot;#Foo#&quot;&gt;
&lt;CFSET Shorter = QuerySlice(Duplicate(Foo), 2, 5)&gt;
&lt;CFOUTPUT&gt;Shorter...&lt;/CFOUTPUT&gt;
&lt;CFDUMP VAR=&quot;#Shorter#&quot;&gt;]]></help>
			               <description><![CDATA[Pass this function a query and tell it what row to start with and how many rows to return.  Good beginning for previous/next functionality.]]></description>
			               <starttext><![CDATA[<cffunction name="QuerySliceAndDice" returntype="query" output="false">
	<cfargument name="theQuery" type="query" required="true" />
	<cfargument name="StartRow" type="numeric" required="true" />
	<cfargument name="NumberOfRows" type="numeric" required="true" />
	<cfargument name="ColumnList" type="string" required="false" default="" />
	
	<cfscript>
		var FinalQuery = "";
		var EndRow = StartRow + NumberOfRows;
		var counter = 1;
		var x = "";
		var y = "";
	
		if (arguments.ColumnList IS "") {
			arguments.ColumnList = theQuery.ColumnList;
		}
		FinalQuery = QueryNew(arguments.ColumnList);
			
		if(EndRow GT theQuery.recordcount) {
			EndRow = theQuery.recordcount+1;
		}
		
		QueryAddRow(FinalQuery,EndRow - StartRow);
		
		for(x = 1; x LTE theQuery.recordcount; x = x + 1){
			if(x GTE StartRow AND x LT EndRow) {
				for(y = 1; y LTE ListLen(arguments.ColumnList); y = y + 1) {
					QuerySetCell(FinalQuery, ListGetAt(arguments.ColumnList, y), theQuery[ListGetAt(arguments.ColumnList, y)][x],counter);
				}
				counter = counter + 1;
			}
		}
			
		return FinalQuery;
	</cfscript>
	
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Kevin Bridges</author>
			               <platforms/>
			               <created>05-23-2005</created>
			               <lastupdated>05-23-2005</lastupdated>
			          </snippet>
					
				 	<snippet id="637" template="cfm">
			               <name>QuerySort</name>
			               <help><![CDATA[&lt;cfquery name=&quot;getit&quot; datasource=&quot;cflib&quot; maxrows=4&gt;
    select name,id from tblUDFs
    order by id desc
&lt;/cfquery&gt;
&lt;cfdump var=&quot;#getIt#&quot; label=&quot;Before Sort&quot;&gt;
&lt;cfdump var=&quot;#querySort(getit,&quot;name&quot;)#&quot; label=&quot;After Sort&quot;&gt;]]></help>
			               <description><![CDATA[Sorts a query using Query of Query.]]></description>
			               <starttext><![CDATA[<cffunction name="QuerySort" output="no" returnType="query">
	<cfargument name="query" type="query" required="true">
	<cfargument name="column" type="string" required="true">
	<cfargument name="sortDir" type="string" required="false" default="asc">

	<cfset var newQuery = "">
	
	<cfquery name="newQuery" dbType="query">
		select * from query
		order by #column# #sortDir#
	</cfquery>
	
	<cfreturn newQuery>
	
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Raymond Camden</author>
			               <platforms/>
			               <created>10-15-2002</created>
			               <lastupdated>10-15-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="10" template="cfm">
			               <name>QueryToArrayOfStructures</name>
			               <help><![CDATA[&lt;CFSET Query = QueryNew(&quot;id,name,age&quot;)&gt;
&lt;CFLOOP INDEX=&quot;X&quot; FROM=1 TO=3&gt;
&lt;CFSET QueryAddRow(Query,1)&gt;
&lt;CFSET QuerySetCell(Query,&quot;ID&quot;,X,X)&gt;
&lt;CFSET QuerySetCell(Query,&quot;Name&quot;,&quot;Name #X#&quot;,X)&gt;
&lt;CFSET QuerySetCell(Query,&quot;Age&quot;,X+15,X)&gt;
&lt;/CFLOOP&gt;
&lt;CFSET arrStruct = QueryToArrayOfStructures(Query)&gt;
&lt;CFDUMP VAR=&quot;#arrStruct#&quot;&gt;]]></help>
			               <description><![CDATA[Converts a query object into an array of structures.]]></description>
			               <starttext><![CDATA[function QueryToArrayOfStructures(theQuery){
	var theArray = arraynew(1);
	var cols = ListtoArray(theQuery.columnlist);
	var row = 1;
	var thisRow = "";
	var col = 1;
	for(row = 1; row LTE theQuery.recordcount; row = row + 1){
		thisRow = structnew();
		for(col = 1; col LTE arraylen(cols); col = col + 1){
			thisRow[cols[col]] = theQuery[cols[col]][row];
		}
		arrayAppend(theArray,duplicate(thisRow));
	}
	return(theArray);
}]]></starttext>
			               <endtext/>
			               <author>Nathan Dintenfass</author>
			               <platforms/>
			               <created>09-27-2001</created>
			               <lastupdated>09-27-2001</lastupdated>
			          </snippet>
					
				 	<snippet id="556" template="cfm">
			               <name>QueryToCsv</name>
			               <help><![CDATA[&lt;cfset test_query = QueryNew(&quot;ValueField, DisplayField&quot;)&gt;
&lt;cfset QueryAddRow(test_query, 3)&gt;
&lt;cfset QuerySetCell(test_query,&quot;ValueField&quot;,&quot;blue&quot;, 1)&gt;
&lt;cfset QuerySetCell(test_query,&quot;DisplayField&quot;,&quot;my favorite color is blue&quot;, 1)&gt;
&lt;cfset QuerySetCell(test_query,&quot;ValueField&quot;,&quot;changed the text for the heck of it&quot;, 2)&gt;
&lt;cfset QuerySetCell(test_query,&quot;DisplayField&quot;,&quot;blah blah blah&quot;, 2)&gt;
&lt;cfset QuerySetCell(test_query,&quot;ValueField&quot;,&quot;Louisiana&quot;, 3)&gt;
&lt;cfset QuerySetCell(test_query,&quot;DisplayField&quot;,&quot;The State of Louisiana&quot;, 3)&gt;
&lt;cfoutput&gt;
&lt;pre&gt;
#querytoCSV(test_query)#
&lt;/pre&gt;
&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Transform a query result into a csv formatted variable.]]></description>
			               <starttext><![CDATA[function QueryToCsv(query){
	var csv = "";
	var cols = "";
	var headers = "";
	var i = 1;
	var j = 1;
	
	if(arrayLen(arguments) gte 2) headers = arguments[2];
	if(arrayLen(arguments) gte 3) cols = arguments[3];
	
	if(cols is "") cols = query.columnList;
	if(headers IS "") headers = cols;
	
	headers = listToArray(headers);
	
	for(i=1; i lte arrayLen(headers); i=i+1){
		csv = csv & """" & headers[i] & """;";
	}

	csv = csv & chr(13) & chr(10);
	
	cols = listToArray(cols);
	
	for(i=1; i lte query.recordCount; i=i+1){
		for(j=1; j lte arrayLen(cols); j=j+1){
			csv = csv & """" & query[cols[j]][i] & """;";
		}		
		csv = csv & chr(13) & chr(10);
	}
	return csv;
}]]></starttext>
			               <endtext/>
			               <author>adgnot sebastien</author>
			               <platforms/>
			               <created>06-26-2002</created>
			               <lastupdated>06-26-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="470" template="cfm">
			               <name>QueryToStructOfArrays</name>
			               <help><![CDATA[&lt;CFSET Query = QueryNew(&quot;id,name,age&quot;)&gt;
&lt;CFLOOP INDEX=&quot;X&quot; FROM=1 TO=3&gt;
&lt;CFSET QueryAddRow(Query,1)&gt;
&lt;CFSET QuerySetCell(Query,&quot;ID&quot;,X,X)&gt;
&lt;CFSET QuerySetCell(Query,&quot;Name&quot;,&quot;Name #X#&quot;,X)&gt;
&lt;CFSET QuerySetCell(Query,&quot;Age&quot;,X+15,X)&gt;
&lt;/CFLOOP&gt;
&lt;CFSET Struct = QueryToStructOfArrays(Query)&gt;
&lt;CFDUMP VAR=&quot;#Struct#&quot;&gt;]]></help>
			               <description><![CDATA[Changes a query into a struct of arrays, where the keys of the struct are the column names in the query.  Each struct key holds an array of the values from the query. See also QueryToArrayOfStructs.]]></description>
			               <starttext><![CDATA[function queryToStructOfArrays(q){
		//a variable to hold the struct
		var st = structNew();
		//two variable for iterating
		var ii = 1;
		var cc = 1;
		//grab the columns into an array for easy looping
		var cols = listToArray(q.columnList);
		//iterate over the columns of the query and create the arrays of values
		for(ii = 1; ii lte arrayLen(cols); ii = ii + 1){
			//make the array with the col name as the key in the root struct
			st[cols[ii]] = arrayNew(1);
			//now loop for the recordcount of the query and insert the values
			for(cc = 1; cc lte q.recordcount; cc = cc + 1)
				arrayAppend(st[cols[ii]],q[cols[ii]][cc]);
		}
		//return the struct
		return st;
	}]]></starttext>
			               <endtext/>
			               <author>Nathan Dintenfass</author>
			               <platforms/>
			               <created>02-23-2002</created>
			               <lastupdated>02-23-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="1155" template="cfm">
			               <name>queryToStructOfStructsAutoRow</name>
			               <help><![CDATA[&lt;cfquery name=&quot;test&quot; datasource=&quot;test&quot;&gt;
select * from test
&lt;/cfquery&gt;

&lt;cfset s = queryToStructOfStructsAutoRow(test)&gt;]]></help>
			               <description><![CDATA[Converts a query to a structure of structures with the primary index of the main structure auto incremented.  Thanks to Shawn Seley's QueryToStructOfStructures for the basis of my code.]]></description>
			               <starttext><![CDATA[function queryToStructOfStructsAutoRow(theQuery){
	var theStructure = StructNew();
	var cols = ListToArray(theQuery.columnlist);
	var row = 1;
	var thisRow = "";
	var col = 1;
	
	for(row = 1; row LTE theQuery.recordcount; row = row + 1){
		thisRow = StructNew();
		for(col = 1; col LTE arraylen(cols); col = col + 1){
			thisRow[cols[col]] = theQuery[cols[col]][row];
		} 
		theStructure[row] = Duplicate(thisRow);
	} 
	return theStructure;
}]]></starttext>
			               <endtext/>
			               <author>Peter J. Farrell</author>
			               <platforms/>
			               <created>09-23-2004</created>
			               <lastupdated>09-23-2004</lastupdated>
			          </snippet>
					
				 	<snippet id="523" template="cfm">
			               <name>QueryToStructOfStructures</name>
			               <help><![CDATA[&lt;CFSET Query = QueryNew(&quot;id,name,age&quot;)&gt;
&lt;CFLOOP INDEX=&quot;X&quot; FROM=1 TO=3&gt;
	&lt;CFSET QueryAddRow(Query,1)&gt;
	&lt;CFSET QuerySetCell(Query,&quot;ID&quot;,X+10)&gt;
	&lt;CFSET QuerySetCell(Query,&quot;Name&quot;,&quot;Name #X#&quot;)&gt;
	&lt;CFSET QuerySetCell(Query,&quot;Age&quot;,X+15)&gt;
&lt;/CFLOOP&gt;

&lt;CFSET structStruct = QueryToStructOfStructures(Query, &quot;ID&quot;)&gt;
&lt;CFDUMP VAR=&quot;#structStruct#&quot;&gt;
&lt;br&gt;
&lt;cfloop index=&quot;id&quot; from=&quot;11&quot; to=&quot;13&quot;&gt;
	&lt;cfoutput&gt;structStruct[#id#] = #structStruct[id].name#, #structStruct[id].age#&lt;br&gt;&lt;/cfoutput&gt;
&lt;/cfloop&gt;]]></help>
			               <description><![CDATA[Dumps an entire query into a structure of structures, with each row being easily accessible by knowing its primaryKey value. By making the passed primaryKey a foreign key from another table, you can effectively &quot;join&quot; tables that you couldn't join otherwise.  Some code based on QueryToArrayOfStructures() by Nathan Dintenfass (nathan@changemedia.com)]]></description>
			               <starttext><![CDATA[function QueryToStructOfStructures(theQuery, primaryKey){
  var theStructure  = structnew();
  // remove primary key from cols listing
  var cols          = ListToArray(ListDeleteAt(theQuery.columnlist, ListFindNoCase(theQuery.columnlist, primaryKey)));
  var row           = 1;
  var thisRow       = "";
  var col           = 1;

  for(row = 1; row LTE theQuery.recordcount; row = row + 1){
    thisRow = structnew();
    for(col = 1; col LTE arraylen(cols); col = col + 1){
      thisRow[cols[col]] = theQuery[cols[col]][row];
    }
    theStructure[theQuery[primaryKey][row]] = duplicate(thisRow);
  }
  return(theStructure);
}]]></starttext>
			               <endtext/>
			               <author>Shawn Seley</author>
			               <platforms/>
			               <created>03-27-2002</created>
			               <lastupdated>03-27-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="538" template="cfm">
			               <name>QueryToVars</name>
			               <help><![CDATA[&lt;cfscript&gt;
	//make a simple query
	q = queryNew(&quot;fname,lname&quot;);
	queryAddRow(q,2);
	querySetCell(q,&quot;fname&quot;,&quot;Jedi&quot;,1);
	querySetCell(q,&quot;lname&quot;,&quot;Master&quot;,1);
	querySetCell(q,&quot;fname&quot;,&quot;Ben&quot;,2);
	querySetCell(q,&quot;lname&quot;,&quot;Archibald&quot;,2);	
	//make local variables
	queryToVars(q);
	//now, put the second row into the request scope
	queryToVars(q,&quot;request&quot;,2);
&lt;/cfscript&gt;
&lt;!--- output the variables to the screen ---&gt;
&lt;cfoutput&gt;
	#fname# #lname#&lt;br&gt;
	#request.fname# #request.lname#
&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[A quick way to get the variables in one row of a query into local variables (or any other scope).  You pass in a query and the variables are created based on the column names in the query.  You can also optionally specify a scope and a row in the query to use.]]></description>
			               <starttext><![CDATA[function queryToVars(q){
	//first, an array of the column names for looping
	var cols = listToArray(q.columnList);
	//a var to use as iterator
	var ii = 1;
	//by default, use no scope
	var scope = "";
	//by default, use the first row
	var row = 1;
	//if there is a second argument, use that as the scope
	if(arrayLen(arguments) GT 1)
		scope = arguments[2] & ".";
	//if there is a third argument and it is numeric, use that as the row (make sure it is a positive integer)
	if(arrayLen(arguments) GT 2 and isNumeric(arguments[3]))
		row = ceiling(abs(arguments[3]));		
	//loop over the columns, making a variables for each one
	for(ii = 1; ii lte arrayLen(cols); ii = ii + 1)
		setVariable(scope & cols[ii],q[cols[ii]][row]);
	//return nothing
	return "";	
}]]></starttext>
			               <endtext/>
			               <author>Nathan Dintenfass</author>
			               <platforms/>
			               <created>03-11-2002</created>
			               <lastupdated>03-11-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="648" template="cfm">
			               <name>QueryToXML</name>
			               <help><![CDATA[&lt;!--- by default, use values nodeMode for queryToXML ---&gt;
&lt;cfparam name=&quot;nodeMode&quot; default=&quot;values&quot;&gt;


&lt;cfscript&gt;
	//build a simple query
	q = queryNew(&quot;id,fname,lname&quot;);
	queryAddRow(q,3);
	querySetCell(q,&quot;id&quot;,createUUID(),1);
	querySetCell(q,&quot;fname&quot;,&quot;Nathan&quot;,1);
	querySetCell(q,&quot;lname&quot;,&quot;Dintenfass&quot;,1);
	querySetCell(q,&quot;id&quot;,createUUID(),2);
	querySetCell(q,&quot;fname&quot;,&quot;Ben&quot;,2);
	querySetCell(q,&quot;lname&quot;,&quot;Archibald&quot;,2);	
	querySetCell(q,&quot;id&quot;,createUUID(),3);
	querySetCell(q,&quot;fname&quot;,&quot;Raymond&quot;,3);
	querySetCell(q,&quot;lname&quot;,&quot;Camden&quot;,3);		
	//make the query into an XML object
	xmlObj = queryToXML(q,&quot;users&quot;,&quot;user&quot;,nodeMode);
	//make a string representation of the xml object
	xmlString = toString(xmlObj);
&lt;/cfscript&gt;

&lt;!--- make a simple form for choosing the nodeMode ---&gt;
&lt;cfoutput&gt;
&lt;form action=&quot;#getFileFromPath(getBaseTemplatePath())#?#cgi.query_string#&quot; method=&quot;post&quot;&gt;
	NodeMode: &lt;select name=&quot;nodeMode&quot; onChange=&quot;this.form.submit();&quot;&gt;
		&lt;cfloop list=&quot;values,columns,rows&quot; index=&quot;option&quot;&gt;
			&lt;option value=&quot;#option#&quot;&lt;cfif nodeMode is option&gt; SELECTED&lt;/cfif&gt;&gt;#option#&lt;/option&gt;
		&lt;/cfloop&gt;
	&lt;/select&gt;
&lt;/form&gt;
&lt;/cfoutput&gt;

&lt;strong&gt;HERE IS A CFDUMP OF THE CF QUERY OBJECT&lt;/strong&gt;&lt;br /&gt;
&lt;cfdump var=&quot;#q#&quot;&gt;
&lt;hr /&gt;

&lt;strong&gt;HERE IS A CFDUMP OF THE XML OBJECT&lt;/strong&gt;
&lt;cfdump var=&quot;#xmlObj#&quot;&gt;]]></help>
			               <description><![CDATA[Sure, WDDX is great, but sometimes you want &quot;real&quot; XML for your query.  This function will create an XMLDoc object where the elements match the names of your columns.  You can choose the name of the root node (by default it's &quot;query&quot;) and each row (by default it's &quot;row&quot;)]]></description>
			               <starttext><![CDATA[function queryToXML(query){
	//the default name of the root element
	var root = "query";
	//the default name of each row
	var row = "row";
	//make an array of the columns for looping
	var cols = listToArray(query.columnList);
	//which mode will we use?
	var nodeMode = "values";
	//vars for iterating
	var ii = 1;
	var rr = 1;
	//vars for holding the values of the current column and value
	var thisColumn = "";
	var thisValue = "";
	//a new xmlDoc
	var xml = xmlNew();
	//if there are 2 arguments, the second one is name of the root element
	if(structCount(arguments) GTE 2)
		root = arguments[2];
	//if there are 3 arguments, the third one is the name each element
	if(structCount(arguments) GTE 3)
		row = arguments[3];		
	//if there is a 4th argument, it's the nodeMode
	if(structCount(arguments) GTE 4)
		nodeMode = arguments[4]; 	
	//create the root node
	xml.xmlRoot = xmlElemNew(xml,root);
	//capture basic info in attributes of the root node
	xml[root].xmlAttributes["columns"] = arrayLen(cols);
	xml[root].xmlAttributes["rows"] = query.recordCount;
	//loop over the recordcount of the query and add a row for each one
	for(rr = 1; rr LTE query.recordCount; rr = rr + 1){
		arrayAppend(xml[root].xmlChildren,xmlElemNew(xml,row)); 
		//loop over the columns, populating the values of this row
		for(ii = 1; ii LTE arrayLen(cols); ii = ii + 1){
			thisColumn = lcase(cols[ii]);
			thisValue = query[cols[ii]][rr];
			switch(nodeMode){
				case "rows":
					xml[root][row][rr].xmlAttributes[thisColumn] = thisValue;
					break;
				case "columns":
					arrayAppend(xml[root][row][rr].xmlChildren,xmlElemNew(xml,thisColumn)); 
					xml[root][row][rr][thisColumn].xmlAttributes["value"] = thisValue;
					break;
				default:
					arrayAppend(xml[root][row][rr].xmlChildren,xmlElemNew(xml,thisColumn)); 
					xml[root][row][rr][thisColumn].xmlText = thisValue;						
			}

		}
	}
	//return the xmlDoc
	return xml;	
}]]></starttext>
			               <endtext/>
			               <author>Nathan Dintenfass</author>
			               <platforms/>
			               <created>11-15-2002</created>
			               <lastupdated>11-15-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="1235" template="cfm">
			               <name>QueryTranspose</name>
			               <help><![CDATA[&lt;cfset myQuery = QueryTranspose(myQuery)&gt;]]></help>
			               <description><![CDATA[Transpose a 2D query, turning rows into columns and columns into rows. Original column headers can be turned on or off.]]></description>
			               <starttext><![CDATA[<cffunction name="queryTranspose" returntype="query">
	<cfargument name="inputQuery" type="query" required="true">
	<cfargument name="includeHeaders" type="boolean" default="true" required="false">
		
	<cfset var outputQuery = QueryNew("")>
	<cfset var columnsList = inputQuery.ColumnList>
	<cfset var newColumn = ArrayNew(1)>
	<cfset var row = 1>
	<cfset var zeroString = "000000">
	<cfset var padFactor = int(log10(inputQuery.recordcount)) + 1 >
	<cfset var i = "">
		
	<cfif includeHeaders>
		<cfset queryAddColumn(OutputQuery,"col_#right(zeroString & row, padFactor)#",listToArray(ColumnsList))>
		<cfset row = row + 1>
	</cfif>	

	<cfloop query="inputQuery">
		<cfloop index="i" from="1" to="#listlen(columnsList)#">
			<cfset newColumn[i] = inputQuery[ListGetAt(columnsList, i)][currentRow]>
		</cfloop>
		<cfset queryAddColumn(outputQuery,"col_#right(zeroString & row, padFactor)#",newColumn)>
		<cfset row = row + 1>
	</cfloop>
	
	<cfreturn outputQuery>
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Glenn Buteau</author>
			               <platforms/>
			               <created>08-24-2005</created>
			               <lastupdated>08-24-2005</lastupdated>
			          </snippet>
					
				 	<snippet id="1395" template="cfm">
			               <name>queryTreeSort</name>
			               <help><![CDATA[&lt;cfquery datasource=&quot;#Request.DSN#&quot; name=&quot;Stuff&quot;&gt;
SELECT ItemID, Name, ParentID
FROM Stuff
ORDER BY Name
&lt;/cfquery&gt;
	
&lt;cfset TreeStuff=queryTreeSort(Stuff)&gt;]]></help>
			               <description><![CDATA[Many datasets used in web programming are hierarchical, or parent-child.  Each item may have multiple subordinate items associated with it, and those subordinate items may have their own subordinate items, ad infinitum.  This sort of relationship is normally handled in a database by having a ParentID of one item point to the ID of another item.  The tricky part is getting the data out of the database in a way such that you can display it logically.  Most database engines do not offer native extensions for handling hierarchical data, so the easiest way is often to just have ColdFusion do the sorting.]]></description>
			               <starttext><![CDATA[<cffunction name="queryTreeSort" returntype="query" output="No">
	<cfargument name="Stuff" type="query" required="Yes">
	<cfargument name="ParentID" type="string" required="No" default="ParentID">
	<cfargument name="ItemID" type="string" required="No" default="ItemID">
	<cfargument name="BaseDepth" type="numeric" required="No" default="0">
	<cfargument name="DepthName" type="string" required="No" default="TreeDepth">
	<cfset var RowFromID=StructNew()>
	<cfset var ChildrenFromID=StructNew()>
	<cfset var RootItems=ArrayNew(1)>
	<cfset var Depth=ArrayNew(1)>
	<cfset var ThisID=0>
	<cfset var ThisDepth=0>
	<cfset var RowID=0>
	<cfset var ChildrenIDs="">
	<cfset var ColName="">
	<cfset var Ret=QueryNew(ListAppend(Stuff.ColumnList,Arguments.DepthName))>
	<!--- Set up all of our indexing --->
	<cfloop query="Stuff">
		<cfset RowFromID[Stuff[Arguments.ItemID][Stuff.CurrentRow]]=CurrentRow>
		<cfif NOT StructKeyExists(ChildrenFromID, Stuff[Arguments.ParentID][Stuff.CurrentRow])>
			<cfset ChildrenFromID[Stuff[Arguments.ParentID][Stuff.CurrentRow]]=ArrayNew(1)>
		</cfif>
		<cfset ArrayAppend(ChildrenFromID[Stuff[Arguments.ParentID][Stuff.CurrentRow]], Stuff[Arguments.ItemID][Stuff.CurrentRow])>
	</cfloop>
	<!--- Find parents without rows --->
	<cfloop query="Stuff">
		<cfif NOT StructKeyExists(RowFromID, Stuff[Arguments.ParentID][Stuff.CurrentRow])>
			<cfset ArrayAppend(RootItems, Stuff[Arguments.ItemID][Stuff.CurrentRow])>
			<cfset ArrayAppend(Depth, Arguments.BaseDepth)>
		</cfif>
	</cfloop>
	<!--- Do the deed --->
	<cfloop condition="ArrayLen(RootItems) GT 0">
		<cfset ThisID=RootItems[1]>
		<cfset ArrayDeleteAt(RootItems, 1)>
		<cfset ThisDepth=Depth[1]>
		<cfset ArrayDeleteAt(Depth, 1)>
		<cfif StructKeyExists(RowFromID, ThisID)>
			<!--- Add this row to the query --->
			<cfset RowID=RowFromID[ThisID]>
			<cfset QueryAddRow(Ret)>
			<cfset QuerySetCell(Ret, Arguments.DepthName, ThisDepth)>
			<cfloop list="#Stuff.ColumnList#" index="ColName">
				<cfset QuerySetCell(Ret, ColName, Stuff[ColName][RowID])>
			</cfloop>
		</cfif>
		<cfif StructKeyExists(ChildrenFromID, ThisID)>
			<!--- Push children into the stack --->
			<cfset ChildrenIDs=ChildrenFromID[ThisID]>
			<cfloop from="#ArrayLen(ChildrenIDs)#" to="1" step="-1" index="i">
				<cfset ArrayPrepend(RootItems, ChildrenIDs[i])>
				<cfset ArrayPrepend(Depth, ThisDepth + 1)>
			</cfloop>
		</cfif>
	</cfloop>
	<cfreturn Ret>
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Rick Osborne</author>
			               <platforms/>
			               <created>03-28-2006</created>
			               <lastupdated>03-28-2006</lastupdated>
			          </snippet>
					
				 	<snippet id="1397" template="cfm">
			               <name>quickSort2D</name>
			               <help><![CDATA[&lt;cfset foo = arrayNew(2)&gt;
&lt;cfset top = 5&gt;
&lt;cfloop index=&quot;x&quot; from=&quot;1&quot; to=&quot;5&quot;&gt;
	&lt;cfloop index=&quot;y&quot; from=&quot;1&quot; to=&quot;#top#&quot;&gt;
		&lt;cfset foo[x][y] = randRange(1,100)&gt;
	&lt;/cfloop&gt;
&lt;/cfloop&gt;

&lt;cfdump var=&quot;#foo#&quot;&gt;

&lt;cfdump var=&quot;#quickSort2d(foo,2,1, top)#&quot;&gt;]]></help>
			               <description><![CDATA[Send the array you want to sort, the column you want to sort by, the lower index you want to start the sort from, and then upper index you want to start the sort from.  The function will sort the array using the quicksort algorithm and return the sorted array.]]></description>
			               <starttext><![CDATA[function quickSort2D(arrayToSort, key, down, top) {
	var i = down;
	var j = top;
	var p = JavaCast("int",((down + top)/2));
	var x = arrayToSort[p][key];
	var temp = 0;
	var length = 0;
	var y = 0;
	var z = 0;
	
	do {
		while(arrayToSort[i][key] LT x AND i LT p) i=i+1;
		while(arrayToSort[j][key] GT x AND j GT p) j=j-1;
		if(i LT j){
			if(j EQ p){
				length = ArrayLen(arrayToSort)+1;
				for(z=length;z GT p+1;z=z-1)
					for(y=1;y LTE ArrayLen(arrayToSort[i]);y=y+1)
						arrayToSort[z][y]=arrayToSort[z-1][y];
								
				for(y=1;y LTE ArrayLen(arrayToSort[i]);y=y+1){ 
					arrayToSort[j+1][y] = arrayToSort[i][y]; 				
					arrayToSort[i][y] = 0;
				}
				
				ArrayDeleteAt(arrayToSort,i);
				
				i=i-1;
				p=p-1;
			}
				
			else if(i EQ p){
				length = ArrayLen(arrayToSort)+1;
				for(z=length;z GT p;z=z-1)
					for(y=1;y LTE ArrayLen(arrayToSort[i]);y=y+1)
						arrayToSort[z][y]=arrayToSort[z-1][y];
				
				j = j + 1;
				i = i + 1;
				p = p + 1;
				
				for(y=1;y LTE ArrayLen(arrayToSort[i]);y=y+1){ 
					arrayToSort[i-1][y] = arrayToSort[j][y]; 				
					arrayToSort[j][y] = 0;
				}
				
				ArrayDeleteAt(arrayToSort,j);
			}
			
			else{
				for(y=1;y LTE ArrayLen(arrayToSort[i]);y=y+1){
					temp = arrayToSort[i][y];
					arrayToSort[i][y] = arrayToSort[j][y];
					arrayToSort[j][y] = temp;		
				}
			}					
		}
				
		if(i LT p) i=i+1;
		if(j GT p) j=j-1;		
				
	}while(i LT j);
	
	if(down LT j) arrayToSort = QuickSort2D(arrayToSort, key, down, p-1);
	if(i LT top) arrayToSort = QuickSort2D(arrayToSort, key, p+1, top);

	return arrayToSort;
}]]></starttext>
			               <endtext/>
			               <author>Matthew Wear</author>
			               <platforms/>
			               <created>03-28-2006</created>
			               <lastupdated>03-28-2006</lastupdated>
			          </snippet>
					
				 	<snippet id="1435" template="cfm">
			               <name>randomWeightedSelection</name>
			               <help><![CDATA[&lt;cfset data = structNew()&gt;
&lt;cfset data[&apos;abc&apos;] = 5&gt;
&lt;cfset data[&apos;def&apos;] = 20&gt;
&lt;cfset data[&apos;mno&apos;] = 50&gt;
&lt;cfset data[&apos;xyz&apos;] = 25&gt;

&lt;cfset counts = structNew()&gt;
&lt;cfset toLimit = 100&gt;
&lt;cfloop index=&quot;index&quot; from=&quot;1&quot; to=&quot;#toLimit#&quot;&gt;
	&lt;cfset sels = randomWeightedSelection(data,1)&gt;
	&lt;cfif not StructKeyExists(counts,sels[1])&gt;&lt;cfset counts[sels[1]] = 0&gt;&lt;/cfif&gt;
	&lt;cfset counts[sels[1]] = counts[sels[1]]+1&gt;
&lt;/cfloop&gt;
&lt;cfloop index=&quot;key&quot; list=&quot;#StructKeyList(counts)#&quot;&gt;
	&lt;cfoutput&gt;
		&lt;p&gt;#key#(#data[key]#) = #counts[key]/toLimit#&lt;/p&gt;
	&lt;/cfoutput&gt;
&lt;/cfloop&gt;]]></help>
			               <description><![CDATA[Requires a structure and the number of selections to make (with replacement).
All keys are selectable elements.
All values are unbounded numeric weights, representing the likelyhood of selection for their respective keys.
Based on free code by Peter Norvig (http://aima.cs.berkeley.edu/python/search.html).]]></description>
			               <starttext><![CDATA[function randomWeightedSelection(weights, n){
	var seq = structKeyArray(weights);
	var totals = arrayNew(1);
	var runningtotal = 0;
	var selections = arrayNew(1);
	var s = 0;
	var i = 0;
	
	for(i=1; i lte arrayLen(seq); i=i+1){
		runningtotal = runningtotal + weights[seq[i]];
		arrayAppend(totals, runningtotal);
	}
	for(s=1; s lte n; s=s+1){
		r = rand()*runningtotal;
		for(i=1; i lte arrayLen(seq); i=i+1){
			if(totals[i] gt r){
				arrayAppend(selections,seq[i]);
				break;
			}
		}
	}
	
	return selections;
}]]></starttext>
			               <endtext/>
			               <author>Chris Spencer</author>
			               <platforms/>
			               <created>05-25-2006</created>
			               <lastupdated>05-25-2006</lastupdated>
			          </snippet>
					
				 	<snippet id="915" template="cfm">
			               <name>ReGroupStructureBy</name>
			               <help><![CDATA[&lt;cfscript&gt;
mydata = arraynew(1);

mydata[1] = structnew();
mydata[1].age = 25;
mydata[1].gender = &quot;m&quot;;
mydata[1].state = &quot;ca&quot;;

mydata[2] = structnew();
mydata[2].age = 25;
mydata[2].gender = &quot;m&quot;;
mydata[2].state = &quot;ca&quot;;

mydata[3] = structnew();
mydata[3].age = 25;
mydata[3].gender = &quot;f&quot;;
mydata[3].state = &quot;ca&quot;;

mydata[4] = structnew();
mydata[4].age = 30;
mydata[4].gender = &quot;m&quot;;
mydata[4].state = &quot;wa&quot;;

mydata[5] = structnew();
mydata[5].age = 30;
mydata[5].gender = &quot;m&quot;;
mydata[5].state = &quot;wa&quot;;

mydata[6] = structnew();
mydata[6].age = 30;
mydata[6].gender = &quot;f&quot;;
mydata[6].state = &quot;wa&quot;;
&lt;/cfscript&gt;

&lt;cfset newdata = ReGroupBy(mydata,&quot;state&quot;)&gt;

&lt;cfdump var=&quot;#newdata#&quot;&gt;]]></help>
			               <description><![CDATA[Pass an Array of structures and the name of a column that exists within each, and it will create a Grouped &quot;Structure of Array of Structures&quot;.]]></description>
			               <starttext><![CDATA[function ReGroupBy(mydata,col){
  var i = "";
  var sttemp = structnew();
  var thisValue = "";
  for (i=1; i LTE arraylen(mydata); i=i+1){
    thisValue = mydata[i][col];
    if (not structkeyexists(sttemp, thisValue)){
      sttemp[thisValue] = arraynew(1);
    }
    arrayappend(sttemp[thisValue] , mydata[i]);
  }
  return sttemp;
}]]></starttext>
			               <endtext/>
			               <author>Casey Broich</author>
			               <platforms/>
			               <created>05-26-2003</created>
			               <lastupdated>05-26-2003</lastupdated>
			          </snippet>
					
				 	<snippet id="1074" template="cfm">
			               <name>RemoveEmptyStructureKeys</name>
			               <help><![CDATA[&lt;cfset s = structNew()&gt;
&lt;cfset s.foo = &quot;&quot;&gt;
&lt;cfset s.goo = &quot;something&quot;&gt;
&lt;cfdump var=&quot;#removeEmptyStructureKeys(s)#&quot;&gt;]]></help>
			               <description><![CDATA[Removes any empty structure keys from within a structure. This is often useful when passing FORM scope variables to a component as an argumentCollection.]]></description>
			               <starttext><![CDATA[function removeEmptyStructureKeys(structure) {
	var newStructure = structNew();
	var keys = structKeyList(arguments.structure);
	var name = "";
	var i = 1;
	for (;i lte listLen(keys);i=i+1) {
		name = listGetAt(keys,i);
		if (not isSimpleValue(arguments.structure[name])) {
			newStructure[name] = arguments.structure[name];
		}
		else if (arguments.structure[name] neq "") {
			newStructure[name] = arguments.structure[name];
		}
	}
	return newStructure;
}]]></starttext>
			               <endtext/>
			               <author>Brian Rinaldi</author>
			               <platforms/>
			               <created>04-19-2004</created>
			               <lastupdated>04-19-2004</lastupdated>
			          </snippet>
					
				 	<snippet id="1993" template="cfm">
			               <name>REStructFindValue</name>
			               <help><![CDATA[&lt;cfscript&gt;
testStruct = StructNew();
testStruct.key1 = &quot;This is a test.&quot;;
testStruct.key2 = ArrayNew(1);
testStruct.key2[1] = StructNew();
testStruct.key2[1].key1 =  &quot;This is not a test.&quot;;
testStruct.key2[1].key2 = &quot;This is not a test&quot;;
testStruct.key3 = ArrayNew(1);
testStruct.key3[1] = &quot;This is not a test&quot;;
result = REStructFindValue(testStruct,&apos;not a test$&apos;);
&lt;/cfscript&gt;
&lt;cfdump var=&quot;#result#&quot;&gt;]]></help>
			               <description><![CDATA[Searches recursively through a substructure of nested arrays, structures, and other elements for structures with values that match the search pattern in the reg_expression parameter.]]></description>
			               <starttext><![CDATA[<cffunction name="REStructFindValue" returntype="array" output="false">
	<cfargument name="top" type="any" required="true">
	<cfargument name="reg_expression" type="string" required="true">
	<cfargument name="scope" type="string" required="false">
	<cfargument name="owner" type="any" required="false">
	<cfargument name="path" type="string" required="false">
	<cfargument name="results" type="any" required="false">
	
	<cfset var key = "">
	<cfset var i = "">
	<cfset var result="">	
	
	<!--- set default values --->
	<cfif not StructKeyExists(arguments,"scope")>
		<cfset arguments.scope = "one">
	</cfif>
	
	<cfif not StructKeyExists(arguments,"owner")>
		<cfset arguments.owner = arguments.top>
	</cfif>
	
	<cfif not StructKeyExists(arguments,"path")>
		<cfset arguments.path = "">
	</cfif>
	
	<cfif not StructKeyExists(arguments,"results")>
		<cfset arguments.results = CreateObject("java","java.util.ArrayList").init()>
	</cfif>
	
	<!--- exit if scope is "one" and we have a result --->
	<cfif CompareNoCase(arguments.scope,"one") eq 0
		and ArrayLen(arguments.results) eq 1>
				
		<cfreturn arguments.results>
		
	</cfif>
		
	<!--- recurse or do test depending on type --->
	<cfif IsStruct(arguments.top)>	
	
		<cfloop collection="#arguments.top#" item="key">	
			<cfset REStructFindValue(arguments.top[key],arguments.reg_expression,arguments.scope,arguments.top,"#arguments.path#.#key#",arguments.results)>
		</cfloop>		
		
	<cfelseif IsArray(arguments.top)>
	
		<cfloop from="1" to="#ArrayLen(arguments.top)#" index="i">	
			<cfset REStructFindValue(arguments.top[i],arguments.reg_expression,arguments.scope,arguments.top,"#path#[#i#]",arguments.results)>
		</cfloop>
		
	<cfelseif IsSimpleValue(arguments.top)
		and IsStruct(arguments.owner)
		and REFind(arguments.reg_expression,arguments.top)>			
			
		<cfset result = StructNew()>
		<cfset result["key"] = ListLast(arguments.path,".")>
		<cfset result["owner"] = arguments.owner>
		<cfset result["path"] = arguments.path>		
		<cfset ArrayAppend(arguments.results,result)>
		
	</cfif>
		
	<cfreturn arguments.results>
			
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Nathan Mische</author>
			               <platforms/>
			               <created>07-12-2009</created>
			               <lastupdated>07-12-2009</lastupdated>
			          </snippet>
					
				 	<snippet id="1994" template="cfm">
			               <name>REStructFindValueNoCase</name>
			               <help><![CDATA[&lt;cfscript&gt;
testStruct = StructNew();
testStruct.key1 = &quot;This is a test.&quot;;
testStruct.key2 = ArrayNew(1);
testStruct.key2[1] = StructNew();
testStruct.key2[1].key1 =  &quot;This is not a test.&quot;;
testStruct.key2[1].key2 = &quot;This is not a test&quot;;
testStruct.key3 = ArrayNew(1);
testStruct.key3[1] = &quot;This is not a test&quot;;
result = REStructFindValueNoCase(testStruct,&apos;not a test$&apos;);
&lt;/cfscript&gt;
&lt;cfdump var=&quot;#result#&quot;&gt;]]></help>
			               <description><![CDATA[Searches recursively through a substructure of nested arrays, structures, and other elements for structures with values that match the search pattern in the reg_expression parameter. The search is case-insensitive.]]></description>
			               <starttext><![CDATA[<cffunction name="REStructFindValueNoCase" returntype="array" output="false">
	<cfargument name="top" type="any" required="true">
	<cfargument name="reg_expression" type="string" required="true">
	<cfargument name="scope" type="string" required="false">
	<cfargument name="owner" type="any" required="false">
	<cfargument name="path" type="string" required="false">
	<cfargument name="results" type="any" required="false">
	
	<cfset var key = "">
	<cfset var i = "">
	<cfset var result="">	
	
	<!--- set default values --->
	<cfif not StructKeyExists(arguments,"scope")>
		<cfset arguments.scope = "one">
	</cfif>
	
	<cfif not StructKeyExists(arguments,"owner")>
		<cfset arguments.owner = arguments.top>
	</cfif>
	
	<cfif not StructKeyExists(arguments,"path")>
		<cfset arguments.path = "">
	</cfif>
	
	<cfif not StructKeyExists(arguments,"results")>
		<cfset arguments.results = CreateObject("java","java.util.ArrayList").init()>
	</cfif>
	
	<!--- exit if scope is "one" and we have a result --->
	<cfif CompareNoCase(arguments.scope,"one") eq 0
		and ArrayLen(arguments.results) eq 1>
				
		<cfreturn arguments.results>
		
	</cfif>
		
	<!--- recurse or do test depending on type --->
	<cfif IsStruct(arguments.top)>	
	
		<cfloop collection="#arguments.top#" item="key">	
			<cfset REStructFindValueNoCase(arguments.top[key],arguments.reg_expression,arguments.scope,arguments.top,"#arguments.path#.#key#",arguments.results)>
		</cfloop>		
		
	<cfelseif IsArray(arguments.top)>
	
		<cfloop from="1" to="#ArrayLen(arguments.top)#" index="i">	
			<cfset REStructFindValueNoCase(arguments.top[i],arguments.reg_expression,arguments.scope,arguments.top,"#path#[#i#]",arguments.results)>
		</cfloop>
		
	<cfelseif IsSimpleValue(arguments.top)
		and IsStruct(arguments.owner)
		and REFindNoCase(arguments.reg_expression,arguments.top)>			
			
		<cfset result = StructNew()>
		<cfset result["key"] = ListLast(arguments.path,".")>
		<cfset result["owner"] = arguments.owner>
		<cfset result["path"] = arguments.path>		
		<cfset ArrayAppend(arguments.results,result)>
		
	</cfif>
		
	<cfreturn arguments.results>
			
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Nathan Mische</author>
			               <platforms/>
			               <created>07-12-2009</created>
			               <lastupdated>07-12-2009</lastupdated>
			          </snippet>
					
				 	<snippet id="156" template="cfm">
			               <name>RowsToColumns</name>
			               <help><![CDATA[&lt;CFSCRIPT&gt;
	Q = QueryNew(&quot;Name&quot;);
	QueryAddRow(Q,11);
	QuerySetCell(Q,&quot;Name&quot;,&quot;Anna&quot;,1);
	QuerySetCell(Q,&quot;Name&quot;,&quot;Barry&quot;,2);
	QuerySetCell(Q,&quot;Name&quot;,&quot;Charles&quot;,3);
	QuerySetCell(Q,&quot;Name&quot;,&quot;Dana&quot;,4);
	QuerySetCell(Q,&quot;Name&quot;,&quot;Ebert&quot;,5);
	QuerySetCell(Q,&quot;Name&quot;,&quot;Fred&quot;,6);
	QuerySetCell(Q,&quot;Name&quot;,&quot;Gorf&quot;,7);
	QuerySetCell(Q,&quot;Name&quot;,&quot;Jeanne&quot;,8);
	QuerySetCell(Q,&quot;Name&quot;,&quot;Hank&quot;,9);
	QuerySetCell(Q,&quot;Name&quot;,&quot;Ingrid&quot;,10);
	QuerySetCell(Q,&quot;Name&quot;,&quot;Jacob&quot;,11);
&lt;/CFSCRIPT&gt;

 &lt;cfset new = rowsToColumns(Q,3,&quot;cols&quot;)&gt;
 &lt;table border=&quot;1&quot;&gt;
 	&lt;tr&gt;
 		&lt;cfset counter = 0&gt;
 		&lt;cfoutput query=&quot;new&quot;&gt;
 			&lt;cfset counter = counter + 1&gt;
 			&lt;td&gt;#name#&lt;/td&gt;
 			&lt;cfif Counter is cols and counter is not new.recordcount&gt;
 				&lt;/tr&gt;&lt;tr&gt;
 				&lt;cfset counter = 0&gt;
 			&lt;/cfif&gt;
 		&lt;/cfoutput&gt;
 	&lt;/tr&gt;
 &lt;/table&gt;]]></help>
			               <description><![CDATA[Takes a query and transforms it to allow outputting for viewing in columns instead of rows. 

You specify the query you want to parse and the number of columns to put it into.

For example, if you have output that looks like:

&lt;PRE&gt;
a b c
d e f
&lt;/PRE&gt;

you could output it as 

&lt;PRE&gt;
a c e
b d f
&lt;/PRE&gt;

PLEASE NOTE: This function will put empty strings into cells that do not need filling, so if you have:

&lt;PRE&gt;
a d g
b e h
c f 
&lt;/PRE&gt;

The cell after &quot;f&quot; would contain empty values.  This is done to allow consistent and easy outputting without needing to a lot of parsing after the tag is called.

It is still up to you as a developer to do the work to put the output into the proper number of columns.  For instance:
&lt;PRE&gt;
&lt;cfset getUsers = rowsToColumns(yourQuery,4,&quot;cols&quot;)&gt;
&lt;table border=&quot;1&quot;&gt;
	&lt;tr&gt;
		&lt;cfset counter = 0&gt;
		&lt;cfoutput query=&quot;GetUsers&quot;&gt;
			&lt;cfset counter = counter + 1&gt;
			&lt;td&gt;#LastName#, #FirstName#&lt;/td&gt;
			&lt;cfif counter is cols and counter is not getUsers.recordcount&gt;
				&lt;/tr&gt;&lt;tr&gt;
				&lt;cfset counter = 0&gt;
			&lt;/cfif&gt;
		&lt;/cfoutput&gt;
	&lt;/tr&gt;
&lt;/table&gt;
&lt;/PRE&gt;]]></description>
			               <starttext><![CDATA[function rowsToColumns(query,maxColumns,actualColumnCountVarName){
	//make an array of the columns in the incoming query for looping
	var columnArray = listToArray(query.columnlist);
	//make a new query to return based on the columns of the incoming query
	var newQuery = queryNew(query.columnlist);
	//figure out how many rows there will be
	var rows = ceiling(query.recordcount/maxColumns);
	//set up a var to count row we are on
	var onRow = 1;
	//set up a var to count the column we are on
	var onColumn = 0;
	//set up a var to hold the row we want to grab
	var getRow = 0;
	//set up a var to index the outer loop
	var ii = 1;
	//set up a var to index the inner loop
	var zz = 1;
	//if there will be extra columns, make sure no more columns than necessary.  this is necessary to ensure that if you ask for more columns than there are records to fill you know how many there really are!!
	if(ceiling(query.recordcount/rows) LT maxColumns)
		maxColumns = ceiling(query.recordcount/rows);
	//starting on row 1, loop through the recordcount of the original query, putting rows in the new query					
	for(ii = 1; ii lte evaluate(rows * maxColumns); ii = ii + 1){
		//increment the column we are now on
		onColumn = onColumn + 1;
		//get the proper row from the original query
		getRow = ((onColumn - 1) * rows) + onRow;
		//now add a row to the newQuery
		queryAddRow(newQuery);
		//loop through the columns, putting the cells into the newQuery
		for(zz = 1; zz lte arraylen(columnArray); zz = zz + 1){
			//if the row we want is lower than than the recordcount, put in the value
			if(getRow LTE query.recordcount)
				querySetCell(newQuery,columnArray[zz],query[columnArray[zz]][getRow]);
			//otherwise, just set it to a blank string
			else
				querySetCell(newQuery,columnArray[zz],"");
		} 
		//if the column we are on is the same as the maxColumns, reset the column we are on and increment the row
		if(onColumn EQ maxColumns){
			onColumn = 0;
			onRow = onRow + 1;
		}
	}
	//set the variable for the number of columns!
	setVariable(actualColumnCountVarName,maxColumns);
	//return the new query
	return newQuery;				
}]]></starttext>
			               <endtext/>
			               <author>Nathan Dintenfass</author>
			               <platforms/>
			               <created>03-10-2010</created>
			               <lastupdated>03-10-2010</lastupdated>
			          </snippet>
					
				 	<snippet id="924" template="cfm">
			               <name>saTOss</name>
			               <help><![CDATA[&lt;cfscript&gt;
mystruct = structnew();
mystruct.ID = listtoarray(&quot;400,100,500&quot;);
mystruct.Name = listtoarray(&quot;Joe,John,Jake&quot;);
mystruct.Age = listtoarray(&quot;35,25,29&quot;);
&lt;/cfscript&gt;
&lt;cfset myStruct = saTOss(mystruct,&quot;ID&quot;)&gt;
&lt;cfdump var=&quot;#myStruct#&quot;&gt;]]></help>
			               <description><![CDATA[Converts a structure of arrays into a name/key style structure. For example, if the structure contains three keys, each arrays, named age, ID, and name, you can ask this UDF to return a new structure where the keys are based on ID. Each item in the ID array will be a key of the new struct. Each key will be a struct containing each of the keys from the previous structure, along with the corresponding data. In other words, oldStruct.name[X] will equal newStruct[id].name.
 Optional param to specify which columns each keyed structure will contain.]]></description>
			               <starttext><![CDATA[function saTOss(struct,thekey){
	var x = "";
	var i = ""; 
	var ii = ""; 
	var new = structnew();
	var cols = structkeyarray(Struct); 

	if(arrayLen(arguments) GT 2) cols = listToArray(arguments[3]);
	
	for(i = 1; i lte arraylen(Struct[thekey]); i = i + 1){
		new[Struct[thekey][i]] = structnew();
		for(ii = 1; ii lte arraylen(cols); ii = ii + 1){
			new[Struct[thekey][i]][cols[ii]] = Struct[cols[ii]][i];
		}
	}
	return new;
}]]></starttext>
			               <endtext/>
			               <author>Casey Broich</author>
			               <platforms/>
			               <created>06-12-2003</created>
			               <lastupdated>06-12-2003</lastupdated>
			          </snippet>
					
				 	<snippet id="1048" template="cfm">
			               <name>ScopeCoalesce</name>
			               <help><![CDATA[&lt;cfset request.testing = &quot;20&quot;&gt;
&lt;cfset form.testing = &quot;10&quot;&gt;
&lt;cfset url.testing = &quot;5&quot;&gt;
&lt;cfset variables.testing = ScopeCoalesce(&quot;testing&quot;, &quot;client,form,url&quot;)&gt;
&lt;cfoutput&gt;
  variables.testing = &apos;#variables.testing#&apos;
&lt;/cfoutput&gt;
&lt;!- the output will display &apos;10&apos; -&gt;]]></help>
			               <description><![CDATA[This UDF can be used to get a value from a form, url, or other scope variable depending on its existence.  It can also be useful to force a scope precedence that is different from the ColdFusion default.  The optional 3rd parameter allows you to define the default return value if is desired.]]></description>
			               <starttext><![CDATA[function ScopeCoalesce(strVariable, lstScopes) {
  var vRet = "";
  var nIndex = 1;
  var nLstLen = ListLen(lstScopes);

  // assign the default return if passed in
  If (ArrayLen(Arguments) GTE 3)
    vRet = Arguments[3];

  // loop over the list
  while (nIndex LTE nLstLen) {
    if (IsDefined(ListGetAt(lstScopes, nIndex) & '.' & strVariable)) {
      vRet = Evaluate(ListGetAt(lstScopes, nIndex) & '.' & strVariable);
      break;
    }
    nIndex = nIndex + 1;
  }

  return vRet;
}]]></starttext>
			               <endtext/>
			               <author>Scott Jibben</author>
			               <platforms/>
			               <created>02-17-2004</created>
			               <lastupdated>02-17-2004</lastupdated>
			          </snippet>
					
				 	<snippet id="1276" template="cfm">
			               <name>shiftArray</name>
			               <help><![CDATA[&lt;cfset dowArray = arrayNew(1)&gt;
&lt;cfloop index=&quot;x&quot; from=&quot;1&quot; to=&quot;7&quot;&gt;
	&lt;cfset arrayAppend(dowArray,x)&gt;
&lt;/cfloop&gt;

&lt;cfloop index=&quot;x&quot; from=&quot;1&quot; to=&quot;7&quot;&gt;
	&lt;cfdump var=&quot;#shiftArray(dowArray,x)#&quot;&gt;
&lt;/cfloop&gt;]]></help>
			               <description><![CDATA[Allows you to move an array index and the remaining indexes below it to the top of an array. Extremly helpful in building grid based outputs such as calendars.]]></description>
			               <starttext><![CDATA[function shiftArray(inArray,ShiftOnVal) {
	var tmpArray = arrayNew(1);
	var x = 0;
        
	for(x=1; x lte arrayLen(inArray); x=x+1) {
		if(inArray[x] EQ ShiftOnVal) { break; }
		else {
			arrayAppend(tmpArray,inArray[x]);
			arrayDeleteAt(inArray,x);
			x=0;
		}
	}

	for(x=1;x lte arrayLen(tmpArray); x=x+1) arrayAppend(inArray,tmpArray[x]);
        
	return inArray;
}]]></starttext>
			               <endtext/>
			               <author>Richard Nugen</author>
			               <platforms/>
			               <created>08-16-2005</created>
			               <lastupdated>08-16-2005</lastupdated>
			          </snippet>
					
				 	<snippet id="1880" template="cfm">
			               <name>sortArrayOfStructures</name>
			               <help><![CDATA[&lt;cfscript&gt;

	// 	EXAMPLE USAGE:
	//an array of 4 persons, with three properties...
	variables.persons = arrayNew(1);
	variables.person = structNew();
	variables.person.name = &apos;Martijn&apos;;
	variables.person.age = 29;
	variables.person.weight = 78;
	arrayAppend(variables.persons, variables.person);
	
	variables.person = structNew();
	variables.person.name = &apos;Jelle&apos;;
	variables.person.age = 29;
	variables.person.weight = 85;
	arrayAppend(variables.persons, variables.person);

	variables.person = structNew();
	variables.person.name = &apos;Lammert&apos;;
	variables.person.age = 51;
	variables.person.weight = 78;
	arrayAppend(variables.persons, variables.person);
		
	variables.person = structNew();
	variables.person.name = &apos;Bas&apos;;
	variables.person.age = 51;
	variables.person.weight = 78;
	arrayAppend(variables.persons, variables.person);
	
	
	
	// specify how to sort: 
	// first on age - descending
	// second on weight - ascending
	// third on name - ascending
	variables.sortkeys = arrayNew(1);
	variables.sortKey = structNew();
	variables.sortKey.keyName = &quot;age&quot;;
	variables.sortKey.sortOrder = &quot;descending&quot;;
	arrayAppend(variables.sortKeys, variables.sortKey);
	variables.sortKey = structNew();
	variables.sortKey.keyName = &quot;weight&quot;;
	variables.sortKey.sortOrder = &quot;ascending&quot;;
	arrayAppend(variables.sortKeys, variables.sortKey);
	variables.sortKey = structNew();
	variables.sortKey.keyName = &quot;name&quot;;
	variables.sortKey.sortOrder = &quot;ascending&quot;;
	arrayAppend(variables.sortKeys, variables.sortKey);
	
	// do the sorting
	variables.persons_sorted = sortArrayOfStructures(variables.persons, variables.sortKeys);
	


&lt;/cfscript&gt;

&lt;h3&gt;Unsorted:&lt;/h3&gt;
&lt;cfdump var=&quot;#variables.persons#&quot;&gt;


&lt;h3&gt;Sorted:&lt;/h3&gt;
&lt;cfdump var=&quot;#variables.persons_sorted#&quot;&gt;]]></help>
			               <description><![CDATA[This function performs a so-called 'insertion sort' on an array of structures. You can specify multiple keys to sort on. The sort order (&quot;descending&quot;) or (&quot;ascending&quot;) seperately per key
Sorting is hierarchical: elements that match on the first-specified key are sorted on the second key; element that match on the first two key are sorted on the third key and so on..]]></description>
			               <starttext><![CDATA[function sortArrayOfStructures(arrayToSort,sortKeys){
	// This function takes three arguments, of which the third is optional
	
	// The first argument 'arrayToSort' is (obviously) the array to sort. This must be an array that is to be sorted
	// on one or more keys. Keys to be sorted on must contain numbers or strings
	
	// Sortkeys are specified as stuctures in the second argument 'sortkeys', which is an array
	// sortkey struct must contain the following keys: 
	// keyname - string - the name of a key on which to 	
	// sortorder - string - either "ascending" or "descending"
	
	//NOTE: By default, the structures in the returned array point to the same memory location
	// as the structures in the argument 'arrayToSort'. After executing this function
	// changing a structure in the returned array thus also changes the corresponding 
	// structure in the argument array, and vice versa! If this kind of behavior is unwanted,
	// specify the third argument 'doDuplicate' as true.
	
	// a struct to hold variables local to this function
	var locals = structNew();
		
	// by default, return the structs in the array by reference 
	if (ArrayLen(Arguments) eq 2)	{
		arguments[3] = false;
	}
		
	// the array to be returned by this function (now empty)
	locals.arrayToReturn = arrayNew(1);
	// the number of elements in the array that was passed in
	locals.nElements = arrayLen(arguments.arrayToSort);
	// the number of key on which sorting is to take place
	locals.nSortKeys = arrayLen(arguments.sortKeys);
				
	// for every element in the array that was passed in
	for (locals.i = 1; locals.i lte locals.nElements; locals.i = locals.i + 1) {
		// reference to the data in the current element in 'arrayToSort'
		locals.elementData = arguments.arrayToSort[locals.i];			
			
		// purpose of the code below is to determine on what position the 
		// current element is to be put on the array to be returned
		// the position is initialized as 1
		locals.insertPosition = 1;
			
		// for every element that has been previously put in the array to return
		for (locals.j = 1; locals.j lt locals.i; locals.j = locals.j + 1) {
				
			// reference to the current element in the array to return
			locals.previousElementData = locals.arrayToReturn[locals.j];
				
			// boolean used in the loop over sortkeys, to indicate that the loop over
			// elements in the array to return must be broken out of.
			locals.doBreak = false;
				
			// for every sortkey
			for (locals.k = 1; locals.k lte locals.nSortKeys; locals.k = locals.k + 1) {
					
				// specifications for the current key
				locals.currentKey = arguments.sortKeys[locals.k];
				locals.currentValue = locals.elementData[locals.currentKey.keyName];
					
				// value of the current key in the current element in the array to return
				locals.previousValue = locals.previousElementData[locals.currentKey.keyName];
					
				// boolean indicating if the key-value of the current element in the passed-in array
				// is greater than the key-value in the current element, previously inserted in the array to return
				locals.currentGreater = locals.currentValue gt locals.previousValue;
				// boolean indicating if the key-value in the array to return is greater
				locals.previousGreater = locals.previousValue gt locals.currentValue;					
					
				// boolean indicating if the current element in the array to sort must go 
				// BEFORE the previously inserted element in the array to return
				locals.currentFirst = 
					(locals.currentGreater AND (locals.currentKey.sortOrder eq "descending"))
					OR (locals.previousGreater AND (locals.currentKey.sortOrder eq "ascending"));
					
				// boolean indication if the current element in the array to sort must go 
				// AFTER the previously inserted element in the array to return
				locals.previousFirst = 
					(locals.previousGreater AND (locals.currentKey.sortOrder eq "descending"))
					OR (locals.currentGreater AND (locals.currentKey.sortOrder eq "ascending"));
					
					
				// if the element previously inserted in the array to return goes first
				if (locals.previousFirst)
					{
					// 	increment the insertPosition of the element in arrayToSort by one
					locals.insertPosition = locals.insertPosition + 1;
					// break out of the loop over sortkeys
					break;
					}
						
				// if the current element in the array to sort goes first 	
				if (locals.currentFirst)
					{
					// indicate that the loop over previously inserted elements in the array to return 
					// must be broken out of
					locals.doBreak = true;
					// break out of the loop over sortkeys
					break;
					}				
			} // end of loop over sortkeys
				
				
			// break out of the loop over previously inserted elements in the array to return,
			// when so indicated by the inner loop (over sortkeys)
			if (locals.doBreak)
				{
				break;
				}
					
		} //end of loop over elements that were previously put in the array to return
			
			
		// at this point locals.insertPosition holds the correct position, where the current 
		// element in the array to sort (argument) should be put
			
		// based on the value of the 'doDuplicate' argument, get either a deep copy or a reference of the 
		// data to insert in the array to return
		if (arguments[3]) {
			locals.insertData = duplicate(locals.elementData); 
		} else {
			locals.insertData = locals.elementData;
		}
						
		// if the insertposition is not greater than the current length of the array to return
		if (locals.insertPosition lt locals.i)
			{
			// do an insert into the correct position
			arrayInsertAt(locals.arrayToReturn,locals.insertPosition,locals.insertData);
			}
		else // if not ..
			{
			// do an append	
			arrayAppend(locals.arrayToReturn,locals.insertData);
			}			
	} // end of loop over elements in the array that was passed in
	return locals.arrayToReturn;		
}]]></starttext>
			               <endtext/>
			               <author>Martijn van der Woud</author>
			               <platforms/>
			               <created>09-27-2008</created>
			               <lastupdated>09-27-2008</lastupdated>
			          </snippet>
					
				 	<snippet id="1127" template="cfm">
			               <name>SQLBatcher</name>
			               <help><![CDATA[&lt;cfparam name=&quot;Form.BatchCode&quot; default=&quot;&quot;&gt;
&lt;cfparam name=&quot;Form.DSN&quot; default=&quot;&quot;&gt;
&lt;table&gt;&lt;tr&gt;&lt;td&gt;
&lt;cfoutput&gt;
&lt;form  method=&quot;post&quot; &gt;
DSN:&lt;input type=&quot;text&quot; name=&quot;DSN&quot; value=&quot;#FORM.DSN#&quot;&gt;
&lt;br&gt;SQL Batch:&lt;br&gt;
&lt;textarea cols=&quot;75&quot; rows=&quot;20&quot; name=&quot;BatchCode&quot;&gt;#FORM.BatchCode#&lt;/textarea&gt;
 &lt;br&gt;
&lt;input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/form&gt;
&lt;/cfoutput&gt;
&lt;/table&gt;
&lt;cfif isDefined(&quot;FORM.Submit&quot;)&gt;
&lt;cfdump var=&quot;#SQLBatcher(FORM.BatchCode,Form.DSN)#&quot;&gt; 
&lt;/cfif&gt;
&lt;p&gt;Copy SQL like the following into the textarea. Make sure the last GO is followed by a carriage return.
&lt;hr&gt;
&lt;pre&gt; 
if exists (select * from dbo.sysobjects where id = object_id(N&apos;[dbo].[myContacts]&apos;) and OBJECTPROPERTY(id, N&apos;IsUserTable&apos;) = 1)
drop table [dbo].[myContacts]
GO

CREATE TABLE [dbo].[myContacts] (
	[ContactID] [int] IDENTITY (1, 1) NOT NULL ,
	[ContactTypesID] [smallint] NOT NULL ,
	[StatusID] [smallint] NOT NULL ,
	[Name] [varchar] (50) NOT NULL
) ON [PRIMARY]
GO

if exists (select * from dbo.sysobjects where id = object_id(N&apos;[pr_myContacts_INS]&apos;) and OBJECTPROPERTY(id, N&apos;IsProcedure&apos;) = 1)
drop procedure [pr_myContacts_INS]
GO

  IF OBJECT_ID(&apos;dbo.pr_myContacts_INS&apos;) IS NOT NULL
        SELECT &apos;&lt;&lt;&lt; FAILED DROPPING PROCEDURE pr_myContacts_INS &gt;&gt;&gt;&apos;
    ELSE
        SELECT  &apos;&lt;&lt;&lt; DROPPED PROCEDURE dbo.pr_myContacts_INS &gt;&gt;&gt;&apos;
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE pr_myContacts_INS
(
     @ContactTypesID 	[smallint],
     @StatusID       	[smallint],
     @Name           	[varchar](50)
)
AS
BEGIN
BEGIN TRANSACTION
  INSERT INTO  dbo.myContacts 
	(
	 [ContactTypesID],
	 [StatusID],
	 [Name]
	)
  VALUES
	(
	 @ContactTypesID,
	 @StatusID,
	 @Name
	)
IF (@@error!=0)
  BEGIN
	RAISERROR  20000 &apos;pr_myContacts_INS: Cannot insert data into dbo.myContacts&apos;
	ROLLBACK TRAN
	RETURN(1)
  END

COMMIT TRAN
END

SELECT SCOPE_IDENTITY() AS ContactID

GO
IF OBJECT_ID(&apos;dbo.pr_myContacts_INS&apos;) IS NOT NULL
    SELECT &apos;&lt;&lt;&lt; CREATED PROCEDURE dbo.pr_myContacts_INS &gt;&gt;&gt;&apos;
ELSE
    SELECT &apos;&lt;&lt;&lt; FAILED CREATING PROCEDURE dbo.pr_myContacts_INS &gt;&gt;&gt;&apos;

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

&lt;/pre&gt;]]></help>
			               <description><![CDATA[Sends an SQL Batch script with 1 or more code blocks to a DSN. Reports results of each code block. Each code block seperated by a &quot;GO\r&quot; token is executed with a CFQuery.]]></description>
			               <starttext><![CDATA[<cffunction name="SQLBatcher" access="public" returntype="string" hint="Runs a set of queries based on sql string" output="false">
	<cfargument name="BatchCode" type="string" required="yes">
	<cfargument name="theDSN" type="string" required="yes">
	<cfargument name="sSep" type="string" required="no" default="GO">
		
	<cfscript> 
	var CleanedBatchCode = ReReplaceNoCase(BatchCode, "--.*?\r", "", "all");// clean sql comments
	var arBatchBlocks = ArrayNew(1); // index of each block and it's SQL string
	var separator = REFindNoCase("#arguments.sSep#\r",CleanedBatchCode,1,1); // looks for separators
	var pos = separator.pos[1]; // 0 or position of first separator
	var oldpos = 1;
	var Batch = 0; // count of separator blocks
	var Block = ""; // Code block of SQL 
	var sSQL = ""; // string to be returned
	
	// make sure arguments have length
	if ( (Len(Trim(theDSN)) EQ 0) OR (Len(Trim(CleanedBatchCode)) EQ 0) ) {
		sSQL = "<<<ERROR>>> Invalid parameters";
		return sSQL; // if there is an error stop batcher and return to caller 
	}
		
	// if no separator blocks, just query on the one block
	if(not pos) arBatchBlocks[1] = CleanedBatchCode;
	// loop around the separator blocks to get the code block for each separator
	while(pos gt 0) {
		block = mid(CleanedBatchCode,oldpos,pos-oldpos);
		// only add a block if there are characters in it. 
		if (ReFind("[[:alnum:]]",block,1,"False")) arrayAppend(arBatchBlocks,block);
		oldpos = pos + separator.len[1];
		separator = REFindNoCase("#arguments.sSep#\r|$",CleanedBatchCode,oldpos+1,1);
		pos = separator.pos[1];
	}		
	</cfscript>
		
	<!--- build return string --->
	<cfsavecontent variable="sSQL">
	
	<cfoutput>#Chr(60)#cftransaction#Chr(62)##Chr(10)##Chr(10)#</cfoutput>
		<cfloop index="Batch" from="1" to="#ArrayLen(arBatchBlocks)#" step="1">
			<cfset Block = arBatchBlocks[Batch]>
			<cfif Len(Trim(Block))><cfoutput>#Chr(60)#cfquery name="q#BATCH#" datasource="#Arguments.theDSN#"#Chr(62)##Chr(10)##Trim(PreserveSingleQuotes(Block))##Chr(10)##Chr(60)#/cfquery#Chr(62)##Chr(10)##Chr(10)#</cfoutput></cfif> 
		</cfloop>
	<cfoutput>#Chr(60)#/cftransaction#Chr(62)#</cfoutput>
	</cfsavecontent>
		
	<cfreturn sSQL>
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Joseph Flanigan</author>
			               <platforms/>
			               <created>11-09-2006</created>
			               <lastupdated>11-09-2006</lastupdated>
			          </snippet>
					
				 	<snippet id="1563" template="cfm">
			               <name>sqlXMLToCFXML</name>
			               <help><![CDATA[&lt;cfquery datasource=&quot;mydatasource&quot; name=&quot;xmlQuery&quot;&gt;
SELECT * FROM myTable FOR XML AUTO, ELEMENTS
&lt;/cfquery&gt;

&lt;cfset retVar = sqlXMLToCFXML(doc=&quot;myRoot&quot;,qry=xmlQuery)/&gt;]]></help>
			               <description><![CDATA[Takes a query and a name for a root element and creates a XML string (not xmlObject) that can then be used within ColdFusion.  This is conversion only for MSSQL generated XML.]]></description>
			               <starttext><![CDATA[<cffunction name="sqlXMLToCFXML" access="public" output="false" returntype="Any" hint="This function will take a multiple row query result and turn it into a CF XML var.">
      <cfargument name="doc" type="String" required="false" default="xml" />
      <cfargument name="qry" type="Query" required="true" />

      <cfset var x = "" />
      <cfset var y = "" />
      <cfset var retXML = "" />

      <cfset x = listFirst(arguments.qry.columnList)>
      <cfloop index="y" from="1" to="#arguments.qry.recordCount#">
         <cfset retXML = retXML & arguments.qry[x][y]>
      </cfloop>

      <cfset retXML = "<#arguments.doc#>" & retXML & "</#arguments.doc#>">

      <cfreturn retXML>
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Russel Brown</author>
			               <platforms/>
			               <created>04-09-2007</created>
			               <lastupdated>04-09-2007</lastupdated>
			          </snippet>
					
				 	<snippet id="684" template="cfm">
			               <name>struct</name>
			               <help><![CDATA[&lt;cfdump var=&quot;#Struct(foo=&apos;bar&apos;,bar=&apos;foo&apos;,quux=Struct(one=&apos;1&apos;,two=&apos;2&apos;,three=&apos;3&apos;))#&quot;&gt;]]></help>
			               <description><![CDATA[Now you can make simple or complex structures with a one-liner in CF, just like with built-in shorthand syntax in many other programming languages. You can create simple structures with ease, or nest Struct() functions to create complex, nested structures.]]></description>
			               <starttext><![CDATA[function struct() { return duplicate(arguments); }]]></starttext>
			               <endtext/>
			               <author>Erki Esken</author>
			               <platforms/>
			               <created>08-22-2007</created>
			               <lastupdated>08-22-2007</lastupdated>
			          </snippet>
					
				 	<snippet id="1716" template="cfm">
			               <name>structBlend</name>
			               <help><![CDATA[&lt;cfscript&gt;
	St1.Base = &quot;Struct One Keyval&quot;;
	St1.Nest.one = &quot;one&quot;;
	St1.Nest.two = &quot;two&quot;;
	St1.Nest.three = &quot;three&quot;;
	St2.Base = &quot;Struct 2 Keyval&quot;;
	St2.Nest.two = 2;
	St2.Nest.four = 4;
&lt;/cfscript&gt;	
	
&lt;cfoutput&gt;
	&lt;cfdump var=&quot;#St1#&quot; label=&quot;St1 Orginal&quot;&gt;
	&lt;cfdump var=&quot;#St2#&quot; label=&quot;St2&quot;&gt;
	Blend with overwrite=false: Return=&lt;cfoutput&gt;#structBlend(St1,St2,false)#&lt;/cfoutput&gt;
	&lt;cfdump var=&quot;#St1#&quot; label=&quot;St1 blended&quot;&gt;
	Blend with overwrite=true: Return=&lt;cfoutput&gt;#structBlend(St1,St2,true)#&lt;/cfoutput&gt;
	&lt;cfdump var=&quot;#St1#&quot; label=&quot;St1 blended, overwrite=true&quot;&gt;
&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Works much like Coldfusion's own structAppend.  The difference is it checks all nested structs and updates or adds children nested keys and their values to any depth.

Note that this UDF modified the structs. If you wish to keep the original data, make a backup using duplicate first.]]></description>
			               <starttext><![CDATA[function structBlend(Struct1,Struct2) {
	var i = 1;
	var OverwriteFlag = true;
	var StructKeyAr = listToArray(structKeyList(Struct2));
	var Success = true;
  	if ( arrayLen(arguments) gt 2 AND isBoolean(Arguments[3]) ) // Optional 3rd argument "OverwriteFlag"
  		OverwriteFlag = Arguments[3];
		try {
			for ( i=1; i lte structCount(Struct2); i=i+1 ) {
				if ( not isDefined('Struct1.#StructKeyAr[i]#') )  // If structkey doesn't exist in Struct1
					Struct1[StructKeyAr[i]] = Struct2[StructKeyAr[i]]; // Copy all as is.
				else if ( isStruct(struct2[StructKeyAr[i]]) )			// else if key is another struct
					Success = structBlend(Struct1[StructKeyAr[i]],Struct2[StructKeyAr[i]],OverwriteFlag);  // Recall function
				else if ( OverwriteFlag )	// if Overwrite
					Struct1[StructKeyAr[i]] = Struct2[StructKeyAr[i]];  // set Struct1 Key with Struct2 value.
			}
		}
		catch(any excpt) { Success = false; }
	return Success;
}]]></starttext>
			               <endtext/>
			               <author>Raymond Compton</author>
			               <platforms/>
			               <created>10-30-2008</created>
			               <lastupdated>10-30-2008</lastupdated>
			          </snippet>
					
				 	<snippet id="1136" template="cfm">
			               <name>structCompare</name>
			               <help><![CDATA[&lt;cfset LeftStruct = structNew()&gt;
&lt;cfset LeftStruct.Email = &quot;test@Test.com&quot;&gt;
&lt;cfset LeftStruct.Name = &quot;test&quot;&gt;
&lt;cfset LeftStruct.Struct = structNew()&gt;
&lt;cfset LeftStruct.Struct.keys = arrayNew(1)&gt;
&lt;cfset LeftStruct.Struct.keys[1] = &quot;1&quot;&gt;
&lt;cfset LeftStruct.Struct.keys[2] = &quot;2&quot;&gt;
&lt;cfset LeftStruct.Array = arrayNew(1)&gt;
&lt;cfset LeftStruct.Array[1] = structNew()&gt;
&lt;cfset LeftStruct.Array[1].id = &quot;1&quot;&gt;
&lt;cfset LeftStruct.Array[1].name = &quot;test&quot;&gt;
&lt;cfset LeftStruct.Array[2] = &quot;321&quot;&gt;

&lt;cfset RightStruct = structNew()&gt;
&lt;cfset RightStruct.Name = &quot;test&quot;&gt;
&lt;cfset RightStruct.Email = &quot;test@Test.com&quot;&gt;
&lt;cfset RightStruct.Struct = structNew()&gt;
&lt;cfset RightStruct.Struct.keys = arrayNew(1)&gt;
&lt;cfset RightStruct.Struct.keys[1] = &quot;1&quot;&gt;
&lt;cfset RightStruct.Struct.keys[2] = &quot;2&quot;&gt;
&lt;cfset RightStruct.Array = arrayNew(1)&gt;
&lt;cfset RightStruct.Array[1] = structNew()&gt;
&lt;cfset RightStruct.Array[1].id = &quot;1&quot;&gt;
&lt;cfset RightStruct.Array[1].name = &quot;test&quot;&gt;
&lt;cfset RightStruct.Array[2] = &quot;321&quot;&gt;

&lt;cfdump var=&quot;#LeftStruct#&quot;&gt;
&lt;cfdump var=&quot;#RightStruct#&quot;&gt;
&lt;cfoutput&gt;#structCompare(LeftStruct,RightStruct)#&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Recursive functions to compare structures and arrays. The root structure or array may contain nested structures and arrays.]]></description>
			               <starttext><![CDATA[function structCompare(LeftStruct,RightStruct) {
	var result = true;
	var LeftStructKeys = "";
	var RightStructKeys = "";
	var key = "";
	
	//Make sure both params are structures
	if (NOT (isStruct(LeftStruct) AND isStruct(RightStruct))) return false;

	//Make sure both structures have the same keys
	LeftStructKeys = ListSort(StructKeyList(LeftStruct),"TextNoCase","ASC");
	RightStructKeys = ListSort(StructKeyList(RightStruct),"TextNoCase","ASC");
	if(LeftStructKeys neq RightStructKeys) return false;	
	
	// Loop through the keys and compare them one at a time
	for (key in LeftStruct) {
		//Key is a structure, call structCompare()
		if (isStruct(LeftStruct[key])){
			result = structCompare(LeftStruct[key],RightStruct[key]);
			if (NOT result) return false;
		//Key is an array, call arrayCompare()
		} else if (isArray(LeftStruct[key])){
			result = arrayCompare(LeftStruct[key],RightStruct[key]);
			if (NOT result) return false;
		// A simple type comparison here
		} else {
			if(LeftStruct[key] IS NOT RightStruct[key]) return false;
		}
	}
	return true;
}]]></starttext>
			               <endtext/>
			               <author>Ja Carter</author>
			               <platforms/>
			               <created>10-14-2005</created>
			               <lastupdated>10-14-2005</lastupdated>
			          </snippet>
					
				 	<snippet id="1878" template="cfm">
			               <name>structGetKey</name>
			               <help><![CDATA[&lt;cfset myData = structNew()&gt;
&lt;cfset mydata.keyThatExists = 1&gt;

&lt;cfset result1 = structGetKey(myData, &quot;keyThatExists&quot;, &quot;not found&quot;) /&gt; &lt;!--- this returns the value of myData.keyThatExists ---&gt;
&lt;cfset result2 = structGetKey(myData, &quot;keyThatNOTExists&quot;, &quot;not found&quot;) /&gt; &lt;!--- this returns &quot;not found&quot; ---&gt;
&lt;cfoutput&gt;#result1#&lt;br /&gt;#result2#&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Returns a key value from the given struct, or a default value.]]></description>
			               <starttext><![CDATA[function structGetKey(theStruct, theKey, defaultVal){
	if (structKeyExists(arguments.theStruct, arguments.theKey)){
		return arguments.theStruct[arguments.theKey];
	}else{
		return arguments.defaultVal;
	}
}]]></starttext>
			               <endtext/>
			               <author>Adam Tuttle</author>
			               <platforms/>
			               <created>09-09-2008</created>
			               <lastupdated>09-09-2008</lastupdated>
			          </snippet>
					
				 	<snippet id="306" template="cfm">
			               <name>StructInvert</name>
			               <help><![CDATA[&lt;cfscript&gt;
	stOne=StructNew();
	stOne.firstvalue=&quot;cheese&quot;;
	stOne.secondvalue=&quot;soup&quot;;
	stOne.thirdvalue=&quot;donuts&quot;;
	stOneInverted=StructInvert(stOne);
&lt;/cfscript&gt;
stOne:
&lt;cfdump var=&quot;#stOne#&quot;&gt;
stOneInverted:
&lt;cfdump var=&quot;#stOneInverted#&quot;&gt;]]></help>
			               <description><![CDATA[Takes a struct of simple values and returns the  structure with the values and keys inverted.  The Values of the structure passed in will be the keys of the reutrned structure.  The Values of the Keys of the returned structure will be the corresponding keys of the passed in structure.]]></description>
			               <starttext><![CDATA[function StructInvert(st) {
		var stn=StructNew();
		var lKeys="";
		var nkey="";
		var i=1;
		var eflg=0;
		if (NOT IsStruct(st)) {
			eflg=1;
		}
		else {
			lKeys=StructKeyList(st);
			for (i=1; i LTE ListLen(lKeys); i=i+1) {
				nKey=listgetat(lkeys, i);
				if (IsSimpleValue(st[nKey]))
					stn[st[nKey]]=nKey;
				else {
					eflg=1;
					break;
				}
			}
		}
		if (eflg is 1) {
			writeoutput("Error in <Code>InvertStruct()</code>! Correct usage: InvertStruct(<I>Structure</I>) -- Returns a structure with the values and keys of <I>Structure</I> inverted when <i>Structure</i> is a structure of simple values.");
			return 0;
		}
		else {
			return stn;
		}
	}]]></starttext>
			               <endtext/>
			               <author>Craig Fisher</author>
			               <platforms/>
			               <created>11-13-2001</created>
			               <lastupdated>11-13-2001</lastupdated>
			          </snippet>
					
				 	<snippet id="1414" template="cfm">
			               <name>structMerge</name>
			               <help><![CDATA[&lt;cfset str1 = structNew() /&gt;
&lt;cfset str1.name = &quot;Marcos&quot; /&gt;
&lt;cfset str1.surname = &quot;Placona&quot; /&gt;
&lt;cfset str1.age = 22 /&gt;
&lt;cfset str1.wife = false /&gt;
&lt;cfset str1.dog = &quot;Toby&quot; /&gt;
&lt;cfset str1.company = &quot;Company 1&quot;&gt;

&lt;cfset str2 = structNew() /&gt;
&lt;cfset str2.name = &quot;John&quot; /&gt;
&lt;cfset str2.surname = &quot;Doe&quot; /&gt;
&lt;cfset str2.age = 55 /&gt;
&lt;cfset str2.children = 2 /&gt;
&lt;cfset str2.company = &quot;Company 2&quot;&gt;
&lt;cfset str2.website = &quot;www.mywebsite.co.uk&quot;&gt;

&lt;cfdump var=&quot;#structMerge(str1,str2)#&quot; label=&quot;structMerge&quot;&gt;
&lt;cfset structAppend(str1, str2)&gt;
&lt;cfdump var=&quot;#str1#&quot; label=&quot;structAppend&quot;&gt;]]></help>
			               <description><![CDATA[This UDF can be used when you want to merge two ColdFusion Structures on just one. Just pass the structures as arguments, and it returns a new structure with all the data amended or merged. Unlike structAppend, existing values in struct1 will be appended, not overwritten.]]></description>
			               <starttext><![CDATA[<cffunction name="structMerge" output="false">
	<cfargument name="struct1" type="struct" required="true">
	<cfargument name="struct2" type="struct" required="true">
	<cfset var ii = "" />
	
	<!--- Loop over the second structure passed --->
	<cfloop collection="#arguments.struct2#" item="ii">
		<cfif structKeyExists(struct1,ii)>
		<!--- In case it already exists, we just update it --->
			<cfset struct1[ii] = listAppend(struct1[ii], struct2[ii])>
		<cfelse>
		<!--- In all the other cases, just create a new key with the values or list of values --->
			<cfset struct1[ii] = struct2[ii] />
		</cfif>
	</cfloop>
	<cfreturn struct1 />
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Marcos Placona</author>
			               <platforms/>
			               <created>03-02-2006</created>
			               <lastupdated>03-02-2006</lastupdated>
			          </snippet>
					
				 	<snippet id="555" template="cfm">
			               <name>StructOfArraysToQuery</name>
			               <help><![CDATA[&lt;!--- create structure with column names as keys ---&gt;

   &lt;cfset stcolums = structNew()&gt;
   &lt;cfset stcolums.ContentID = ArrayNew(1)&gt;
   &lt;cfset stcolums.title = ArrayNew(1)&gt;
   &lt;cfset stcolums.created = ArrayNew(1)&gt;

   &lt;!--- add an array to each key column in the above structure  ---&gt;

   &lt;cfloop from=1 to=5 index=&quot;row&quot;&gt;
       &lt;cfset title = mid(&apos;abcdefghijklmonpqrstuvwxyz&apos;,RandRange(1,26),1)&gt;
       &lt;cfset tmp = arrayappend(stcolums.title, &quot;title &quot; &amp; row)&gt;
       &lt;cfset tmp = arrayappend(stcolums.created, DateFormat(DateAdd(&apos;d&apos;,RandRange(1,30),now()),&apos;dd mmm yyyy&apos;) )&gt;
       &lt;cfset tmp = arrayappend(stcolums.ContentID, createuuid() )&gt;
   &lt;/cfloop&gt;


   &lt;cfdump var=&quot;#stcolums#&quot;&gt; &lt;!--- output from above ---&gt;

   &lt;cfset myQuery = StructOfArraysToQuery(stcolums)&gt; &lt;!--- Pass structure to function ---&gt;

   &lt;cfdump var=&quot;#myQuery#&quot;&gt; &lt;!--- query result ---&gt;]]></help>
			               <description><![CDATA[Converts a structure of arrays to a CF Query.]]></description>
			               <starttext><![CDATA[function StructOfArraysToQuery(thestruct){
   var fieldlist = structkeylist(thestruct);
   var numrows   = arraylen( thestruct[listfirst(fieldlist)] );
   var thequery  = querynew(fieldlist);
   var fieldname="";
   var thevalue="";
   var row=1;
   var col=1;
   for(row=1; row lte numrows; row = row + 1)
   {
      queryaddrow(thequery);
      for(col=1; col lte listlen(fieldlist); col = col + 1)
      {
	 fieldname = listgetat(fieldlist,col);
	 thevalue  = thestruct[fieldname][row];
	 querysetcell(thequery,fieldname,thevalue);
      }
   }
return(thequery); }]]></starttext>
			               <endtext/>
			               <author>Casey Broich</author>
			               <platforms/>
			               <created>03-27-2002</created>
			               <lastupdated>03-27-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="940" template="cfm">
			               <name>StructOfArraysToStructOfStructs</name>
			               <help><![CDATA[&lt;cfscript&gt;
  mystruct = structnew();
  mystruct.name   = listtoarray(&quot;Joe,Bob,Jim&quot;);
  mystruct.weight = listtoarray(&quot;140,180,160&quot;);
  mystruct.Age    = listtoarray(&quot;25,40,33&quot;);
  mystruct.ID    = listtoarray(&quot;1,2,3&quot;);
&lt;/cfscript&gt;

Original:
&lt;cfdump var=&quot;#mystruct#&quot;&gt;

&lt;p&gt;
New Structure:
&lt;cfset new = StructOfArraysToStructOfStructs(mystruct,&quot;ID&quot;)&gt;
&lt;cfdump var=&quot;#new#&quot;&gt;]]></help>
			               <description><![CDATA[Converts a structure of arrays to a keyed structure of structs. In other words - taking a struct where each key is an array, it converts the struct into a struct of structs, where a particular key is used as the root key.]]></description>
			               <starttext><![CDATA[function StructOfArraysToStructOfStructs(struct,thekey){ 
   var i = ""; 
   var ii = ""; 
   var new = structNew();
   var value = ""; 
   var cols = "";

   if(arrayLen(arguments) GT 2) cols = listToArray(arguments[3]);
   else cols = structkeyarray(struct); 

   for(i = 1; i lte arraylen(struct[thekey]); i = i + 1){
      new[struct[thekey][i]] = structNew();
      for(ii = 1; ii lte arraylen(cols); ii = ii + 1){
      if(structKeyExists(struct,cols[ii])){
         value = struct[cols[ii]][i];
      }else{
         value = "";
      }
      new[struct[thekey][i]][cols[ii]] = value;
      }
   }
   return new;
}]]></starttext>
			               <endtext/>
			               <author>Casey Broich</author>
			               <platforms/>
			               <created>08-02-2003</created>
			               <lastupdated>08-02-2003</lastupdated>
			          </snippet>
					
				 	<snippet id="939" template="cfm">
			               <name>StructOfListsToArrayOfStructs</name>
			               <help><![CDATA[&lt;cfscript&gt;
  mystruct = structnew();
  mystruct.name = &quot;Joe,Bob,Jim&quot;;
  mystruct.weight = &quot;140,180,160&quot;;
  mystruct.Age = &quot;25,40,33&quot;;
&lt;/cfscript&gt;

&lt;cfset aos = StructOfListsToArrayOfStructs(mystruct)&gt;
&lt;cfdump var=&quot;#aos#&quot;&gt;

&lt;cfset aos = StructOfListsToArrayOfStructs(mystruct,&quot;,&quot;,&quot;weight,age&quot;)&gt;
&lt;cfdump var=&quot;#aos#&quot;&gt;]]></help>
			               <description><![CDATA[Converts a structure of Lists to an Array of structures.]]></description>
			               <starttext><![CDATA[function StructOfListsToArrayOfStructs(Struct){
   var delim = ",";
   var theArray = arraynew(1);
   var row = 1;
   var i = ""; 
   var cols = structkeyarray(Struct);
   var count = 0;
   var value = ""; 
   var strow = "";

   if(arrayLen(arguments) GT 1) delim = arguments[2];
   if(arrayLen(arguments) GT 2) cols = listToArray(arguments[3]);
   count = listlen(struct[cols[1]],delim);
   if(arraylen(cols) gt 0) {
      for(row=1; row LTE count; row = row + 1){
      strow = structnew();
      for(i=1; i lte arraylen(cols); i=i+1) {
         if(structKeyExists(Struct,cols[i])){
            if(listlen(Struct[cols[i]],delim) gte row){
               value = listgetat(Struct[cols[i]],row,delim);
            }else{
               value = "";
            }
         }else{
            value = "";
         }
         strow[cols[i]] = value;
      }
      arrayAppend(theArray,strow);
      }
   }
   return theArray;
}]]></starttext>
			               <endtext/>
			               <author>Casey Broich</author>
			               <platforms/>
			               <created>08-02-2003</created>
			               <lastupdated>08-02-2003</lastupdated>
			          </snippet>
					
				 	<snippet id="584" template="cfm">
			               <name>StructOfStructuresToQuery</name>
			               <help><![CDATA[&lt;cfset s = structNew()&gt;
&lt;cfset s.ray = structNew()&gt;
&lt;cfset s.ray.name = &quot;Raymond&quot;&gt;
&lt;cfset s.ray.age = 29&gt;
&lt;cfset s.foo = structNew()&gt;
&lt;cfset s.foo.name = &quot;Foo&quot;&gt;
&lt;cfset s.foo.age = 32&gt;
&lt;cfset s.jacob = structNew()&gt;
&lt;cfset s.jacob.name = &quot;Jacob&quot;&gt;
&lt;cfset s.jacob.age = 2&gt;
&lt;cfdump var=&quot;#structOfStructuresToQuery(s,&quot;username&quot;)#&quot;&gt;]]></help>
			               <description><![CDATA[Takes a structure of structures as created by the QueryToStructOfStructures UDF and converts it back to a ColdFusion Query. These two functions combined allow you to directly read and manipulate the rows of a query simply by knowing the value of the Primary Key. Some code based on Casey Broich's StructOfArraysToQuery.]]></description>
			               <starttext><![CDATA[function StructOfStructuresToQuery(theStruct, primaryKey){
	var primary_key_list   = StructKeyList(theStruct);
	var field_list         = StructKeyList(theStruct[ListFirst(primary_key_list)]);
	var num_rows           = ListLen(primary_key_list);
	var the_query          = QueryNew(primaryKey & "," & field_list);
	var primary_key_value  = "";
	var field_name         = "";
	var the_value          = "";
	var row                = 0;
	var col                = 0;

	for(row=1; row LTE num_rows; row=row+1) {
		QueryAddRow(the_query);
		primary_key_value = ListGetAt(primary_key_list, row);
		QuerySetCell(the_query, primaryKey, primary_key_value);
		for(col=1; col LTE ListLen(field_list); col=col+1) {
			field_name = ListGetAt(field_list, col);
			the_value  = theStruct[primary_key_value][field_name];
			QuerySetCell(the_query, field_name, the_value);
		}
	}

	return(the_query);
}]]></starttext>
			               <endtext/>
			               <author>Shawn Seley</author>
			               <platforms/>
			               <created>06-28-2002</created>
			               <lastupdated>06-28-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="561" template="cfm">
			               <name>StructRenameKey</name>
			               <help><![CDATA[&lt;cfscript&gt;
	foo = StructNew();
	foo[&quot;foo&quot;] = ArrayNew(1);
	foo[&quot;foo&quot;][1] = &quot;foo one&quot;;
	foo[&quot;foo&quot;][2] = &quot;foo two&quot;;
	foo[&quot;bar&quot;] = &quot;bar&quot;;
	foo[&quot;foobar&quot;] = &quot;foobar&quot;;
&lt;/cfscript&gt;

Original:
&lt;cfdump var=&quot;#foo#&quot;&gt;

&lt;br&gt;

Renamed (allowoverwrite = false):
&lt;cfset foo = StructRenameKey(foo, &quot;foo&quot;, &quot;foobar&quot;)&gt;
&lt;cfdump var=&quot;#foo#&quot;&gt;

&lt;br&gt;

Renamed (allowoverwrite = true):
&lt;cfset foo = StructRenameKey(foo, &quot;foo&quot;, &quot;foobar&quot;, true)&gt;
&lt;cfdump var=&quot;#foo#&quot;&gt;]]></help>
			               <description><![CDATA[Renames a specified key in the specified structure. You can optionally choose if overwriting existing key is allowed or not (by default overwriting is not allowed).]]></description>
			               <starttext><![CDATA[function StructRenameKey(struct, key, newkey) {
	// Allow overwriting existing keys or not?
	var AllowOverWrite = false;
	switch (ArrayLen(Arguments)) {
		case "4":
			AllowOverWrite = Arguments[4];
	}

	// No key or keys are the same? Return.
	if (NOT StructKeyExists(struct, key) OR CompareNoCase(key, newkey) EQ 0)
		return struct;

	if (NOT AllowOverWrite AND StructKeyExists(struct, newkey)) {
		// New key already exists and overwriting is off? Return.
		return struct;
	} else {
		// Duplicate and delete old. Return.
		struct[newkey] = Duplicate(struct[key]);
		StructDelete(struct, key);
		return struct;
	}
}]]></starttext>
			               <endtext/>
			               <author>Erki Esken</author>
			               <platforms/>
			               <created>06-26-2002</created>
			               <lastupdated>06-26-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="1460" template="cfm">
			               <name>structToList</name>
			               <help><![CDATA[&lt;!--- Create Struct ---&gt;
&lt;cfset user=structNew()&gt;
&lt;cfset user.firstname=&quot;John&quot;&gt;
&lt;cfset user.lastname=&quot;Smith&quot;&gt;
&lt;cfset user.age=35&gt;
&lt;cfdump var=&quot;#user#&quot; label=&quot;user&quot;&gt;

&lt;!--- Call Function ---&gt;
&lt;br&gt;
Using defult delimiter:
&lt;br&gt;
&lt;cfset myList = structToList(user)&gt;
&lt;cfdump var=&quot;#myList#&quot;&gt;
&lt;br&gt;&lt;br&gt;
Using custom delimiter:
&lt;br&gt;
&lt;cfset myList2 = structToList(user,&quot;@&quot;)&gt;
&lt;cfdump var=&quot;#myList2#&quot;&gt;]]></help>
			               <description><![CDATA[Converts a struct into a delimed key/value list. Defult delimiter is &quot;&amp;&quot; but any character can be used by passing it as a second argument.]]></description>
			               <starttext><![CDATA[function structToList(s) {
	var delim = "&";
	var i = 0;
	var newArray = structKeyArray(arguments.s);

	if (arrayLen(arguments) gt 1) delim = arguments[2];

	for(i=1;i lte structCount(arguments.s);i=i+1) newArray[i] = newArray[i] & "=" & arguments.s[newArray[i]];

	return arraytoList(newArray,delim);
}]]></starttext>
			               <endtext/>
			               <author>Greg Nettles</author>
			               <platforms/>
			               <created>07-25-2006</created>
			               <lastupdated>07-25-2006</lastupdated>
			          </snippet>
					
				 	<snippet id="1836" template="cfm">
			               <name>structToQueryRow</name>
			               <help><![CDATA[&lt;cfset qry = queryNew(&quot;my,column,names&quot;) /&gt;

&lt;cfset s = structNew() /&gt;
&lt;cfset s.my = &quot;foo&quot; /&gt;
&lt;cfset s.column = &quot;bar&quot; /&gt;
&lt;cfset s.names = &quot;goo&quot; /&gt;

&lt;cfset q = structToQueryRow(qry ,s) /&gt;
&lt;cfdump var=&quot;#q#&quot;&gt;]]></help>
			               <description><![CDATA[Adds a row to a query object and populates it with the values of a structure.]]></description>
			               <starttext><![CDATA[<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>]]></starttext>
			               <endtext/>
			               <author>Brian Rinaldi</author>
			               <platforms/>
			               <created>04-25-2008</created>
			               <lastupdated>04-25-2008</lastupdated>
			          </snippet>
					
				 	<snippet id="428" template="cfm">
			               <name>StructToQueryString</name>
			               <help><![CDATA[&lt;cfscript&gt;
   test = StructNew();
   test.foo = &quot;bar&quot;;
   test.another = &quot;foobar&quot;;
   normalQueryString = StructToQueryString(test);
   sesQueryString = StructToQueryString(test, &quot;/&quot;, &quot;/&quot;);
&lt;/cfscript&gt;

&lt;cfdump var=&quot;#normalQueryString#&quot;&gt;
&lt;P&gt;
&lt;cfdump var=&quot;#sesQueryString#&quot;&gt;]]></help>
			               <description><![CDATA[Converts a structure to a URL query string. Query string delimiters can be changed: second function argument is the key/value delimiter (default is =) and third argument is the other delimiter (default is &).]]></description>
			               <starttext><![CDATA[function StructToQueryString(struct) {
  var qstr = "";
  var delim1 = "=";
  var delim2 = "&";

  switch (ArrayLen(Arguments)) {
    case "3":
      delim2 = Arguments[3];
    case "2":
      delim1 = Arguments[2];
  }
	
  for (key in struct) {
    qstr = ListAppend(qstr, URLEncodedFormat(LCase(key)) & delim1 & URLEncodedFormat(struct[key]), delim2);
  }
  return qstr;
}]]></starttext>
			               <endtext/>
			               <author>Erki Esken</author>
			               <platforms/>
			               <created>12-17-2001</created>
			               <lastupdated>12-17-2001</lastupdated>
			          </snippet>
					
				 	<snippet id="1351" template="cfm">
			               <name>structUpdateVals</name>
			               <help><![CDATA[&lt;cfset struct1 = structNew() /&gt;
&lt;cfset struct1[&apos;FNAME&apos;] = &quot;John&quot; /&gt;
&lt;cfset struct1[&apos;LNAME&apos;] = &quot;Smith&quot; /&gt;
&lt;cfset struct1[&apos;PHONE&apos;] = &quot;305.555.5555&quot; /&gt;

&lt;cfset struct2 = structNew() /&gt;
&lt;cfset struct2[&apos;FNAME&apos;] = &quot;Bill&quot; /&gt;
&lt;cfset struct2[&apos;LNAME&apos;] = &quot;Gates&quot; /&gt;

&lt;cfdump var=&quot;#struct1#&quot; label=&quot;Struct 1&quot;&gt;
&lt;cfdump var=&quot;#struct2#&quot; label=&quot;Struct 2&quot;&gt;

&lt;cfset structUpdateVals(struct1, struct2) /&gt;
&lt;cfdump var=&quot;#struct1#&quot; label=&quot;Updated Struct 1&quot;&gt;]]></help>
			               <description><![CDATA[This function will find the matching keys between two structures and update structure1 values with structure2 values. If structure2 has more keys than structure1 the keys will not be added.]]></description>
			               <starttext><![CDATA[<cffunction name="structUpdateVals" returntype="struct" output="false">
	<cfargument name="struct1" required="yes" type="struct" />
	<cfargument name="struct2" required="yes" type="struct"  />

	<cfloop collection="#struct2#" item="key">
		<cfif structKeyExists(struct1, key)>
			<cfset structUpdate(struct1, key, struct2[key]) />
	</cfif>
	</cfloop>		
	<cfreturn struct1 />
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Jorge Loyo</author>
			               <platforms/>
			               <created>12-22-2005</created>
			               <lastupdated>12-22-2005</lastupdated>
			          </snippet>
					
				 	<snippet id="1512" template="cfm">
			               <name>structValueList</name>
			               <help><![CDATA[&lt;cfoutput&gt;#structValueList(CGI)#&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Converts a structure into a key/value pair list. Ignores complex values (nested structures, arrays, etc.).]]></description>
			               <starttext><![CDATA[function structValueList(struct) {
	var delimiter = ",";
	var element = 0;
	var kvName = "";
	var kvValue = "";
	var returnList = "";
		
	if(arrayLen(arguments) gt 1) delimiter = arguments[2];
		
	if (isStruct(struct)) {
		for (; element lt listLen(structKeyList(struct, delimiter)) ; element=element+1) {
			kvName = listGetAt(structKeyList(struct, delimiter), element+1, delimiter);
			kvValue = "";
			if(isSimpleValue(struct[kvName])) kvValue = struct[kvName];
			returnList = listAppend(returnList, kvName & iif(len(trim(kvValue)) gt 0, de("=" & kvValue), de("")));
		}
	}
	
	return returnList;
}]]></starttext>
			               <endtext/>
			               <author>Kit Brandner</author>
			               <platforms/>
			               <created>11-06-2006</created>
			               <lastupdated>11-06-2006</lastupdated>
			          </snippet>
					
				 	<snippet id="859" template="cfm">
			               <name>structWrite</name>
			               <help><![CDATA[&lt;cfset fishStock = structNew()&gt;
&lt;cfdump var=&quot;#fishStock#&quot; /&gt;

&lt;cfset result = structWrite( fishStock, &quot;trout&quot;, &quot;100&quot;, &quot;false&quot; )&gt;
&lt;cfdump var=&quot;#result#&quot; /&gt;
&lt;cfdump var=&quot;#fishStock#&quot; /&gt;
&lt;hr /&gt;
&lt;cfset result = structWrite( fishStock, &quot;trout&quot;, &quot;50&quot;, &quot;false&quot; )&gt;
&lt;cfdump var=&quot;#result#&quot; /&gt;
&lt;cfdump var=&quot;#fishStock#&quot; /&gt;
&lt;hr /&gt;
&lt;cfset result = structWrite( fishStock, &quot;trout&quot;, &quot;0&quot;, &quot;true&quot; )&gt;
&lt;cfdump var=&quot;#result#&quot; /&gt;
&lt;cfdump var=&quot;#fishStock#&quot; /&gt;
&lt;hr /&gt;
&lt;cfset result = structWrite( fishStock, &quot;salmon&quot;, &quot;10&quot;, &quot;true&quot; )&gt;
&lt;cfdump var=&quot;#result#&quot; /&gt;
&lt;cfdump var=&quot;#fishStock#&quot; /&gt;]]></help>
			               <description><![CDATA[A replacement for structInsert() function. Works around the structInsert() feature of thowing an error if you are writing to a struct, the key exists, and you don't want to overwrite.]]></description>
			               <starttext><![CDATA[function structWrite(structure, key, value) {
	var valueWritten = false;
	var allowOverwrite = false;
		
	if(arrayLen(arguments) gte 4) allowOverwrite = arguments[4];

	if ( structKeyExists( structure, key ) IMP allowOverwrite ) {
		valueWritten = structInsert( structure, key, value, allowOverwrite );
	}
	return yesNoFormat(valueWritten);
}]]></starttext>
			               <endtext/>
			               <author>Anthony Cooper</author>
			               <platforms/>
			               <created>05-09-2003</created>
			               <lastupdated>05-09-2003</lastupdated>
			          </snippet>
					
				 	<snippet id="2009" template="cfm">
			               <name>toXML</name>
			               <help><![CDATA[&lt;cfscript&gt;
	t = structNew();
	t.logical = &quot;true&quot;;
	t.data = structNew();
	t.data.item = 1;
	t.data.another_item = 2;
	t.data.string = &quot;hello&quot;;
	t.array_items = arrayNew(1);
	arrayAppend(t.array_items, &quot;error 1&quot;);
	arrayAppend(t.array_items, &quot;error 2&quot;);
	arrayAppend(t.array_items, &quot;error 3&quot;);

	x = toXML(t, &quot;root&quot;);
&lt;/cfscript&gt;
&lt;cfoutput&gt;#HTMLeditFormat(x)#&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Need to convert a structure or array to XML and have it multi-level? This one recursive function will convert these items into a XML string (without the XML header), beginning with one element and walking through all keys and arrays.

Very simple and very fast - for arrays it assumes that the array name is plural, and children will be the non-plural version (will be the same if not plural) - ending with an &quot;S&quot;, not intelligent, i.e. won't convert &quot;spies&quot; to &quot;spy&quot;.]]></description>
			               <starttext><![CDATA[<cffunction name="toXML" output="false" returntype="String">
	<cfargument name="input" type="Any" required="true" />
	<cfargument name="element" type="string" required="true" />
	<cfscript>
		var i = 0;
		var s = "";
		var s1 = "";
		s1 = arguments.element;
		if (right(s1, 1) eq "s") {
			s1 = left(s1, len(s1)-1);
		}
		
		s = s & "<#lcase(arguments.element)#>";
		if (isArray(arguments.input)) {
			for (i = 1; i lte arrayLen(arguments.input); i = i + 1) {
				if (isSimpleValue(arguments.input[i])) {
					s = s & "<#lcase(s1)#>" & arguments.input[i] & "</#lcase(s1)#>";
				} else {
					s = s & toXML(arguments.input[i], s1);
				}
			}
		} else if (isStruct(arguments.input)) {
			for (i in arguments.input) {
				if (isSimpleValue(arguments.input[i])) {
					s = s & "<#lcase(i)#>" & arguments.input[i] & "</#lcase(i)#>";
				} else {
					s = s & toXML(arguments.input[i], i);
				}
			}
		} else {
			s = s & XMLformat(arguments.input);
		}
		s = s & "</#lcase(arguments.element)#>";
	</cfscript>
	<cfreturn s />
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Phil Arnold</author>
			               <platforms/>
			               <created>09-09-2009</created>
			               <lastupdated>09-09-2009</lastupdated>
			          </snippet>
					
				 	<snippet id="537" template="cfm">
			               <name>TranslateMacromediaResourceFeed</name>
			               <help><![CDATA[&lt;cfhttp url=&quot;http://www.macromedia.com/desdev/resources/macromedia_resources.xml&quot; method=&quot;GET&quot;&gt;
&lt;/cfhttp&gt;

&lt;cfset variables.ResourceFeed = TranslateMacromediaResourceFeed(cfhttp.FileContent)&gt;

&lt;cfdump var=&quot;#variables.ResourceFeed#&quot;&gt;]]></help>
			               <description><![CDATA[This Page contains a function to take Macromedia's XML Resource feed and put it into ColdFusion variables.

It will turn it into an array of structures.  The structure will be in this format:

structure.Type		( Type )
structure.Title		( The title )
structure.Author	( The author )
structure.URL 		( The URL )
structure.Products	( An Array of Products ) 

Data Type Definition: 
http://www.macromedia.com/desdev/resources/macromedia_resources.dtd

XML Feed: 
http://www.macromedia.com/desdev/resources/macromedia_resources.xml]]></description>
			               <starttext><![CDATA[function TranslateMacromediaResourceFeed(S) {

	// the current token we are looking at 
	var Token = GetToken(S,1,"<>");
	
	// LoopControl needs to be initialized
	var LoopControl = 1;
	
	// Initialize the Current Query Row 
	var RowNumber = 1;

	// the number of the next token we are looking at 
	var NextToken = 2;
	
	var ResourceStruct = StructNew();

	// Initialize Return Query 
	var ResultQuery = QueryNew("Type, Title, Author, URL, ProductName");
	
	// loop until we are out of tokens 
	while(Token is not "/macromedia_resources"){
	
		switch(Left(Token,7)){

			case "resourc":{
				// if we are getting a resource token, we want to:
				// create a new blank structure 
				// and define the structure's type
				
				// define new structure
				ResourceStruct = StructNew();
				
				// add the type of entry to the structure
				StructInsert(ResourceStruct, "Type", GetToken(Token,  2, """"));

				// increment next token
				NextToken = NextToken + 1;
				break;
			} // end resource case			
			
			case "/resour":{
				// if we are getting a /resource token, we want to:
				// Create a new row in the query for each product 
				// Assuming the structure isn't empty 
				
				// copy existing structure into result array
				if (not StructIsEmpty(ResourceStruct)){
					
					for (LoopControl = 1 ; 
						 LoopControl LTE ArrayLen(ResourceStruct.Products) ; 
						 LoopControl = LoopControl+1){
						
						// add a new row to the query 
						RowNumber = QueryAddRow(ResultQuery);
						
						// populate Query 
						QuerySetCell(ResultQuery, "Type", ResourceStruct.Type, RowNumber);
						QuerySetCell(ResultQuery, "Title", ResourceStruct.Title, RowNumber);
						QuerySetCell(ResultQuery, "Author", ResourceStruct.Author, RowNumber);
						QuerySetCell(ResultQuery, "URL", ResourceStruct.URL, RowNumber);
						QuerySetCell(ResultQuery, "ProductName", ResourceStruct.Products[LoopControl], RowNumber);

					}
					
				}
				
				// increment next token
				NextToken = NextToken + 1;
				break;
			} // end resource case			


			case "title":{
				// if we are getting the title token, then we want to:
				// add the next token to our structure, because that will be our title text
				// increment the 'nexttoken' variable two increments past the end title token

				// add the title to the structure
				StructInsert(ResourceStruct, "Title", GetToken(S,  NextToken+1, "<>"));
				
				// increment next token
				NextToken = NextToken + 2;

				break;
			} // end title case

			case "author":{
				// if we are getting the author token, then we want to:
				// add the next token to our structure, because that will be our author text
				// increment the 'nexttoken' variable two increments past the end Author token

				// add the title to the structure
				StructInsert(ResourceStruct, "Author", GetToken(S,  NextToken+1, "<>"));
				
				// increment next token
				NextToken = NextToken + 2;
				
				break;
			} // end author case 


			case "url":{
				// if we are getting the url token, then we want to:
				// add the next token to our structure, because that will be our url text
				// increment the 'nexttoken' variable two increments past the end url token

				// add the title to the structure
				StructInsert(ResourceStruct, "URL", GetToken(S,  NextToken+1, "<>"));
				
				// increment next token
				NextToken = NextToken + 2;
				
				break;
			} // end url case 
			
			case "product":{ 
				// if the case is a product, we want to:
				// Pick out the name from the token and add it to our product array
				// increment the nexttoken variable once
				
				// if product array doesn't exist, create it
				if (not IsDefined("ResourceStruct.Products")){
					StructInsert(ResourceStruct, "Products", ArrayNew(1));
				}
				
				// add product name to array 
				ArrayAppend(ResourceStruct.Products,GetToken(Token,  2, """"));
				
				// increment next token
				NextToken = NextToken + 1;
				
				break;
			} // end product case 

			
//				case "/title","/author","/url"
//				these cases or anything else not defined, we just ignore, but we still wanna get the 
// 			next token
			default: {
				Token = GetToken(S,NextToken,"<>");
				NextToken = NextToken + 1;
				break;
			} // end default case 
		} // end switch
		Token = GetToken(S,NextToken,"<>");
	} // end while

	return (ResultQuery);
}]]></starttext>
			               <endtext/>
			               <author>Jeffry Houser</author>
			               <platforms/>
			               <created>08-12-2002</created>
			               <lastupdated>08-12-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="1064" template="cfm">
			               <name>trimQuery</name>
			               <help><![CDATA[&lt;cfset qryFoo = queryNew(&apos;FirstName,LastName&apos;)&gt;
&lt;cfset queryAddRow(qryFoo, 3)&gt;
&lt;cfset querySetCell(qryFoo, &apos;FirstName&apos;, &apos;  Ben   &apos;, 1)&gt;
&lt;cfset querySetCell(qryFoo, &apos;LastName&apos;, &apos;  Forta        &apos;, 1)&gt;
&lt;cfset querySetCell(qryFoo, &apos;FirstName&apos;, &apos;Massimo   &apos;, 2)&gt;
&lt;cfset querySetCell(qryFoo, &apos;LastName&apos;, &apos;Foti       &apos;, 2)&gt;
&lt;cfset querySetCell(qryFoo, &apos;FirstName&apos;, &apos;    Ju&apos;, 3)&gt;
&lt;cfset querySetCell(qryFoo, &apos;LastName&apos;, &apos;Ratto       &apos;, 3)&gt;
&lt;pre&gt;
&lt;strong&gt;Not Trimmed&lt;/strong&gt;:
&lt;cfoutput query=&quot;qryFoo&quot;&gt;#qryFoo.FirstName# #qryFoo.LastName#&lt;br&gt;&lt;/cfoutput&gt;
&lt;cfset qryFoo=TrimQuery(qryFoo)&gt;
&lt;strong&gt;Trimmed&lt;/strong&gt;:
&lt;cfoutput query=&quot;qryFoo&quot;&gt;#qryFoo.FirstName# #qryFoo.LastName#&lt;br&gt;&lt;/cfoutput&gt;
&lt;/pre&gt;]]></help>
			               <description><![CDATA[Trims spaces from all recordset in a query. Useful for databases that retrieve varchars values with extra spaces (as SQL Server). 

Note - it is preferable to have the database do your trim for you. SQL Server for example can easily trim the data returned.]]></description>
			               <starttext><![CDATA[function trimQuery(qry) {
	var col="";
	var i=1;
	var j=1;
	for(;i lte qry.recordCount;i=i+1) {
		for(j=1;j lte listLen(qry.columnList);j=j+1) {
			col=listGetAt(qry.columnList,j);
			querySetCell(qry,col,trim(qry[col][i]),i);
		}
	}
	return qry;
}]]></starttext>
			               <endtext/>
			               <author>Giampaolo Bellavite</author>
			               <platforms/>
			               <created>02-26-2004</created>
			               <lastupdated>02-26-2004</lastupdated>
			          </snippet>
					
				 	<snippet id="677" template="cfm">
			               <name>TrimStruct</name>
			               <help><![CDATA[&lt;cfscript&gt;
st = structNew();
st.apple = &quot;  Ray  &quot;;
st.banana = &quot;Camden&quot;;
st.leaveme = &quot;           Foo &quot;;
&lt;/cfscript&gt;
&lt;!--- use pass by rev ---&gt;
&lt;cfset trimStruct(st,&quot;leaveme&quot;)&gt;
&lt;cfoutput&gt;
&lt;pre&gt;
&lt;cfloop item=&quot;key&quot; collection=&quot;#st#&quot;&gt;
st.#key# = #st[key]#
&lt;/cfloop&gt;
&lt;/pre&gt;
&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Allows for trimming of all fields in a structure. Useful for automatically trimming the Form scope for example.]]></description>
			               <starttext><![CDATA[function TrimStruct(st) {
	var excludeList = "";
	var key = "";

	if(arrayLen(arguments) gte 2) excludeList = arguments[2];
	for(key in st) {
		if(not listFindNoCase(excludeList,key) and isSimpleValue(st[key])) st[key] = trim(st[key]);
	}
	return st;
}]]></starttext>
			               <endtext/>
			               <author>Mike Gillespie</author>
			               <platforms/>
			               <created>07-11-2002</created>
			               <lastupdated>07-11-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="689" template="cfm">
			               <name>TypeOf</name>
			               <help><![CDATA[&lt;cfscript&gt;
   function foo() { return; }
   foo2 = createDate( 2002, 4, 1 );
   foo3 = Tobinary( ToBase64( &quot;foo&quot; ) );
&lt;/cfscript&gt;
&lt;cfoutput&gt;
   #typeof( foo )#&lt;br&gt;
   #typeof( foo2 )#&lt;br&gt;
   #typeof( foo3 )#&lt;br&gt;
&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Enhanced typeof() function with added checking for binary, custom function, and date values.]]></description>
			               <starttext><![CDATA[function TypeOf(x) {
   if(isArray(x)) return "array";
   if(isStruct(x)) return "structure";
   if(isQuery(x)) return "query";
   if(isSimpleValue(x) and isWddx(x)) return "wddx";
   if(isBinary(x)) return "binary";
   if(isCustomFunction(x)) return "custom function";
   if(isDate(x)) return "date";
   if(isNumeric(x)) return "numeric";
   if(isBoolean(x)) return "boolean";
   if( listFindNoCase( structKeyList( GetFunctionList() ), "isXMLDoc" ) AND
isXMLDoc(x)) return "xml";
   if(isSimpleValue(x)) return "string";
   return "unknown";  
}]]></starttext>
			               <endtext/>
			               <author>Jordan Clark</author>
			               <platforms/>
			               <created>08-16-2002</created>
			               <lastupdated>08-16-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="1573" template="cfm">
			               <name>UniqueValueList</name>
			               <help><![CDATA[--Not Case sensitive
#uniqueValueList(queryName, &quot;queryColumn&quot;)#

-- Case Sensitive
#uniqueValueList(queryName, &quot;queryColumn&quot;, 1)#]]></help>
			               <description><![CDATA[Returns a list of unique values from a query column with the option of case sensitive or not.]]></description>
			               <starttext><![CDATA[function uniqueValueList(queryName, columnName) {
	var cs = 0; 
	var curRow = 1;
	var uniqueList = "";  
	
	if(arrayLen(arguments) GTE 3 AND isBoolean(arguments[3])) cs = arguments[3]; 
	
	for(; curRow LTE queryName.recordCount; curRow = curRow +1){
		if((not cs AND not listFindNoCase(uniqueList, trim(queryName[columnName][curRow]))) OR (cs AND not listFind(uniqueList, trim(queryName[columnName][curRow])))){
			uniqueList = ListAppend(uniqueList, trim(queryName[columnName][curRow]));
		}
	}
	return uniqueList; 
}]]></starttext>
			               <endtext/>
			               <author>Nick Giovanni</author>
			               <platforms/>
			               <created>03-27-2007</created>
			               <lastupdated>03-27-2007</lastupdated>
			          </snippet>
					
				 	<snippet id="1056" template="cfm">
			               <name>validateXMLFile</name>
			               <help><![CDATA[Please see the example at: http://www.massimocorner.com/demos/validateXMLFile.zip]]></help>
			               <description><![CDATA[Validate an XML file against a DTD.]]></description>
			               <starttext><![CDATA[<cffunction name="validateXMLFile" output="false" returntype="boolean" hint="Validate an XML file against a DTD">
	<cfargument name="xmlUrl" type="string" required="true" hint="XML document url">
	<cfargument name="throwerror" type="boolean" required="false" default="false" hint="Throw an exception if the document isn't valid">
	<cfargument name="fileLockTimeout" type="numeric" required="false" default="5" hint="Specifies the maximum amount of time, to wait to obtain a lock on the file">
	<cfset var isValid=true>
	<cfset var saxFactory="">
	<cfset var xmlReader="">
	<cfset var eHandler="">
	<!--- Better to be sure the file exist --->
	<cfif NOT FileExists(arguments.xmlUrl)>
		<cfthrow message="validateXMLFile: #arguments.xmlUrl# doesn't exist" type="validateXMLFile">
	</cfif>
	<cftry>
		<cfscript>
		//Call the SAX parser factory
		saxFactory = CreateObject("java","javax.xml.parsers.SAXParserFactory").newInstance();
		//Creates a SAX parser and get the XML Reader
		xmlReader = saxFactory.newSAXParser().getXMLReader();
		//Turn on validation
		xmlReader.setFeature("http://xml.org/sax/features/validation",true);
		//Create an error handler
		eHandler = CreateObject("java","org.apache.xml.utils.DefaultErrorHandler").init();
		//Assign the error handler
		xmlReader.setErrorHandler(eHandler);
		</cfscript>
		<!--- Throw an exception in case any Java initialization failed --->
		<cfcatch type="Object">
			<cfthrow message="validateXMLFile: failed to initialize Java objects" type="validateXMLFile">
		</cfcatch>
	</cftry>
	<cftry>
		<!--- 
		Since we are reading the file, we better lock it.
		Safer thing to do is to use the file's url as name for the lock
		 --->
		<cflock name="#arguments.xmlUrl#" timeout="#arguments.fileLockTimeout#" throwontimeout="yes" type="readonly">
			<cfset xmlReader.parse(arguments.xmlUrl)>
		</cflock>
		<!--- Catch SAX's exception and set the flag --->
	<cfcatch type="org.xml.sax.SAXParseException">
		<!--- The SAX parser failed to validate the document --->
		<cfset isValid=false>
		<cfif arguments.throwerror>
			<!--- Throw an exception with the error message if required	--->
			<cfthrow message="validateXMLFile: Failed to validate the document, #cfcatch.Message#" type="validateXMLFile">
		</cfif>
	</cfcatch>
	</cftry>
	<!--- Return the boolean --->
	<cfreturn isValid>
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Massimo Foti</author>
			               <platforms/>
			               <created>02-18-2004</created>
			               <lastupdated>02-18-2004</lastupdated>
			          </snippet>
					
				 	<snippet id="1055" template="cfm">
			               <name>validateXMLString</name>
			               <help><![CDATA[Please see the examples here: http://www.massimocorner.com/demos/validateXMLString.zip]]></help>
			               <description><![CDATA[Validate a formatted XML string against a DTD.]]></description>
			               <starttext><![CDATA[<cffunction name="validateXMLString" output="false" returntype="boolean" hint="Validate a formatted XML string against a DTD">
	<cfargument name="xmlString" type="string" required="true" hint="XML document as string">
	<cfargument name="throwerror" type="boolean" required="false" default="false" hint="Throw an exception if the document isn't valid">
	<cfargument name="baseUrl" type="string" required="false" default="" hint="Needed to resolve url found in the DOCTYPE declaration and external entity references. Format must be: http://www.mydomain.com/xmldirectoty/">
	<cfset var isValid=true>
	<cfset var jStringReader="">
	<cfset var xmlInputSource="">
	<cfset var saxFactory="">
	<cfset var xmlReader="">
	<cfset var eHandler="">
	<cftry>
		<cfscript>
		//Use Java string reader to read the CFML variable
		jStringReader = CreateObject("java","java.io.StringReader").init(arguments.xmlString);
		//Turn the string into a SAX input source 
		xmlInputSource = CreateObject("java","org.xml.sax.InputSource").init(jStringReader);
		//Call the SAX parser factory
		saxFactory = CreateObject("java","javax.xml.parsers.SAXParserFactory").newInstance();
		//Creates a SAX parser and get the XML Reader
		xmlReader = saxFactory.newSAXParser().getXMLReader();
		//Turn on validation
		xmlReader.setFeature("http://xml.org/sax/features/validation",true);
		//Add a system id if required
		if(IsDefined("arguments.baseUrl")){
			xmlInputSource.setSystemId(arguments.baseUrl);
		}
		//Create an error handler
		eHandler = CreateObject("java","org.apache.xml.utils.DefaultErrorHandler").init();
		//Assign the error handler
		xmlReader.setErrorHandler(eHandler);
		</cfscript>
		<!--- Throw an exception in case any Java initialization failed --->
		<cfcatch type="Object">
			<cfthrow message="validateXMLString: failed to initialize Java objects" type="validateXMLString">
		</cfcatch>
	</cftry>
	<cftry>
		<cfset xmlReader.parse(xmlInputSource)>
		<!--- Catch SAX's exception and set the flag --->
	<cfcatch type="org.xml.sax.SAXParseException">
		<!--- The SAX parser failed to validate the document --->
		<cfset isValid=false>
		<cfif arguments.throwerror>
			<!--- Throw an exception with the error message if required	--->
			<cfthrow message="validateXMLString: Failed to validate the document, #cfcatch.Message#" type="validateXMLString">
		</cfif>
	</cfcatch>
	</cftry>
	<!--- Return the boolean --->
	<cfreturn isValid>
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Massimo Foti</author>
			               <platforms/>
			               <created>02-18-2004</created>
			               <lastupdated>02-18-2004</lastupdated>
			          </snippet>
					
				 	<snippet id="713" template="cfm">
			               <name>VarToScript</name>
			               <help><![CDATA[&lt;cfscript&gt;
/* &quot;house&quot; is a complex variable that takes a while to build from scratch, but for this demo i&apos;ll hard code it.
N.B. CFMX can handle query cells with complex variables, but CF5 can&apos;t, hence the check on the variables scope... */
house=StructNew();
tmpQuery=QueryNew(&apos;name,pictures&apos;);
QueryAddRow(tmpQuery,1);
QuerySetCell(tmpQuery, &apos;name&apos;, &apos;diningroom&apos;, 1);
tmpArray=ArrayNew(2);
tmpArray[1][1]=&apos;Fish on table&apos;;
tmpArray[1][2]=&apos;still life&apos;;
if (IsDefined(&apos;variables&apos;) AND IsStruct(variables)){
 QuerySetCell(tmpQuery, &apos;pictures&apos;, tmpArray, 1);
} else {
 QuerySetCell(tmpQuery, &apos;pictures&apos;, ArrayToList(tmpArray[1]), 1);
}
house.rooms=tmpQuery;
&lt;/cfscript&gt;

&lt;!--- convert the CF variable into a string of CFSCRIPT ---&gt;
&lt;cfset stufftosave = varToScript(house,&quot;cachedhouse&quot;)&gt;

&lt;!--- save the generated script to file, along with &lt;script&gt; tags ---&gt;
&lt;cfset filename = CreateUUID()&gt;
&lt;cfset filepath = GetDirectoryFromPath(GetCurrentTemplatePath()) &amp; &apos;/&apos; &amp; filename&gt;
&lt;cffile action=&quot;WRITE&quot;
  file=&quot;#filepath#&quot;
  output=&quot;&lt;cfscript&gt;#stufftosave#&lt;/cfscript&gt;&quot;&gt;

&lt;!--- include the cached file to recreate the object ---&gt;
&lt;cfinclude template=&quot;#filename#&quot;&gt;

&lt;!--- this delete is just here in the demo.... ---&gt;
&lt;cffile action=&quot;DELETE&quot;
  file=&quot;#filepath#&quot;&gt; 

&lt;table&gt;
&lt;tr&gt;&lt;th&gt;Original &quot;#house#&quot;&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;cfdump var=&quot;#house#&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;Output from the UDF (#stufftosave#)&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;pre&gt;&lt;cfoutput&gt;#stufftosave#&lt;/cfoutput&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;Recreated &quot;#cachedhouse#&quot;&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;cfdump var=&quot;#cachedhouse#&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;]]></help>
			               <description><![CDATA[Pass a CF variable, and a valid variable name, and the UDF returns a chunk of CFscript that will, when run, recreate the original var as a variable with the name passed as the second argument.
Designed as a way of caching complex variables when usind in conjunction with CFfile (or similar).]]></description>
			               <starttext><![CDATA[function VarToScript(lObj,lName) {
	var i="";
	var j="";
	var k="";
	var l="";
	var crlf=chr(13) & chr(10);
	var s="";
	var t="";
	var u='",##';
	var v='"",####';

	if (IsStruct(lObj)) {
		s = s & crlf & lName & "=StructNew();";
		for (i IN lObj) {
			if (IsSimpleValue( lObj[i] )) {
				s = s & crlf & lName & "[""" & i & """]=""" & ReplaceList(lObj[i],u,v) & """;";
			} else {
				s = s & varToScript(lObj[i], lName & "[""" & i & """]");
			}
		}

	} else if (IsArray(lObj)) {
		s = s & crlf & lName & "=ArrayNew(1);";
		for(i=1; i LTE ArrayLen(lObj); i=i+1) {
			if (IsSimpleValue( lObj[i] )) {
				s = s & crlf & lName & "[" & i & "]=""" & ReplaceList(lObj[i],u,v) & """;";
			} else {
				s = s & varToScript(lObj[i], lName & "[""" & i & """]");
			}
		}

	} else if (IsQuery(lObj)) {
		l = lObj.columnList;

		s = s & crlf & lName & "=QueryNew(""" & l & """);";
		s = s & crlf & "QueryAddRow(" & lName & ", " & lObj.recordcount & ");";

		for(i=1; i LTE lObj.recordcount; i=i+1) {
			for(j=1; j LTE ListLen(l); j=j+1) {
				k = lObj[ListGetAt(l,j)][i];
				if (IsSimpleValue(k)) {
					s = s & crlf & "QuerySetCell(" & lName & ",""" & ListGetAt(l,j) & """, """ & ReplaceList(k,u,v) & """," & i & ");";
				} else {
					t = "request.var2script_" & Replace(CreateUUID(),'-','_','all');
					s = s & crlf & "QuerySetCell(" & lName & ",""" & ListGetAt(l,j) & """, " & t & "," & i & ");";
					s = varToScript(k, t) & s;
					s = s & crlf & "StructDelete(variables,""#t#"");";
				}
			}
		}

	} else if (IsSimpleValue(lObj)) {
		s = s & crlf & lName & "=""" & ReplaceList(lObj,u,v) & """;";

	} else if (IsCustomFunction(lObj)) {
		s = s & crlf & "/* " & lName & " is a custom fuction, but i can't cfscript it */";

	} else {
		s = s & crlf & "/* " & lName & " - not sure what it is.... */";
	}

	return s;
}]]></starttext>
			               <endtext/>
			               <author>Bert Dawson</author>
			               <platforms/>
			               <created>09-18-2002</created>
			               <lastupdated>09-18-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="385" template="cfm">
			               <name>vCal</name>
			               <help><![CDATA[&lt;cfscript&gt;
  stEvent = StructNew();
  stEvent.description = &quot;This can come from a file or other variable&quot;;
  stEvent.subject = &quot;A vCal created with the vCal UDF&quot;;
  stEvent.location = &quot;Chicago, IL&quot;;
  stEvent.startTime = &quot;{ts &apos;2002-01-14 20:53:07&apos;}&quot;; //dateObj or timestamp in GMT
  stEvent.endTime = &quot;{ts &apos;2002-01-14 21:53:07&apos;}&quot;; // dateObj or timestamp in GMT
  stEvent.priority = 2;
  vCalOutput = vCal(stEvent);
&lt;/cfscript&gt;

&lt;cfoutput&gt;
#vCalOutput#
&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Pass a formatted structure containing subject, descrition, start date/time in GMT, end date/time in GMT, and priority and get back a formatted string in the vCalendar format that can be saved to a file to be used as an attachment with cfmail.]]></description>
			               <starttext><![CDATA[function vCal(stEvent)
{

	var description = "";
	var vCal = "";
	
	var CRLF=chr(13)&chr(10);
	
	if (NOT IsDefined("stEvent.startTime"))
		stEvent.startTime = DateConvert('local2Utc', Now());
	
	if (NOT IsDefined("stEvent.endTime"))
		stEvent.endTime = DateConvert('local2Utc', Now());
		
	if (NOT IsDefined("stEvent.location"))
		stEvent.location = "N/A";
				
	if (NOT IsDefined("stEvent.subject"))
		stEvent.subject = "Auto vCalendar Generated";
		
	if (NOT IsDefined("stEvent.description"))
		stEvent.description = "Autobot VCalendar Generated";
		
	if (NOT IsDefined("stEvent.priority"))
		stEvent.priority = "1";
			

	vCal = "BEGIN:VCALENDAR" & CRLF;
	vCal = vCal & "PRODID:-//Microsoft Corporation//OutlookMIMEDIR//EN" & CRLF;
	vCal = vCal & "VERSION:1.0" & CRLF;
	vCal = vCal & "BEGIN:VEVENT" & CRLF;
	vCal = vCal & "DTSTART:" & 
			DateFormat(stEvent.startTime,"yyyymmdd") & "T" & 
			TimeFormat(stEvent.startTime, "HHmmss") & "Z" & CRLF;
	vCal = vCal & "DTEND:" & DateFormat(stEvent.endTime, "yyyymmdd") & "T" & 
			TimeFormat(stEvent.endTime, "HHmmss") & "Z" & CRLF;
	vCal = vCal & "LOCATION:" & stEvent.location & CRLF;
	vCal = vCal & "SUMMARY;ENCODING=QUOTED-PRINTABLE:" & stEvent.subject & CRLF;
	
	vCal = vCal & "DESCRIPTION;ENCODING=QUOTED-PRINTABLE:";
	// Convert CF_CRLF (13_10) into =0D=0A with CR/LF and indent sequences
	description = REReplace(stEvent.description,"[#Chr(13)##Chr(10)#]", "=0D=0A=#Chr(13)##Chr(10)#     ", "ALL");
	vCal = vCal & description & CRLF;
	
	vCal = vCal & "PRIORITY:" & stEvent.priority & CRLF;
	vCal = vCal & "END:VEVENT" & CRLF;
	vCal = vCal & "END:VCALENDAR" & CRLF;	
	
	return vCal;
	
}]]></starttext>
			               <endtext/>
			               <author>Chris Wigginton</author>
			               <platforms/>
			               <created>04-10-2002</created>
			               <lastupdated>04-10-2002</lastupdated>
			          </snippet>
					
				 	<snippet id="944" template="cfm">
			               <name>xmlDoctoString</name>
			               <help><![CDATA[&lt;!--- Generate the XML doc ---&gt;
&lt;cfsavecontent variable=&quot;xmlString&quot;&gt;
	&lt;geeks_list&gt;
		&lt;geek city=&quot;Washinton D.C.&quot; name=&quot;Tom Muck&quot;&gt;The only guy I know able to write a whole book using more than 6 different server-side languages&lt;/geek&gt;
		&lt;geek city=&quot;Lugano (Switzerland)&quot; name=&quot;Massimo Foti&quot;&gt;The man who learned JavaScript in order to avoid learning german&lt;/geek&gt;
		&lt;geek city=&quot;Los Angeles&quot; name=&quot;Angela Buraglia&quot;&gt;By far the cutiest geek in town&lt;/geek&gt;
		&lt;geek city=&quot;Seattle&quot; name=&quot;Dan Short&quot;&gt;Be careful with him, he married a trained killer...&lt;/geek&gt;
	&lt;/geeks_list&gt;	
&lt;/cfsavecontent&gt;

&lt;cfoutput&gt;#htmlEditFormat(xmlDoctoString(xmlString))#&lt;/cfoutput&gt;

&lt;!--- 
In order to understand the need to have such a UDF try the CFML code below. 
Basically CF always return the XML declaration when you turn an XML  Doc to string:
---&gt;
&lt;cfset XMLDoc=XmlParse(xmlString, &quot;yes&quot;)&gt;
&lt;cfoutput&gt;#htmlEditFormat(ToString(XMLDoc))#&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Converts an CF XML objects to string without the XML declaration.
In order to understand the need to have such a UDF you have to remember that CF always return the XML declaration when you turn an XML Doc to a string.]]></description>
			               <starttext><![CDATA[<cffunction name="xmlDoctoString" output="no" returntype="string" displayname="xmlDoctoString" hint="Extract the root element inside an XML Doc and return it as a string">
	<cfargument name="xmlDoc" type="string" required="true" displayname="xmlDoc" hint="An XML Doc or a well formed XML string">
	<cfset var xmlToParse="">
	<!--- Check to see if the argument is already an XMLDoc --->
	<cfif IsXmlDoc(arguments.xmlDoc)>
		<cfset xmlToParse=arguments.xmlDoc>
	<cfelse>
		<!--- We need a parsed XML doc, not just a simple string --->
		<cftry>
			<cfset xmlToParse=XmlParse(arguments.xmlDoc, "yes")>
			<!--- Failed parsing, the string culd be not a well formed XML, throw an exception --->
			<cfcatch type="Any">
				<cfthrow message="xmlDoctoString: failed to parse argument.xmlDoc" type="xmlDoctoString">
			</cfcatch>
		</cftry>
	</cfif>
	<cfreturn xmlToParse.getDocumentElement().toString()>
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Massimo Foti</author>
			               <platforms/>
			               <created>08-02-2003</created>
			               <lastupdated>08-02-2003</lastupdated>
			          </snippet>
					
				 	<snippet id="1008" template="cfm">
			               <name>xmlExtractList</name>
			               <help><![CDATA[&lt;cfxml variable=&quot;EntryXML&quot;&gt;
&lt;users&gt;
 &lt;salesman&gt;
  &lt;systemname&gt;user&lt;/systemname&gt;
  &lt;fullname&gt;Mike Smith&lt;/fullname&gt;
  &lt;email&gt;MSmith@noDomain.com&lt;/email&gt;
 &lt;/salesman&gt;
 &lt;salesman&gt;
  &lt;systemname&gt;user&lt;/systemname&gt;
  &lt;fullname&gt;mark Hendrix Smith&lt;/fullname&gt;
  &lt;email&gt;MHendrix@noDomain.com&lt;/email&gt;
 &lt;/salesman&gt;
 &lt;salesman&gt;
  &lt;systemname&gt;user&lt;/systemname&gt;
  &lt;fullname&gt;Tammy Cochran&lt;/fullname&gt;
  &lt;email&gt;MCochran@noDomain.com&lt;/email&gt;
 &lt;/salesman&gt;
 &lt;salesman&gt;
  &lt;systemname&gt;user&lt;/systemname&gt;
  &lt;fullname&gt;Mike Smith&lt;/fullname&gt;
  &lt;email&gt;MSmith@noDomain.com&lt;/email&gt;
 &lt;/salesman&gt;
&lt;/users&gt;
&lt;/cfxml&gt;

&lt;cfoutput&gt;#xmlExtractList(EntryXML, &quot;email&quot;)#&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[This UDF searches for all elements matching the specified tag name and returns a list from the text within those elements.]]></description>
			               <starttext><![CDATA[<cffunction name="xmlExtractList" returnType="string" output="no">
   <cfargument name="inString" type="any">
   <cfargument name="tagName" type="string">
   <cfargument name="delim" default=",">
   
   <cfset var inXML = "">
   
   <cfset var elementsArray = "">
   <cfset var valuesArray = arrayNew(1)>
   <cfset var i=1>
   <cfset var j=1>
   <cfset var ret = "">
   
   <cfif isXmlDoc(arguments.inString)>
      <cfset inXML = arguments.inString>
   <cfelse>
      <cfset inXML  = xmlParse(arguments.inString)>
   </cfif>
   
   <cfset elementsArray = xmlSearch(inXML, "//" & arguments.tagName)>

   
   <cfloop index="j" from="1" to="#arrayLen(elementsArray)#">
      <cfif elementsArray[j].xmlText neq "">
         <cfset valuesArray[i] = elementsArray[j].xmlText>
         <cfset i=i+1>
      </cfif>
   </cfloop>
   
   <cfset ret = arrayToList(valuesArray, arguments.delim)>
   <cfreturn ret>
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Samuel Neff</author>
			               <platforms/>
			               <created>01-13-2004</created>
			               <lastupdated>01-13-2004</lastupdated>
			          </snippet>
					
				 	<snippet id="1026" template="cfm">
			               <name>xmlMerge</name>
			               <help><![CDATA[&lt;cfxml variable=&quot;xmlDoc1&quot;&gt;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;settings&gt;
	&lt;system&gt;
		&lt;datasource value=&quot;myDSN&quot;/&gt;
		&lt;home value=&quot;index.cfm&quot;/&gt;
	&lt;/system&gt;
	&lt;instance&gt;
		&lt;timeZone&gt;
			&lt;offset 
				value=&quot;0&quot;/&gt;
			&lt;label
				value=&quot;GMT&quot;/&gt;
		&lt;/timeZone&gt;
		&lt;skin value=&quot;default&quot;/&gt;
	&lt;/instance&gt;
	&lt;custom /&gt;			
&lt;/settings&gt;
&lt;/cfxml&gt;


&lt;cfxml variable=&quot;xmlDoc2&quot;&gt;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;settings&gt;
	&lt;instance&gt;
		&lt;timeZone&gt;
			&lt;offset
				value=&quot;-7&quot;/&gt;
			&lt;label
				value=&quot;PST&quot;/&gt;
		&lt;/timeZone&gt;		
	&lt;/instance&gt;				
	&lt;custom&gt;
		&lt;excludeFromLogging&gt;
			&lt;page value=&quot;hidden.cfm&quot;/&gt;
			&lt;page value=&quot;logreport.cfm&quot;/&gt;
		&lt;/excludeFromLogging&gt;
	&lt;/custom&gt;
&lt;/settings&gt;
&lt;/cfxml&gt;


&lt;h2&gt;XMLMerge With Overwriting of Nodes (Default)&lt;/h2&gt;
&lt;cfoutput&gt;
&lt;table border=&quot;1&quot;&gt;
	&lt;tr&gt;
		&lt;th&gt;Original&lt;/th&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td valign=&quot;top&quot; style=&quot;font-size:x-small;&quot;&gt;#htmlCodeFormat(toString(xmlDoc1))#&lt;/td&gt;
	&lt;/tr&gt;	
	&lt;tr&gt;
		&lt;th&gt;To Merge&lt;/th&gt;
	&lt;/tr&gt;	
	&lt;tr&gt;
		&lt;td valign=&quot;top&quot; style=&quot;font-size:x-small;&quot;&gt;#htmlCodeFormat(toString(xmlDoc2))#&lt;/td&gt;
		&lt;cfset xmlMerge(xmlDoc1,xmlDoc2)&gt;
	&lt;/tr&gt;
	&lt;tr&gt;	
		&lt;th&gt;Merged&lt;/th&gt;
	&lt;/tr&gt;	
	&lt;tr&gt;
		&lt;td valign=&quot;top&quot; style=&quot;font-size:x-small;&quot;&gt;#htmlCodeFormat(toString(xmlDoc1))#&lt;/td&gt;
	&lt;/tr&gt;
&lt;/table&gt;
&lt;/cfoutput&gt;


&lt;cfxml variable=&quot;xmlDoc3&quot;&gt;
&lt;bloggers&gt;
	&lt;blogger firstName=&quot;Ben&quot; lastName=&quot;Forta&quot; blog=&quot;http://forta.com/blog/&quot;/&gt;
	&lt;blogger firstName=&quot;Sean&quot; lastName=&quot;Corfield&quot; blog=&quot;http://www.corfield.org/blog/&quot;/&gt;
&lt;/bloggers&gt;
&lt;/cfxml&gt;

&lt;cfxml variable=&quot;xmlDoc4&quot;&gt;
&lt;bloggers&gt;
	&lt;blogger firstName=&quot;Christian&quot; lastName=&quot;Cantrell&quot; blog=&quot;http://www.markme.com/cantrell/&quot;/&gt;
	&lt;blogger firstName=&quot;Brandon&quot; lastName=&quot;Purcell&quot; blog=&quot;http://www.bpurcell.org&quot;/&gt;
&lt;/bloggers&gt;
&lt;/cfxml&gt;

&lt;h2&gt;XMLMerge Without Overwrite of Nodes&lt;/h2&gt;

&lt;cfoutput&gt;
&lt;table border=&quot;1&quot;&gt;
	&lt;tr&gt;
		&lt;th&gt;Original&lt;/th&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td valign=&quot;top&quot; style=&quot;font-size:x-small;&quot;&gt;#htmlCodeFormat(toString(xmlDoc3))#&lt;/td&gt;
	&lt;/tr&gt;	
	&lt;tr&gt;
		&lt;th&gt;To Merge&lt;/th&gt;
	&lt;/tr&gt;	
	&lt;tr&gt;
		&lt;td valign=&quot;top&quot; style=&quot;font-size:x-small;&quot;&gt;#htmlCodeFormat(toString(xmlDoc4))#&lt;/td&gt;
		
	&lt;/tr&gt;
	&lt;tr&gt;	
		&lt;th&gt;Merged&lt;/th&gt;
	&lt;/tr&gt;	
	&lt;tr&gt;
		&lt;cfset xmlMerge(xmlDoc3,xmlDoc4,false)&gt;
		&lt;td valign=&quot;top&quot; style=&quot;font-size:x-small;&quot;&gt;#htmlCodeFormat(toString(xmlDoc3))#&lt;/td&gt;
	&lt;/tr&gt;
&lt;/table&gt;
&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[Given two XML documents, merge (superimpose) the second into the first.  You can choose to either overwrite existing nodes with the new values (default behavior) or add the nodes even if they duplicate the existing document.  This UDF is particularly handy when you have a default set of configurations in an XML file and want to be able to override some of them with an second XML file but want to have the second file contain only the nodes you are overriding.]]></description>
			               <starttext><![CDATA[function xmlMerge(xml1,xml2){
	var readNodeParent = arguments.xml2;
	var writeNodeList = arguments.xml1;
	var writeNodeDoc = arguments.xml1;
	var readNodeList = "";
	var writeNode = "";
	var readNode = "";
	var nodeName = "";
	var ii = 0;
	var writeNodeOffset = 0;
	var toAppend = 0;
	var nodesDone = structNew();
	//by default, overwrite nodes
	var overwriteNodes = true;
	//if there's a 3rd arguments, that's the overWriteNodes flag
	if(structCount(arguments) GT 2)
		overwriteNodes = arguments[3];
	//if there's a 4th argument, it's the DOC of the writeNode -- not a user provided argument -- just used when doing recursion, so we know the original XMLDoc object
	if(structCount(arguments) GT 3)
		writeNodeDoc = arguments[4];
	//if we are looking at the whole document, get the root element
	if(isXMLDoc(arguments.xml2))
		readNodeParent = arguments.xml2.xmlRoot;
	//if we are looking at the whole Doc for the first element, get the root element
	if(isXMLDoc(arguments.xml1))
		writeNodeList = arguments.xml1.xmlRoot;	
	//loop through the readNodeParent (recursively) and override all xmlAttributes/xmlText in the first document with those of elements that match in the second document
	for(nodeName in readNodeParent){
		writeNodeOffset = 0;
		//if we haven't yet dealt with nodes of this name, do it
		if(NOT structKeyExists(nodesDone,nodeName)){
			readNodeList = readNodeParent[nodeName];
			//if there aren't any of this node, we need to append however many there are
			if(NOT structKeyExists(writeNodeList,nodeName)){
				toAppend = arrayLen(readNodeList);
			}
			//if there are already at least one node of this name
			else{
				//if we are overwriting nodes, we need to append however many there are minus however many there were (if there none new, it will be 0)
				if(overWriteNodes){
					toAppend = arrayLen(readNodeList) - arrayLen(writeNodeList[nodeName]);
				}
				//if we are not overwriting, we need to add however many there are
				else{
					toAppend = arrayLen(readNodeList);
					//if we are not overwriting, we need to make the offset of the writeNode equal to however many there already are
					writeNodeOffset = arrayLen(writeNodeList[nodeName]);
				}
			}
			//append however many nodes necessary of the name
			for(ii = 1;  ii LTE toAppend; ii = ii + 1){
				arrayAppend(writeNodeList.xmlChildren,xmlElemNew(writeNodeDoc,nodeName));
			}
			//loop through however many of this nodeName there are, writing them to the writeNodes
			for(ii = 1; ii LTE arrayLen(readNodeList); ii = ii + 1){
				writeNode = writeNodeList[nodeName][ii + writeNodeOffset];
				readNode = readNodeList[ii];
				//set the xmlAttributes and xmlText to this child's values
				writeNode.xmlAttributes = readNode.xmlAttributes;				
				//deal with the CDATA scenario to properly preserve (though, if it contains CDATA and text nodes, this won't work!!
				if(arrayLen(readNode.xmlNodes) AND XmlGetNodeType(readNode.xmlNodes[1]) is "CDATA_SECTION_NODE"){
					writeNode.xmlCData = readNode.xmlcdata;
				}
				else{
					//modify to check to see if it's cData or not
					writeNode.xmlText = readNode.xmlText;
				}
				//if this element has any children, recurse
				if(arrayLen(readNode.xmlChildren)){
					xmlMerge(writeNode,readNode,overwriteNodes,writeNodeDoc);
				}
			}
			//add this node name to those nodes we have done -- we need to do this because an XMLDoc object can have duplicate keys
			nodesDone[nodeName] = true;
		}
	}
}]]></starttext>
			               <endtext/>
			               <author>Nathan Dintenfass</author>
			               <platforms/>
			               <created>10-15-2008</created>
			               <lastupdated>10-15-2008</lastupdated>
			          </snippet>
					
				 	<snippet id="1957" template="cfm">
			               <name>xmlToJson</name>
			               <help><![CDATA[&lt;!--- XML example: ---&gt;
&lt;cfsavecontent variable=&quot;xml&quot;&gt;&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;
	&lt;root arg=&quot;arg_root&quot;&gt;text_root
		&lt;depth1node1 d1n1a1=&quot;d1n1a1&quot;&gt;
			text_d1n1
			&lt;depth2node1 d2n1a1=&quot;d2n1a1&quot; d2n1a2=&quot;d2n1a2&quot;&gt;
				text_d2n1
				&lt;depth3nodearr d3naa1=&quot;d3naa1&quot; d3naa2=&quot;d3naa2&quot; d3naa3=&quot;d3naa3&quot;&gt;
					text_d3na
				&lt;/depth3nodearr&gt;
				&lt;depth3nodearr d3naa1=&quot;d3naa1&quot; d3naa2=&quot;d3naa2&quot; d3naa3=&quot;d3naa3&quot;&gt;
					text_d3na
				&lt;/depth3nodearr&gt;				
			&lt;/depth2node1&gt;
			&lt;depth2node2 d2n2a1=&quot;d2n2a1&quot; d2n2a2=&quot;d2n2a2&quot; d2n2a3=&quot;d2n2a3&quot;&gt;
				text_d2n2
			&lt;/depth2node2&gt;
		&lt;/depth1node1&gt;
	&lt;/root&gt;
&lt;/cfsavecontent&gt;
&lt;cfdump var=&quot;#xmlToJson(xml)#&quot;&gt;
&lt;cfdump var=&quot;#xmlParse(xml)#&quot;&gt;

&lt;!--- XHTML example: ---&gt;
&lt;cfhttp url=&quot;http://www.xhtmlvalid.com/demo/&quot;/&gt;
&lt;cfdump var=&quot;#xmlToJson(cfhttp.filecontent)#&quot;&gt;
&lt;cfdump var=&quot;#xmlParse(cfhttp.filecontent)#&quot;&gt;]]></help>
			               <description><![CDATA[xmlToJson uses an integrated xsl template (xslt) and xmlTransform() to convert valid markup to JSON. Because of the possible combinations of attribute and node text, the JSON is structured in a very similar fashion as xmlParse.  The JSON result for a node will contain the following keys: text; attributes; [children]. Text is always a simple value. Arguments will be a struct, and is present whether the node has attributes or not. The structure will repeat within [children] for the length of the tree.  This function should work for any well-formed and valid xml/xhtml]]></description>
			               <starttext><![CDATA[<cffunction name="xmlToJson" output="false" returntype="any" hint="convert xml to JSON">
		<cfargument name="xml" default="" required="false" hint="raw xml"/>
		<cfargument name="includeFormatting" type="boolean" default="false" required="false" hint="whether or not to maintain and encode tabs, linefeeds and carriage returns"/>
		<cfset var result ="">
		<cfset var xsl ="">
		<cfsavecontent variable="xsl">
			<?xml version="1.0" encoding="UTF-8"?>
			<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
				<xsl:output indent="no" omit-xml-declaration="yes" method="text" encoding="UTF-8" media-type="application/json"/>
				<xsl:strip-space elements="*"/>
			
				<!-- used to identify unique children in Muenchian grouping, credit Martynas Jusevicius http://www.xml.lt -->
				<xsl:key name="elements-by-name" match="@* | *" use="concat(generate-id(..), '@', name(.))"/>
			
				<!-- string -->
				<xsl:template match="text()">
					<xsl:call-template name="processValues">
						 <xsl:with-param name="s" select="."/>
					</xsl:call-template>
				</xsl:template>
			
				<!-- text values (from text nodes and attributes) -->
				<xsl:template name="processValues">
					<xsl:param name="s"/>
					<xsl:choose>
						<!-- number -->
						<xsl:when test="not(string(number($s))='NaN')">
							<xsl:value-of select="$s"/>
						</xsl:when>			
						<!-- boolean -->
						<xsl:when test="translate($s,'TRUE','true')='true'">true</xsl:when>
						<xsl:when test="translate($s,'FALSE','false')='false'">false</xsl:when>			
						<!-- string -->
						<xsl:otherwise>
							<xsl:call-template name="escapeArtist">
								<xsl:with-param name="s" select="$s"/>
							</xsl:call-template>
						</xsl:otherwise>			
					</xsl:choose>
				</xsl:template>
			
				<!-- begin filter chain -->
				<xsl:template name="escapeArtist">
					<xsl:param name="s"/>
					"
					<xsl:call-template name="escapeBackslash">
						<xsl:with-param name="s" select="$s"/>
					</xsl:call-template>
					"
				</xsl:template>
			
				<!-- escape the backslash (\) before everything else. -->
				<xsl:template name="escapeBackslash">
					<xsl:param name="s"/>
					<xsl:choose>
						<xsl:when test="contains($s,'\')">
							<xsl:call-template name="escapeQuotes">
								<xsl:with-param name="s" select="concat(substring-before($s,'\'),'\\')"/>
							</xsl:call-template>
							<xsl:call-template name="escapeBackslash">
								<xsl:with-param name="s" select="substring-after($s,'\')"/>
							</xsl:call-template>
						</xsl:when>
						<xsl:otherwise>
							<xsl:call-template name="escapeQuotes">
								<xsl:with-param name="s" select="$s"/>
							</xsl:call-template>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:template>
			
				<!-- escape the double quote ("). -->
				<xsl:template name="escapeQuotes">
					<xsl:param name="s"/>
					<xsl:choose>
						<xsl:when test="contains($s,'&quot;')">
							<xsl:call-template name="encoder">
								<xsl:with-param name="s" select="concat(substring-before($s,'&quot;'),'\&quot;')"/>
							</xsl:call-template>
							<xsl:call-template name="escapeQuotes">
								<xsl:with-param name="s" select="substring-after($s,'&quot;')"/>
							</xsl:call-template>
						</xsl:when>
						<xsl:otherwise>
							<xsl:call-template name="encoder">
								<xsl:with-param name="s" select="$s"/>
							</xsl:call-template>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:template>
			
				<!-- encode tab, line feed and/or carriage return-->
				<xsl:template name="encoder">
					<xsl:param name="s"/>
					<xsl:choose>
						<!-- tab -->
						<xsl:when test="contains($s,'&#x9;')">
							<xsl:call-template name="encoder">
								<xsl:with-param name="s" select="concat(substring-before($s,'&#x9;'),'<cfoutput>#iif(arguments.includeFormatting,DE("\t"),DE(" "))#</cfoutput>',substring-after($s,'&#x9;'))"/>
							</xsl:call-template>
						</xsl:when>			
						<!-- line feed -->
						<xsl:when test="contains($s,'&#xA;')">
							<xsl:call-template name="encoder">
								<xsl:with-param name="s" select="concat(substring-before($s,'&#xA;'),'<cfoutput>#iif(arguments.includeFormatting,DE("\n"),DE(" "))#</cfoutput>',substring-after($s,'&#xA;'))"/>
							</xsl:call-template>
						</xsl:when>			
						<!-- carriage return -->
						<xsl:when test="contains($s,'&#xD;')">
							<xsl:call-template name="encoder">
								<xsl:with-param name="s" select="concat(substring-before($s,'&#xD;'),'<cfoutput>#iif(arguments.includeFormatting,DE("\r"),DE(" "))#</cfoutput>',substring-after($s,'&#xD;'))"/>
							</xsl:call-template>
						</xsl:when>
						<xsl:otherwise><xsl:value-of select="$s"/></xsl:otherwise>
					</xsl:choose>
				</xsl:template>
				
				<!-- main handler template
					creates a struct containing: the node text(); struct of attributes; and set a struct key for any node children. 
					this template then drills into the children, repeating itself until complete
				-->
				<xsl:template name="processNode">
					{
						"text":	
						<xsl:call-template name="escapeArtist">
							<xsl:with-param name="s" select="key('elements-by-name', concat(generate-id(..), '@', name(.)))/text()"/>
						</xsl:call-template>
						,"attributes":{				
							<xsl:for-each select="@*">
								<xsl:call-template name="escapeArtist">
									<xsl:with-param name="s" select="name()"/>
								</xsl:call-template>
								:						
								<xsl:call-template name="processValues">
									<xsl:with-param name="s" select="."/>
								</xsl:call-template>
								<xsl:if test="position() &lt; count(parent::node()/attribute::*)">
									,
								</xsl:if>
							</xsl:for-each>
						}
						<!-- drill down the tree -->
						<xsl:for-each select="*[generate-id(.) = generate-id(key('elements-by-name', concat(generate-id(..), '@', name(.))))]">
							,
							<xsl:call-template name="escapeArtist">
								<xsl:with-param name="s" select="name()"/>
							</xsl:call-template>
							:						
							<xsl:apply-templates select="."/>				
						</xsl:for-each>
					}
				</xsl:template>
				
				<!-- main parser
					basically a node 'loop' - performed once for all matches of *, so once for each node including the root.
					note: this loop has no knowledge of other iterations it may have performed.
				-->
				<xsl:template match="*">
					<!-- determine whether any peers share the node name, so we can spool off into 'array mode' -->
					<xsl:variable name="isArray" select="count(key('elements-by-name', concat(generate-id(..), '@', name(.)))) &gt; 1"/>
					
					<xsl:if test="count(ancestor::node()) = 1"><!-- begin the root node-->
						{ 
						<xsl:call-template name="escapeArtist">
							<xsl:with-param name="s" select="name()"/>
						</xsl:call-template>
						:		
					</xsl:if>				
					
					<xsl:if test="not($isArray)">
						<xsl:call-template name="processNode">
							<xsl:with-param name="s" select="."/>
						</xsl:call-template>
					</xsl:if>				
					<xsl:if test="$isArray">
						[
							<xsl:apply-templates select="key('elements-by-name', concat(generate-id(..), '@', name(.)))" mode="array"/>
						]
					</xsl:if>		
					<xsl:if test="count(ancestor::node()) = 1">}</xsl:if><!-- close the root node -->		
				</xsl:template>
				
				<!-- array template called from main parser -->
				<xsl:template match="*" mode="array">	
					<xsl:call-template name="processNode">
						<xsl:with-param name="s" select="."/>
					</xsl:call-template>
					<xsl:if test="position() != last()">,</xsl:if>				
				</xsl:template>
				
			</xsl:stylesheet>
		</cfsavecontent>
		<cfset xsl = xmlParse(reReplace(xsl,'([\s\S\w\W]*)(<\?xml)','\2','all'))>
		<cfscript>		
			result = arguments.xml;
			result = reReplace(result,'([\s\S\w\W]*)(<\?xml)','\2','all');
			result = xmlTransform(trim(result),xsl);
			return result;
		</cfscript>
	</cffunction>]]></starttext>
			               <endtext/>
			               <author>Tony Felice</author>
			               <platforms/>
			               <created>02-27-2009</created>
			               <lastupdated>02-27-2009</lastupdated>
			          </snippet>
					
				 	<snippet id="1145" template="cfm">
			               <name>xsdValidate</name>
			               <help><![CDATA[&lt;cfset err = structNew()&gt;

&lt;cfset xmlUri = &quot;file:///c:/test/bad.xml&quot;&gt;
&lt;cfset xsdUri = &quot;file:///c:/test/test.xsd&quot;&gt;

&lt;cfoutput&gt;
Valid: #xsdValidate(xmlUri, xsdUri, &quot;&quot;, err)#&lt;br /&gt;
&lt;/cfoutput&gt;

&lt;cfdump var=&quot;#err#&quot; label=&quot;Information about the error, if any&quot;&gt;]]></help>
			               <description><![CDATA[This UDF accepts a single XML file any one or more XSD files and validates the XML against the specified XSD(s).  Supports no-namespace validation and namespace-aware validation.  Returns true/false if valid and optionally a structure with the detailed error message if the XML file doesn't validate properly.

Requires that the Xerces Java 2 parser be installed on the CFMX server.  http://xml.apache.org/xerces2-j/index.html

The file paths must be specified as valid URI's.  The UDF makeUriFromPath can be used to convert absolute paths to URI's.]]></description>
			               <starttext><![CDATA[<cffunction name="xsdValidate" returnType="boolean" output="false">
  <cfargument name="xmlPath" type="string">
  <cfargument name="noNamespaceXsdUri" type="string">
  <cfargument name="namespaceXsdUri" type="string">
  <cfargument name="parseError" type="struct">
  
  <cfscript>
    var parser = createObject("java","org.apache.xerces.parsers.SAXParser");
    
    var err = structNew();
    var k = "";
    var success = true;
    
    var eHandler = createObject(
                     "java",
                     "org.apache.xml.utils.DefaultErrorHandler");
    
    var apFeat = "http://apache.org/xml/features/";
    var apProp = "http://apache.org/xml/properties/";
    
    eHandler.init();
    
    if (structKeyExists(arguments, "parseError")) {
       err = arguments.parseError;
     }
    
    
    try {
       parser.setErrorHandler(eHandler);
       
       parser.setFeature(
          "http://xml.org/sax/features/validation", 
          true);
          
       parser.setFeature(
          apFeat & "validation/schema", 
          true);
          
       parser.setFeature(
          apFeat & "validation/schema-full-checking", 
          true);
       
       if (structKeyExists(arguments, "noNamespaceXsdUri") and 
           arguments.noNamespaceXsdUri neq "") {
          
          parser.setProperty(
            apProp & "schema/external-noNamespaceSchemaLocation",
            arguments.noNamespaceXsdUri
          
          );
        }
       
       if (structKeyExists(arguments, "namespaceXsdUri") and 
           arguments.namespaceXsdUri neq "") {
          
          parser.setProperty(
            apProp & "schema/external-schemaLocation",
            arguments.namespaceXsdUri
          );
        }
       
       
       parser.parse(arguments.xmlPath);
     } catch (Any ex) {
       structAppend(err, ex, true);
       success = false;
     }
  </cfscript>

  <cfreturn success>
  
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Samuel Neff</author>
			               <platforms/>
			               <created>09-23-2004</created>
			               <lastupdated>09-23-2004</lastupdated>
			          </snippet>
					
				 	<snippet id="1154" template="cfm">
			               <name>xslt</name>
			               <help><![CDATA[&lt;cfxml variable=&quot;xml&quot;&gt;
&lt;!--- valid xml doc ---&gt;
&lt;/cfxml&gt;

&lt;cfxml variable=&quot;xsl&quot;&gt;
&lt;!--- valid xsl doc ---&gt;
&lt;/cfxml&gt;

&lt;cfscript&gt;
 stParams = StructNew();
 StructInsert(stParams, &quot;root&quot;, &quot;http://www.mysite.com&quot;);
&lt;/cfscript&gt;

&lt;cfoutput&gt;#xslt(xml, xsml, stParams)#&lt;/cfoutput&gt;
OR

&lt;cfoutput&gt;#xslt(&quot;c:\xmlFile.xml&quot;, xsl, stParams)#&lt;/cfoutput&gt;

OR

&lt;cfoutput&gt;#xslt(xml, &quot;c:\xslFile.xsl&quot;, stParams)#&lt;/cfoutput&gt;

OR

&lt;cfoutput&gt;#xslt((&quot;c:\xmlFile.xml&quot;, &quot;c:\xslFile.xsl&quot;, stParams)#&lt;/cfoutput&gt;]]></help>
			               <description><![CDATA[This UDF using CFMX's underlying Java XML/XSL engine to provide support for XSL transformations.  Natively CFMX does not provide support for parameters to be passed through to XSL stylesheets, nor does it allow for relative use of &amp;lt;xsl:import&amp;gt; tags due to the fact that xsl files must first be read into memory via &lt;CFFILE&gt;.  This UDF works around this by leveraging the underlying Java which supports parameter pass through, and also allows you enter a file path for your xml/xsl document.

Syntax:
XSLT(xmlsource, xslsource [, stParameters])

Arguments:
xmlSource - either a valid xml document as a string, or a absolute file path to a XML file.
xslSource - either a valid XSL document as a string, or a absolute file path to a XSL file.
stParameters (optional) - a structure of xsl:param elements to pass through where the key is the name of the param, and the value is the value of the param being passed through.  Do note that StructInsert() will need to be used as param names are case sensitive, and otherwise the struct key value will be in uppercase.]]></description>
			               <starttext><![CDATA[<cffunction name="xslt" returntype="string" output="No">
	<cfargument name="xmlSource" type="string" required="yes">
	<cfargument name="xslSource" type="string" required="yes">
	<cfargument name="stParameters" type="struct" default="#StructNew()#" required="No">
	
	<cfscript>
		var source = "";		var transformer = "";	var aParamKeys = "";	var pKey = "";
		var xmlReader = "";		var xslReader = "";		var pLen = 0;
		var xmlWriter = "";		var xmlResult = "";		var pCounter = 0;
		var tFactory = createObject("java", "javax.xml.transform.TransformerFactory").newInstance();
		
		//if xml use the StringReader - otherwise, just assume it is a file source.
		if(Find("<", arguments.xslSource) neq 0)
		{
			xslReader = createObject("java", "java.io.StringReader").init(arguments.xslSource);
			source = createObject("java", "javax.xml.transform.stream.StreamSource").init(xslReader);
		}
		else
		{
			source = createObject("java", "javax.xml.transform.stream.StreamSource").init("file:///#arguments.xslSource#");
		}
		
		transformer = tFactory.newTransformer(source);
		
		//if xml use the StringReader - otherwise, just assume it is a file source.
		if(Find("<", arguments.xmlSource) neq 0)
		{
			xmlReader = createObject("java", "java.io.StringReader").init(arguments.xmlSource);
			source = createObject("java", "javax.xml.transform.stream.StreamSource").init(xmlReader);
		}
		else
		{
			source = createObject("java", "javax.xml.transform.stream.StreamSource").init("file:///#arguments.xmlSource#");
		}
		
		//use a StringWriter to allow us to grab the String out after.
		xmlWriter = createObject("java", "java.io.StringWriter").init();
		
		xmlResult = createObject("java", "javax.xml.transform.stream.StreamResult").init(xmlWriter);		
		
		if(StructCount(arguments.stParameters) gt 0)
		{
			aParamKeys = structKeyArray(arguments.stParameters);
			pLen = ArrayLen(aParamKeys);
			for(pCounter = 1; pCounter LTE pLen; pCounter = pCounter + 1)
			{
				//set params
				pKey = aParamKeys[pCounter];
				transformer.setParameter(pKey, arguments.stParameters[pKey]);			
			}	
		}
		
		transformer.transform(source, xmlResult);
		
		return xmlWriter.toString();
	</cfscript>
</cffunction>]]></starttext>
			               <endtext/>
			               <author>Mark Mandel</author>
			               <platforms/>
			               <created>01-16-2006</created>
			               <lastupdated>01-16-2006</lastupdated>
			          </snippet>
					
				 	<snippet id="147" template="cfm">
			               <name>XSLTCF5</name>
			               <help><![CDATA[&lt;!---
&lt;cfset sourceDoc=&quot;#GetDirectoryFromPath(GetCurrentTemplatePath())#cd_list.xml&quot;&gt;
&lt;cfset styleDoc=&quot;#GetDirectoryFromPath(GetCurrentTemplatePath())#cd_list.xsl&quot;&gt;
&lt;cfoutput&gt;#xsltcf5(sourceDoc,styleDoc)#&lt;/cfoutput&gt;
Commented out since the COM object has issues on this box.
---&gt;]]></help>
			               <description><![CDATA[Returns the Transformed content of an XML document from a specified XSL document. This function uses the MSXML processor. (Tested on MSXML3+)]]></description>
			               <starttext><![CDATA[function xsltcf5(source,style){
	// Instantiate COM Objects
	var objSource=CreateObject("COM", "Microsoft.XMLDOM", "INPROC");
	var objStyle=CreateObject("COM", "Microsoft.XMLDOM", "INPROC");
	var sourceReturn = "";
	var styleReturn = "";
	var styleRoot = "";
	var xsloutput = "";
	// Parse XML
	objSource.async = "false";
	sourceReturn = objSource.load("#source#");
	// Parse XSL
	objStyle.async = "false";
	styleReturn = objStyle.load("#style#");
	// Transform Document 
	styleRoot = objStyle.documentElement;
	xsloutput = objSource.transformNode(styleRoot);
	// Output Results
	return xsloutput;
}]]></starttext>
			               <endtext/>
			               <author>Joshua Miller</author>
			               <platforms/>
			               <created>09-20-2004</created>
			               <lastupdated>09-20-2004</lastupdated>
			          </snippet>
					
				</snippets>
			</library>