sql - Debugging Coldfusion Query with cfloop inside -
i'm trying debug cf query , cannot because of complex structure.the code following:
<cfquery name="qquery" datasource="#variables.datasource#"> <cfloop index="i" from="1" to="#arraylen(asql)#" step="1"> <cfif issimplevalue(asql[i])> <cfset temp = asql[i]>#trim(dmpreservesinglequotes(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="#asql[i].value#" 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>
if run <cfdump var="#qquery#">
it's not working nor cfoutput, undefined qquery error. how can find query executing behind ? don't want use ms sql profiler.
thanks,
take inside query , wrap in cfsavecontent instead. output result.
if place cfsavecontent inside cfquery tags, don't need worry cfqueryparam tags barfing, although need re-output saved content inside query. see http://coldflint.blogspot.com/2016/01/debugging-queries-dirty-way.html
basically, should have this:
<cfquery name="qquery" datasource="#variables.datasource#"> <cfsavecontent variable="sqlcontent"> <cfloop index="i" from="1" to="#arraylen(asql)#" step="1"> <cfif issimplevalue(asql[i])> <cfset temp = asql[i]>#trim(dmpreservesinglequotes(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="#asql[i].value#" 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> </cfsavecontent> #sqlcontent# </cfquery> <pre>#sqlcontent#</pre>
do make sure put normal once you're done debugging.
Comments
Post a Comment