Passing querytext as a function argument OR When is a string not a string?
Today I wrote a function that added in default rows to a query. Part of the function needed the text of a query to find the default values. I attempted to pass in the query text and use the same text in a <cfquery> tag.
This did not work.
Here is the query I passed in:
Here is the resulting error:
After a few minutes, I figured out the query worked fine if I left the criteria out. This worked:
Well, it kinda worked. It parsed and executed fine but I obviously got more records than I wanted. I expected it was a wierd parsing error and then used chr() function to replace the single quotes AND the equal sign. Nada.
The final product that worked with the criteria was to use toString(). <cfsavecontent> would probably work also.
2 #toString( arguments.SQLForRowTypes)#
3 </cfquery>
It was not obvious this wouldn't work without the toString(). I could dump the arguments scope and see the query text VERBATIM. I could also copy the cfdumped text and paste it directly in QueryAnalyzer and it also ran. I am still scratching my head over this one.
There are no comments for this entry.
@Sean,
You are correct sir!
Due to my nearly rabid use of cfqueryparam, I'd placed preserveSingleQuotes on the back burner. Thanks for reminding me.
dw
From the Docs:
Prevents ColdFusion from automatically escaping single-quotation mark characters that are contained in a variable. ColdFusion does not evaluate the argument.





Sez : Dan Wilson
March 22, 2007 5:33 PM
Suscribe
Follow Us
Contact
Isn't this what preserveSingleQuotes() is for?
http://cfquickdocs.com/?getDoc=PreserveSingleQuote...