Ich mache parametrisierte SQL-Abfragen wie folgt:
var sql = require('mssql');
var myFirstInput = "foo bar";
var mySecondInput = "hello world";
sql.input('inputField1', sql.VarChar, myFirstInput);
sql.input('inputField2', sql.VarChar, mySecondInput);
sql.query("SELECT * FROM table WHERE field1 = @inputField1 OR field2 = @inputField2")
.then(function(results)
{
//do whatever you want with the results
console.log(results)
})
.catch(function(error)
{
//do whatever when you get an error
console.log(error)
})
Was hier passiert ist, dass die sql.input('inputField1', sql.VarChar, myFirstInput) wird das @inputField1 ändern mit der Variablen namens myFirstInput . Das gleiche passiert für @inputField2 mit mySecondInput .
Dies hilft ihm bei SQL-Injektionen