Skip to content

Instantly share code, notes, and snippets.

@wellercs
Created July 27, 2012 23:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wellercs/3190924 to your computer and use it in GitHub Desktop.
Save wellercs/3190924 to your computer and use it in GitHub Desktop.
Easy method for setting cfqueryparam null attribute
<cfcomponent name="utilities" output="false" hint="I provide various utility functionality">
<cffunction name="init" access="public" returntype="any" output="false" hint="Initializes the Service">
<cfreturn this />
</cffunction>
<cffunction name="isNullFormat" access="remote" returntype="any" output="false" hint="I return whether something is null">
<cfargument name="input" type="any" required="true" />
<cfset var inputdatatype = "">
<cftry>
<cfset inputdatatype = arguments.input.GetClass().GetName() />
<cfif inputdatatype IS "java.lang.String" AND NOT len(trim(arguments.input))>
<cfreturn true />
<cfelseif inputdatatype IS "java.lang.String" AND len(trim(arguments.input))>
<cfreturn false />
<cfelseif inputdatatype IS "coldfusion.runtime.Struct" AND StructIsEmpty(arguments.input)>
<cfreturn true />
<cfelseif inputdatatype IS "coldfusion.runtime.Struct" AND NOT StructIsEmpty(arguments.input)>
<cfreturn false />
<cfelseif inputdatatype IS "coldfusion.runtime.Array" AND NOT ArrayLen(arguments.input)>
<cfreturn true />
<cfelseif inputdatatype IS "coldfusion.runtime.Array" AND ArrayLen(arguments.input)>
<cfreturn false />
<cfelseif inputdatatype IS "coldfusion.sql.QueryTable" AND NOT arguments.input.recordcount>
<cfreturn true />
<cfelseif inputdatatype IS "coldfusion.sql.QueryTable" AND arguments.input.recordcount>
<cfreturn false />
<cfelse>
<cfthrow type="customerror" message="Unknown data type." detail="Input: #arguments.input#. Data type received: #inputdatatype#">
</cfif>
<cfcatch type="any">
<!--- fail --->
</cfcatch>
</cftry>
</cffunction>
</cfcomponent>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment