Solved

Variable evaluation and/or substitution

Posted on 2014-04-30
16
215 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:Spleendrivel
  • 8
  • 4
  • 4
16 Comments
 
LVL 15

Expert Comment

by:myselfrandhawa
Comment Utility
There is no attachment in your question

please provide the attachment
0
 
LVL 15

Expert Comment

by:myselfrandhawa
Comment Utility
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 52

Accepted Solution

by:
_agx_ earned 270 total points
Comment Utility
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
 

Author Comment

by:Spleendrivel
Comment Utility
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:Spleendrivel
Comment Utility
Everyone,

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

Expert Comment

by:_agx_
Comment Utility
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 15

Expert Comment

by:myselfrandhawa
Comment Utility
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 52

Expert Comment

by:_agx_
Comment Utility
Oops, our posts clashed.  Didn't see your responses before posting..
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 15

Expert Comment

by:myselfrandhawa
Comment Utility
just like @agx said above, both our comments posted almost same time, so i did not saw
0
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
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 52

Expert Comment

by:_agx_
Comment Utility
(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:Spleendrivel
Comment Utility
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 52

Expert Comment

by:_agx_
Comment Utility
You're welcome. Glad I could help.
0
 

Author Comment

by:Spleendrivel
Comment Utility
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 52

Expert Comment

by:_agx_
Comment Utility
> 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 52

Expert Comment

by:_agx_
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now