collectionExists(collection)
Last updated March 10, 2006
Version: 2 | Requires: ColdFusion MX | Library: UtilityLib
Description:
Call this function, passing in a collection name, to see if that named Verity colleciton exists.
The previous version of this UDF used the <cfcollection action="list" /> tag to determine if the collection exists. The problem is, this action takes a very long time to return a result if there are a lot of collection registered (appx 1 second for every 3 collections.)
Return Values:
Returns a boolean.
Example:
<cfcollection
action="create"
collection="catalog"
path="#pathToVerityCollection#"
language="english"
/>
</cfif>
Parameters:
| Name | Description | Required |
|---|---|---|
| collection | Name of collection | Yes |
Full UDF Source:
<!---
Call this function, passing in a collection name, to see if that named Verity colleciton exists.
Version 1 by Pete Ruckelshaus, pruckelshaus@yahoo.com
Raymond Camden modified version 2 a bit.
@param collection Name of collection (Required)
@return Returns a boolean.
@author Dan G. Switzer, II (pruckelshaus@yahoo.comdswitzer@pengoworks.com)
@version 2, March 10, 2006
--->
<cffunction name="collectionExists" returnType="boolean" output="false" hint="This returns a yes/no value that checks for the existence of a named collection.">
<cfargument name="collection" type="string" required="yes">
<!---// by default return true //--->
<cfset var bExists = true />
<cfset var searchItems = "">
<!---// if you can't search the collection, then assume it doesn't exist //--->
<cftry>
<cfsearch
name="searchItems"
collection="#arguments.collection#"
type="simple"
criteria="#createUUID()#"
/>
<cfcatch type="any">
<!---// if the message contains the string "does not exist", then the collection can't be found //--->
<cfif cfcatch.message contains "does not exist">
<cfset bExists = false />
<cfelse>
<cfrethrow>
</cfif>
</cfcatch>
</cftry>
<!---// returns true if search was successful and false if an error occurred //--->
<cfreturn bExists />
</cffunction>
Search CFLib.org
Latest Additions
Raymond Compton added
structBlend
19 day(s) ago
Duncan added
IsZIPUK
19 day(s) ago
Todd Sharp added
getTagContentAll
25 day(s) ago
Gerald Guido added
ListReturnDuplicat...
1 month(s) ago
Gerald Guido added
ListReturnDuplicat...
1 month(s) ago