Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

resolving CFML code from a query reult

Status
Not open for further replies.

vin75

IS-IT--Management
Joined
Apr 20, 2001
Messages
2
Location
NL
Hi,

I'm having trouble resolving CFML-code which comes as a query result from a database. The code is now simply passed to the webserver without resolving it. As you can imagine I want the cfml-code to be processed before passing it to the webserver. Using the evaluate function appears not to be an option, since it generates an error. Strange thing is that when the query result only contains a coldfusion function (like dateadd()) the result is resolved by using the evaluate function

Anyone??

Vin
 
CFML code has to be in a .cfm file to be parsed by the CF server. Otherwise, you're just providing a string to the result stream. You can perform all of the string functions on the returned data, but that doesn't mean you can parse it.

Think of it this way:

Request for CFM page -> Web server passes to CF server -> CF server reads and interprets the contents of the CFM page -> (at this point, the die is cast) -> CF server performs the actions stipulated in the CF page -> CF server returns HTML to the Web server

You can write the results of your query to a file, and call it with CFINCLUDE. I believe there are other functions or approaches, but I'm two versions behind the curve here.

HTH,

Phil Hegedusich
Senior Web Developer
IIMAK
<a href=&quot;-----------
Boy howdy, my Liberal Studies degree really prepared me for all of this....
 
If I understand what you're trying to do, Vin... you're storing CFML in a field in a DB record, and you want to process that CFML when you return that record via a query. Is that right?

First, it's never really a good idea to store such code in a database. For one, code is more apt to contain special characters which will cause your database to have fits. For another, it's just not terribly efficient. Imagine storing the code
Code:
 <CFSET myString = &quot;Some string&quot;>
 <CFSET myID = &quot;#qrySomeQuery.id#&quot;>
 <CFOUTPUT>#myString# #myID#</CFOUTPUT>
Not only would you save space in your table if you were to just save myString in it's own field, myID in it's own field, and then produce the output once the query has been returned, but you're also more prone to blow up your code... since you really don't know that you need access to &quot;qrySomeQuery&quot;, for example, until you return the resultset... and what if it doesn't exist?


But... I'm sure you took all this into consideration. So, to answer your original question...
Code:
Evaluate()
is definitely what you're after. If you're getting errors, it's probably because the CFML is malformed, or you forgot to escape a poundsign somewhere.
Another function that may or may not come into play is
Code:
DE()
... it stands for &quot;Delayed Execution&quot;. Basically is makes ColdFusion look at the entire string of CFML before it tries to process it, instead of doing &quot;just-in-time&quot; processing. This allows DE to escape all the poundsigns and quotes before you try to evaluate it.

Try:
Code:
  <CFSET sOutput = Evaluate(DE(qryMyQuery.code))>

You didn't mention the exact errors you're getting... but if they are what I think they are, that'll fix them.

One final note... Evaluate() is dreadfully slow. Yet another reason not to store CFML in a database.



-Carl
 
You can't execute cfml tags with Evaluate(); just functions.

This won't work:
Code:
<cfset mycode = &quot;<cfset a = 1>&quot;>
<cfoutput>#Evaluate(mycode)#</cfoutput>
but this will:
Code:
<cfset mycode = &quot;a = 1&quot;>
<cfoutput>#Evaluate(mycode)#</cfoutput>

-Tek
 
Sorry, wrong example. The second example (the one that works) should be replaced by:
Code:
<cfset mycode = &quot;a = 1&quot;>
<cfset myresult = Evaluate(mycode)>
<cfoutput>
#Evaluate(a)#
</cfoutput>

-Tek
 
Okay, I am having one of those days -- let's try again!
Code:
<cfset mycode = &quot;a = 1&quot;>
<cfset myresult = Evaluate(mycode)>
<cfoutput>
#a#
</cfoutput>
The Evaluate() function wasn't necessary to output the value of &quot;a&quot;.

-Tek
 
I must be having one of those days, too, Tek... I knew evaluating tags wouldn't work... but tunnelvision struck.

My only excuse is I'm half asleep. [sleeping]


-Carl
 
The only solution to evaluate actual cfml tags is to write the returned data to a file and use cfinclude on that file, as far as I know. I've never had to use this idea, though, but this is always what others have to do, based on my experience with every answer I've seen to this question.

-Tek
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top