Here is my code:
var qryStr = \"
UPDATE templates_email
SET title = :title, test_emails = :testEmail, body = :body
WHERE
ColdFusion can get confused when parsing the SQL string to use parameters. The easiest way to solve this shortcoming is to put a space after each of your parameters.
Since some text editors may remove trailing whitespace, like when saving, I include an empty comment after any space at the end of a line.
var qryStr = "
UPDATE templates_email
SET title = :title , test_emails = :testEmail , body = :body /**/
WHERE id = :templateID /**/
";
The parser for getting the params doesn't tokenize on return values, only on whitespace (which is really annoying). Try the following:
var qryStr = "
UPDATE templates_email
SET title = ( :title ), test_emails = ( :testEmail ), body = ( :body )
WHERE ( id = :templateID )
";
The (
and )
should remove any issue with where the parser not being able to recognise where the :params stop and start.
This error occurs because of the tab and line break characters found in your SQL statement. I normally run below function on my SQL statement to remove these characters.
string function cleanSQL(required string sqlStatement)
output="false"
{
return trim(reReplace(arguments.sqlStatement, "\t|\n", " ", "all"));
}
So, your setSQL() can look like:
q.setSQL(cleanSQL(qryStr))
or simply:
q.setSQL(reReplace(qryStr, "\t|\n", " ", "all"))