forked from misterdai/cfbackport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cf11.cfm
63 lines (51 loc) · 2.13 KB
/
cf11.cfm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!--- CF11 functions for CF9+ --->
<cffunction name="QueryExecute" output="false" returntype="query"
hint="
* result struct is returned to the caller by utilizing URL scope (no prefix needed) *
https://wikidocs.adobe.com/wiki/display/coldfusionen/QueryExecute">
<cfargument name="sql_statement" required="true">
<cfargument name="queryParams" default="#structNew()#">
<cfargument name="queryOptions" default="#structNew()#">
<cfset var parameters = []>
<cfif isArray(queryParams)>
<cfloop array="#queryParams#" index="local.param">
<cfif isSimpleValue(param)>
<cfset arrayAppend(parameters, {value=param})>
<cfelse>
<cfset arrayAppend(parameters, param)>
</cfif>
</cfloop>
<cfelseif isStruct(queryParams)>
<cfloop collection="#queryParams#" item="local.key">
<cfif isSimpleValue(queryParams[key])>
<cfset arrayAppend(parameters, {name=local.key, value=queryParams[key]})>
<cfelse>
<cfset var parameter = {name=key}>
<cfset structAppend(parameter, queryParams[key])>
<cfset arrayAppend(parameters, parameter)>
</cfif>
</cfloop>
<cfelse>
<cfthrow message="unexpected type for queryParams">
</cfif>
<cfif structKeyExists(queryOptions, "result")>
<!--- strip scope, not supported --->
<cfset queryOptions.result = listLast(queryOptions.result, '.')>
</cfif>
<cfset var executeResult = new Query(sql=sql_statement, parameters=parameters, argumentCollection=queryOptions).execute()>
<cfif structKeyExists(queryOptions, "result")>
<!--- workaround for passing result struct value out to the caller by utilizing URL scope (no prefix needed) --->
<cfset URL[queryOptions.result] = executeResult.getPrefix()>
</cfif>
<cfreturn executeResult.getResult()>
</cffunction>
<cffunction name="QueryGetRow" output="false" returntype="struct"
hint="https://wikidocs.adobe.com/wiki/display/coldfusionen/QueryGetRow">
<cfargument name="query" type="query" required="true">
<cfargument name="row" type="numeric" default="1">
<cfset var struct = {}>
<cfloop list="#query.columnList#" index="local.col">
<cfset struct[col] = query[col][row]>
</cfloop>
<cfreturn struct>
</cffunction>