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
Tayo Akinmade added
arrayTrim
11 day(s) ago
Will Belden added
longTime
17 day(s) ago
James Sleeman added
quickSort
27 day(s) ago
Ben Forta added
GetHostAddress
30 day(s) ago
Top Rated
EksporSQLData
Rated 5.0, 16 time(s)
backupDatabase
Rated 5.0, 13 time(s)
indentXml
Rated 5.0, 10 time(s)
generateSsccAsn
Rated 5.0, 4 time(s)