Jeg laver parameteriserede SQL-forespørgsler som denne:
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)
})
Det, der sker her, er, at sql.input('inputField1', sql.VarChar, myFirstInput) vil ændre @inputField1 med variablen ved navn myFirstInput . Det samme vil ske for @inputField2 med mySecondInput .
Dette vil hjælpe det fra SQL-injektioner