It would be nice in the readme to specify that the function query (of the driver) needs a array of string and not a string.
ex.:
var sql = require('mssql'); sql.connect(settings)
sql.query("select * from table") //does not work
sql.query(["select * from table"]) //works
sql.query `select * from table` //works
Dang. This is my problem too. What a totally stupid API. Without which the error is...
RequestError: Could not find stored procedure 'S'.
That doesn't make any sense.
Also #552 same thing.
Btw, just to be clear with the OP @jsbinette , while
sql.query(["select * from table"]) //works
sql.query `select * from table` //works
The desired syntax I believe is to use pool.request().query(q)
const pool = await sql.connect('mssql://sa:pass@localhost:1433/master');
const req = await pool.request().query(q);
console.dir(result);
Actually they both work. My version is using the global connection.
Right, that's what I mean. Using the global-connection you have to supply an array with the SQL. Shy of that if you use the pool.request().query() you can supply a string. Which I believe is the intended method of doing it.
worse if you have the sql in a variable then
const sqlString = 'select * from table';
sql.query`${sqlString}`;
doesn't work either
Fixed and to be released in 4.2.
Thank you!
Most helpful comment
worse if you have the sql in a variable then
doesn't work either