Error using Query Parameters with cfscript query

前端 未结 3 1159
后悔当初
后悔当初 2021-01-17 18:27

Here is my code:

var qryStr = \"
            UPDATE templates_email 
            SET title = :title, test_emails = :testEmail, body = :body
            WHERE         


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-17 18:53

    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"))
    

提交回复
热议问题