Created
June 11, 2015 22:11
-
-
Save bdw429s/3003ba56073d759b39aa to your computer and use it in GitHub Desktop.
Stored Procedure Shim for Railo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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