Sidebar

How to escape templates so script blocks and date literals are not stripped when calling evaluateTemplate or doQuery?

+1 vote
735 views
asked Sep 29, 2015 by rich-c-2789 (17,490 points)
retagged Jul 20, 2021 by rich-c-2789
When I use a template with evaluateTemplate or a ODBC date literal with doQuery the function bodies and date literals are stripped out.  How can I embed curly braces with content without it being stripped out of the result?

3 Answers

+1 vote
 
Best answer
Javascript Function Block Example:
var template = "<script>\n" +
" function updateSettings() {\n" +
"   alert('test');\n" + 
" }\n" +
"</script>";
 
qie.evaluateTemplate(template, parameters);
 
Bad Result:
<script>
function updateSettings()
</script>
 
Solution - Use numeric character references:
var template = "<script>\n" +
" function updateSettings() &#123;\n" +
" alert('test');\n" + 
" &#125;\n" +
"</script>";
 
qie.evaluateTemplate(template, parameters);
 
Good Result:
<script>
function updateSettings() {
  alert('test');
}  
</script>
answered Sep 29, 2015 by rich-c-2789 (17,490 points)
selected Dec 2, 2015 by michael-h-5027
+1 vote
SQL ODBC Date Literal Example:
qie.doQuery(dbName, "select * from person where birth = {d '2000-09-09'}");
 
Bad Result:
select * from person where birth =
 
Solution - Use numeric character references:
qie.doQuery(dbName, "select * from person where birth = &#123;d '2000-09-09'&#125;");
 
Good Result:
select * from person where birth = {d '2000-09-09'}
 
Alternatively use other supported date or date literal syntax as per database vendor.  See these Date Literal references:
answered Sep 29, 2015 by rich-c-2789 (17,490 points)
0 votes
answered Jul 20, 2021 by rich-c-2789 (17,490 points)
...