I need to make a JavaScript string which is passed into Node.js friendly for MSSQL.
This question: Making a javascript string sql friendly has a great answer that explains how to escape strings for MySQL:
Credit to Paul D'Aoust
function mysql_real_escape_string (str) {
return str.replace(/[\0\x08\x09\x1a\n\r"'\\\%]/g, function (char) {
switch (char) {
case "\0":
return "\\0";
case "\x08":
return "\\b";
case "\x09":
return "\\t";
case "\x1a":
return "\\z";
case "\n":
return "\\n";
case "\r":
return "\\r";
case "\"":
case "'":
case "\\":
case "%":
return "\\"+char; // prepends a backslash to backslash, percent,
// and double/single quotes
}
});
}
I need to achieve the exact same thing for MSSQL.
I have spent the last hour (probably longer) searching for an answer however, there does not seem to be a lot of documentation on the internet that explains how to do this. The official mssql package documentation only mentions prepared statements however, I want to find a way to do this without prepared statements.