Skip to content

Instantly share code, notes, and snippets.

@roulupen
Last active December 12, 2015 08:29
Show Gist options
  • Save roulupen/4744390 to your computer and use it in GitHub Desktop.
Save roulupen/4744390 to your computer and use it in GitHub Desktop.
<cfscript>
public boolean function ListCompare(required string list,required string sublist,string delim=",") {
var local = {}; //Local scope declaration
local.qryFilterResult = queryNew(""); //Declaring query object to hold filtered list
try {
/* Creating a query object from the list passes in the argumnet */
local.qryOriginalList = queryNew("");
queryAddColumn(local.qryOriginalList, "listElement", "CF_SQL_VARCHAR", listToArray(arguments.list, arguments.delim));
/* Filtering sublist from the list query object with distinct and case insensitive search */
local.qoq = new Query();
local.qoq.setAttributes(QoQsrcTable = local.qryOriginalList);
local.qoq.addParam(name="listElement",value=uCase(arguments.sublist),CFSQLTYPE="CF_SQL_VARCHAR",list="true");
local.qrySubListFilter = local.qoq.execute(
sql="SELECT DISTINCT UPPER(listElement) FROM QoQsrcTable WHERE UPPER(listElement) IN (:listElement)",
dbtype="query");
local.qryFilterResult = local.qrySubListFilter.getResult();
/* If resulted filtered query has record count equal to list length of the sublist then all sublist elements are present in the list. Otherwise all sublist elemnts are not present in the original list */
if(local.qryFilterResult.recordCount EQ listLen(arguments.sublist, arguments.delim))
return true;
else
return false;
} catch(Any e) {
/* If any error will occur during the entire process then it will return false */
return false;
}
}
writeDump(ListCompare("A,a,b,c,d,e,f", "a,b,c"));
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment