Wykonuję sparametryzowane zapytania SQL w ten sposób:
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)
})
Dzieje się tak, że sql.input('inputField1', sql.VarChar, myFirstInput) zmieni @inputField1 ze zmienną o nazwie myFirstInput . To samo stanie się z @inputField2 z mySecondInput .
Pomoże mu to w przypadku wstrzyknięć SQL