Proofs of the adage, “truth is stranger than fictiion”….

Town Outlaws Stripperobics
Religious cult irate over magic cracker

And from the world of code, I found this ColdFusion gem the other day. I’m not really sure what this guy was doing.

<cffunction name="getStatuses" access="remote" returntype="query">
	<cfscript>
	qStatuses = QueryNew("");
	QueryAddRow(qStatuses, 1);
	</cfscript>

	<cfquery name="qStatuses" dbtype="query">
		select 'Held' label, 'HELD' data from qStatuses union  all
		select 'Cancelled' label, 'CANCEL' data from qStatuses union all
		select 'Cancel Requested' label, 'CAN-REQ' data from qStatuses union all
		select 'Released' label, 'RELEASED' data from qStatuses union all
		select 'Release Requested' label, 'REL-REQ' data from qStatuses
	</cfquery>

	<cfreturn qStatuses>
</cffunction>

Oh wait, he did it so he could build a Javascript array string… from the query… instead of just… hard-coding it?

<cffunction name="getStatusesJS"  access="remote" returntype="any">
	<cftry>
		<cfset qStatuses = this.getStatuses()>

		<cfset js = "var _statuses = {};">
		<cfoutput query="qStatuses">
			<cfset js = js & "_statuses['#DATA#'] = {label:'#jsstringformat(LABEL)#',data:'#DATA#'};">
		</cfoutput>

		<cfreturn js>
    <cfcatch type="database">
   		<cfrethrow>
    </cfcatch>
    </cftry>
</cffunction>

I suppose it is far more pedestrian and not very “OOPy” to just do…

<cfset jsArray = ArrayNew(1) />
<cfset ArrayAppend(jsArray, "var _statuses = {};") />
<cfset ArrayAppend(jsArray, "_statuses['HELD'] = {label:'Held',data:'HELD'};") />
<cfset ArrayAppend(jsArray, "_statuses['CANCEL'] = {label:'Cancelled',data:'CANCEL'};") />
<cfset ArrayAppend(jsArray, "_statuses['CAN-REQ'] = {label:'Cancel Requested',data:'CAN-REQ'};") />
<cfset ArrayAppend(jsArray, "_statuses['RELEASED'] = {label:'Released',data:'RELEASED'};") />
<cfset ArrayAppend(jsArray, "_statuses['REL-REQ'] = {label:'Release Requested',data:'REL-REQ'};") />
<cfset jsString = ArrayToList(jsArray, " ") />