[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Variable evaluation and/or substitution

Posted on 2014-04-30
16
Medium Priority
?
256 Views
Last Modified: 2014-05-01
The following code produces an error when run on ColdFusion 9.0.2.  The error occurs on the #QueryName# evaluation, the #Component# seems to work fine.  I am not sure if the name attribute for CFQUERY is having trouble with dynamic names or ???

<CFQUERY name="GetCOMP" datasource="brsdb">
      select *
      from LU_component
      where component not like '%SUMMARY%'
      order by SortOrder
</CFQUERY>

<CFOUTPUT query="GetCOMP">
      <CFQUERY name="#QueryName#" datasource="brsdb">
            exec SP_BRS_REPORTING_DETAIL '#form.year#','#form.month#','#form.fund#','Direct','#Component#','#form.bbfy#'
      </CFQUERY>
</CFOUTPUT>

The error produced can be found in the attached PDF representing a captured screen shot.
0
Comment
Question by:Dave McConnell
  • 8
  • 4
  • 4
16 Comments
 
LVL 16

Expert Comment

by:Gurpreet Singh Randhawa
ID: 40032104
There is no attachment in your question

please provide the attachment
0
 
LVL 16

Expert Comment

by:Gurpreet Singh Randhawa
ID: 40032132
better for this:
<CFOUTPUT query="GetCOMP">
      <CFQUERY name="#QueryName#" datasource="brsdb">
            exec SP_BRS_REPORTING_DETAIL '#form.year#','#form.month#','#form.fund#','Direct','#Component#','#form.bbfy#'
      </CFQUERY>
</CFOUTPUT>

Open in new window

better to do the cfloop list of the query so you can refer them with scope and use it
0
 
LVL 53

Accepted Solution

by:
_agx_ earned 1080 total points
ID: 40032144
I don't see an attachment.  

As long as #QueryName# is a valid variable name (starts with a letter, no special characters, ... ) it should be fine. Though you don't even need a query "name" unless the procedure returns a resultset you want to capture and use elsewhere.

That said, its typically better to use cfstoredproc for stored procedures.  If you still prefer cfquery, for some reason, always use cfqueryparam on all client variables to protect your db against sql injection.
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 

Author Comment

by:Dave McConnell
ID: 40032445
I have attached the error from my screen shot.  It is possible that #QueryName# should work, but it does not in my case.  If I replace this with text it will process all 30+ query records and process the #Component# without a problem.

Btw, the app is for internal use on our internal network, absolutely no public access, most of our security is at network level.  Thanks for the heads up though.
1-9-2014-9-29-38-AM.jpg
0
 

Author Comment

by:Dave McConnell
ID: 40032457
Everyone,

Please be aware that "QueryName" and "Component" are actual columns within the SQL Server 2008 R2 table "LU_COMPONENT".
0
 
LVL 53

Expert Comment

by:_agx_
ID: 40032500
As long as #QueryName# is a valid variable name (starts with a letter, no special characters, ... ) it should be fine.

We need to see the error message to be certain, but from what you described its likely an issue w/the values used for #QueryName#. They must conform to the rules for variable names (start with a letter, no spaces, etc... The example below works fine with valid names like "QueryA", etc...

<cfset myDSN = "Some DSN Name">

<!--- dummy variables for testing --->
<cfset form.year = 2014>
<cfset form.month = 4>
<!--- simulate query --->
<cfset GetCOMP = queryNew("")>
<cfset queryAddColumn(GetCOMP, "QueryName", ["QueryA","QueryB","QueryC"])>

<!--- test query name--->
<CFOUTPUT query="GetCOMP">
      <CFQUERY name="#QueryName#" datasource="#myDSN#">
                  <!--- Be sure to use cfqueryparm in real code ! --->
            SELECT '#form.year#' AS YearNunber,'#form.month#' AS MonthNumber
      </CFQUERY>
        <cfdump var="#variables[QueryName]#">
</CFOUTPUT>
0
 
LVL 16

Expert Comment

by:Gurpreet Singh Randhawa
ID: 40032507
That is not coldfusion associated error, probably keep the cfdump after your cfquery to see what you are getting and do not generate any pdf or flashapaper unless you see the results whatever you need to
0
 
LVL 53

Expert Comment

by:_agx_
ID: 40032509
Oops, our posts clashed.  Didn't see your responses before posting..
0
 
LVL 16

Expert Comment

by:Gurpreet Singh Randhawa
ID: 40032515
just like @agx said above, both our comments posted almost same time, so i did not saw
0
 
LVL 53

Expert Comment

by:_agx_
ID: 40032538
Btw, the app is for internal use on our internal network, absolutely no public access, most of our security is at network level.  Thanks for the heads up though.

Better safe than sorry IMO. Also cfqueryparam/cfstored is recommended to improve performance. By using bind variables, it enables db's like sql server to cache and reuse execution plans, so it doesn't have to recompile them, boosting performance.
0
 
LVL 53

Expert Comment

by:_agx_
ID: 40032546
(EDIT) After reading your responses, I think my comments about variable names may still apply.  But I think you accidentally posted the wrong image. That error is about VS setup, not CF. Can you post the full CF error message?
0
 

Author Closing Comment

by:Dave McConnell
ID: 40032574
agx,

Thank you for all your help, the solution was right in front of me.  I had inserted dashes in some of the query name column values, and of course this was causing CFQUERY to produce an error when attempting to process this as the name attribute.

And I would also like to thank you for providing additional tips on how best to code with ColdFusion for a variety of reasons.

Others may have provided a similar solution but agx was the first to respond with a viable solution.

Thanks everyone,
0
 
LVL 53

Expert Comment

by:_agx_
ID: 40032962
You're welcome. Glad I could help.
0
 

Author Comment

by:Dave McConnell
ID: 40034650
agx,

Well it was working and now I am seeing that damn 500 error again.  I have provided a list of columns and values from the GetCOMP query to show what I am using for the QueryName value.  It runs fine unless I add a simply CFOUTPUT tag to use the query, then I error out again.

ReportTitle = "OIG SUMMARY" - QueryName = "OIGSUMMARY" - Component = "OIG SUMMARY"
ReportTitle = "JA Summary" - QueryName = "JASUMMARY" - Component = "JA SUMMARY"
ReportTitle = "JI Summary" - QueryName = "JISUMMARY" - Component = "JI SUMMARY"
ReportTitle = "JP Summary" - QueryName = "JPSUMMARY" - Component = "JP SUMMARY"
ReportTitle = "OFFICE J" - QueryName = "JQUERY" - Component = "J"
ReportTitle = "OFFICE JC" - QueryName = "JCQUERY" - Component = "JC"
ReportTitle = "OFFICE JE" - QueryName = "JEQUERY" - Component = "JE"
ReportTitle = "OFFICE JA" - QueryName = "JAQUERY" - Component = "JA"
ReportTitle = "OFFICE JA-2" - QueryName = "JA2QUERY" - Component = "JA-2"
ReportTitle = "OFFICE JA-3" - QueryName = "JA3QUERY" - Component = "JA-3"
ReportTitle = "OFFICE JA-4" - QueryName = "JA4QUERY" - Component = "JA-4"
ReportTitle = "OFFICE JA-5" - QueryName = "JA5QUERY" - Component = "JA-5"
ReportTitle = "OFFICE JA-6" - QueryName = "JA6QUERY" - Component = "JA-6"
ReportTitle = "OFFICE JA-7" - QueryName = "JA7QUERY" - Component = "JA-7"
ReportTitle = "OFFICE JA-9" - QueryName = "JA9QUERY" - Component = "JA-9"
ReportTitle = "OFFICE JA-A" - QueryName = "JAAQUERY" - Component = "JA-A"
ReportTitle = "OFFICE JA-F" - QueryName = "JAFQUERY" - Component = "JA-F"
ReportTitle = "OFFICE JA-P" - QueryName = "JAOQUERY" - Component = "JA-P"
ReportTitle = "OFFICE JA-R" - QueryName = "JAPQUERY" - Component = "JA-R"
ReportTitle = "OFFICE JAO" - QueryName = "JARQUERY" - Component = "JAO"
ReportTitle = "OFFICE JAS" - QueryName = "JASQUERY" - Component = "JAS"
ReportTitle = "OFFICE JI" - QueryName = "JIQUERY" - Component = "JI"
ReportTitle = "OFFICE JI-1" - QueryName = "JI1QUERY" - Component = "JI-1"
ReportTitle = "OFFICE JI-2" - QueryName = "JI3QUERY" - Component = "JI-2"
ReportTitle = "OFFICE JI-3" - QueryName = "JI4AQUERY" - Component = "JI-3"
ReportTitle = "OFFICE JI-4" - QueryName = "JI4QUERY" - Component = "JI-4"
ReportTitle = "OFFICE JI-4-A" - QueryName = "JI5QUERY" - Component = "JI-4-A"
ReportTitle = "OFFICE JI-5" - QueryName = "JI6QUERY" - Component = "JI-5"
ReportTitle = "OFFICE JI-6" - QueryName = "JI7QUERY" - Component = "JI-6"
ReportTitle = "OFFICE JI-7" - QueryName = "JI8QUERY" - Component = "JI-7"
ReportTitle = "OFFICE JI-8" - QueryName = "JI9AQUERY" - Component = "JI-8"
ReportTitle = "OFFICE JI-9" - QueryName = "JI9BQUERY" - Component = "JI-9"
ReportTitle = "OFFICE JI-9-A" - QueryName = "JI9QUERY" - Component = "JI-9-A"
ReportTitle = "OFFICE JI-9-B" - QueryName = "JI10QUERY" - Component = "JI-9-B"
ReportTitle = "OFFICE JI-10" - QueryName = "JI2QUERY" - Component = "JI-10"
ReportTitle = "OFFICE JI-W" - QueryName = "JIBQUERY" - Component = "JI-W"
ReportTitle = "OFFICE JIB" - QueryName = "JIIQUERY" - Component = "JIB"
ReportTitle = "OFFICE JII" - QueryName = "JIWQUERY" - Component = "JII"
ReportTitle = "OFFICE JP" - QueryName = "JPQUERY" - Component = "JP"
ReportTitle = "OFFICE JPB" - QueryName = "JPBQUERY" - Component = "JPB"
ReportTitle = "OFFICE JPC" - QueryName = "JPCQUERY" - Component = "JPC"
ReportTitle = "OFFICE JPE" - QueryName = "JPEQUERY" - Component = "JPE"
ReportTitle = "OFFICE JPF" - QueryName = "JPFQUERY" - Component = "JPF"
ReportTitle = "OFFICE JPH" - QueryName = "JPHQUERY" - Component = "JPH"
ReportTitle = "OFFICE JPM" - QueryName = "JPMQUERY" - Component = "JPM"
ReportTitle = "OFFICE NOT DEFINED" - QueryName = "UNDQUERY" - Component = "NOT DEFINED"


		<CFOUTPUT QUERY="GETCOMP">
			<H4 align="left">
				<font color="AB562F" size='5' face="Calibri">
					ReportTitle = "#getcomp.ReportTitle#" - QueryName = "#getcomp.QueryName#" - Component = "#getcomp.Component#" 
				</font>
			</H4>
			<CFOUTPUT query="#getcomp.QueryName#">
			</CFOUTPUT>
		</CFOUTPUT>

Open in new window


Any suggestions,
0
 
LVL 53

Expert Comment

by:_agx_
ID: 40034889
> 500 error

Well, as you probably know 500 is just a generic error. What is the actual detail message you're getting? Either

a) check the log files, usually {cfroot}\logs\exception.log OR
b) if you're on a dev environment, disable error handling so you can see the error OR
c) wrap the offending code in a cftry/cfcatch and dump the error in the cfcatch clause.

Then post the error here.

     <cftry>
          ... code causing the error
         <cfcatch>
               <cfdump var="#cfcatch#">
         <cfcatch>
     </cftry>
0
 
LVL 53

Expert Comment

by:_agx_
ID: 40034908
Oh, wait... I see at least one problem. You cannot nest <cfoutput> tags if they both use the "query" attribute. Instead, replace the inner <cfoutput> with a <cfloop>

<CFOUTPUT QUERY="GETCOMP">
     <H4 align="left">....</H4>
     <CFLOOP query="#getcomp.QueryName#">
     </CFLOOP>
</CFOUTPUT>

If you run into other errors, post the error messages from the logs or cftry/cfcatch
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
In this video I will demonstrate how to set up Nine, which I now consider the best alternative email app to Touchdown.
Suggested Courses

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question