Skip to content

Instantly share code, notes, and snippets.

@bdw429s
Created June 11, 2015 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdw429s/3003ba56073d759b39aa to your computer and use it in GitHub Desktop.
Save bdw429s/3003ba56073d759b39aa to your computer and use it in GitHub Desktop.
Stored Procedure Shim for Railo
<cfcomponent displayName="Stored Procedure Shim for Railo" accessors="true">
<cfproperty name="datasource" type="string" required="true" default="">
<cfproperty name="procedure" type="string" required="true" default="">
<cfproperty name="username" type="string" required="false" default="">
<cfproperty name="password" type="string" required="false" default="">
<cfproperty name="params" type="array" required="false">
<cfproperty name="procResults" type="array" required="false">
<cfproperty name="procResultSets" type="struct" required="false">
<cfscript>
public void function init(dataSource, procedure) {
setParams( [] );
setProcResults( [] );
setProcResultSets( {} );
variables.procResultNames = [];
variables.dataSource = arguments.dataSource;
variables.procedure = arguments.procedure;
}
public void function addParam( string cfsqltype="cf_sql_varchar", string type="in", required value ) {
arrayAppend( variables.params, arguments );
}
public void function addProcResult( required string name, numeric resultset=1 ) {
arrayAppend( variables.procResults, arguments );
arrayAppend( variables.procResultNames, arguments.name );
}
</cfscript>
<cffunction name="execute" access="public" returnType="any">
<cfset var params = getParams()>
<cfset var procResults = getProcResults()>
<cfstoredproc procedure="#variables.procedure#" datasource="#variables.datasource#">
<cfloop array="#params#" index="local.param">
<cfprocparam attributeCollection="#local.param#">
</cfloop>
<cfloop array="#procResults#" index="local.procResult">
<cfprocresult attributeCollection="#local.procResult#">
</cfloop>
</cfstoredproc>
<cfloop array="#variables.procResultNames#" index="local.procResultName">
<cfset variables.procResultSets[ local.procResultName ] = variables[ local.procResultName ]>
</cfloop>
<cfreturn this>
</cffunction>
</cfcomponent>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment