-
Notifications
You must be signed in to change notification settings - Fork 8
/
DataMgrEngine_openbd.cfc
51 lines (40 loc) · 3.37 KB
/
DataMgrEngine_openbd.cfc
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
<cfcomponent>
<cffunction name="runSQL" access="public" returntype="any" output="no" hint="I run the given SQL.">
<cfargument name="sql" type="string" required="yes">
<cfset var qQuery = 0>
<cfset var thisSQL = "">
<cfif Len(arguments.sql)>
<cfif StructKeyExists(variables,"username") AND StructKeyExists(variables,"password")>
<cfquery name="qQuery" datasource="#variables.datasource#" preservesinglequotes="true" username="#variables.username#" password="#variables.password#">#Trim(arguments.sql)#</cfquery>
<cfelse>
<cfquery name="qQuery" datasource="#variables.datasource#" preservesinglequotes="true">#Trim(arguments.sql)#</cfquery>
</cfif>
</cfif>
<cfif IsDefined("qQuery") AND isQuery(qQuery)>
<cfreturn qQuery>
</cfif>
</cffunction>
<cffunction name="runSQLArray" access="public" returntype="any" output="no" hint="I run the given array representing SQL code (structures in the array represent params).">
<cfargument name="sqlarray" type="array" required="yes">
<cfset var qQuery = 0>
<cfset var i = 0>
<cfset var ii = 0>
<cfset var temp = "">
<cfset var aSQL = cleanSQLArray(arguments.sqlarray)>
<cftry>
<cfif ArrayLen(aSQL)>
<cfif StructKeyExists(variables,"username") AND StructKeyExists(variables,"password")>
<cfquery name="qQuery" datasource="#variables.datasource#" preservesinglequotes="true" username="#variables.username#" password="#variables.password#"><cfloop index="i" from="1" to="#ArrayLen(aSQL)#" step="1"><cfif IsSimpleValue(aSQL[i])><cfset temp = aSQL[i]>#Trim(temp)#<cfelseif IsStruct(aSQL[i])><cfset aSQL[i] = queryparam(argumentCollection=aSQL[i])><cfswitch expression="#aSQL[i].cfsqltype#"><cfcase value="CF_SQL_BIT">#getBooleanSqlValue(aSQL[i].value)#</cfcase><cfcase value="CF_SQL_DATE,CF_SQL_DATETIME">#CreateODBCDateTime(aSQL[i].value)#</cfcase><cfdefaultcase><!--- <cfif ListFindNoCase(variables.dectypes,aSQL[i].cfsqltype)>#Val(aSQL[i].value)#<cfelse> ---><cfqueryparam value="#sqlvalue(aSQL[ii].value,aSQL[ii].cfsqltype)#" cfsqltype="#aSQL[i].cfsqltype#" maxlength="#aSQL[i].maxlength#" scale="#aSQL[i].scale#" null="#aSQL[i].null#" list="#aSQL[i].list#" separator="#aSQL[i].separator#"><!--- </cfif> ---></cfdefaultcase></cfswitch></cfif> </cfloop></cfquery>
<cfelse>
<cfquery name="qQuery" datasource="#variables.datasource#" preservesinglequotes="true"><cfloop index="i" from="1" to="#ArrayLen(aSQL)#" step="1"><cfif IsSimpleValue(aSQL[i])><cfset temp = aSQL[i]>#Trim(temp)#<cfelseif IsStruct(aSQL[i])><cfset aSQL[i] = queryparam(argumentCollection=aSQL[i])><cfswitch expression="#aSQL[i].cfsqltype#"><cfcase value="CF_SQL_BIT">#getBooleanSqlValue(aSQL[i].value)#</cfcase><cfcase value="CF_SQL_DATE,CF_SQL_DATETIME">#CreateODBCDateTime(aSQL[i].value)#</cfcase><cfdefaultcase><!--- <cfif ListFindNoCase(variables.dectypes,aSQL[i].cfsqltype)>#Val(aSQL[i].value)#<cfelse> ---><cfqueryparam value="#sqlvalue(aSQL[ii].value,aSQL[ii].cfsqltype)#" cfsqltype="#aSQL[i].cfsqltype#" maxlength="#aSQL[i].maxlength#" scale="#aSQL[i].scale#" null="#aSQL[i].null#" list="#aSQL[i].list#" separator="#aSQL[i].separator#"><!--- </cfif> ---></cfdefaultcase></cfswitch></cfif> </cfloop></cfquery>
</cfif>
</cfif>
<cfcatch>
<cfthrow message="#CFCATCH.Message#" detail="#CFCATCH.detail#" extendedinfo="#readableSQL(aSQL)#">
</cfcatch>
</cftry>
<cfif IsDefined("qQuery") AND isQuery(qQuery)>
<cfreturn qQuery>
</cfif>
</cffunction>
</cfcomponent>