I'm trying to read from my database using the sqlite3 package in NodeJS. In the code I have:
var sqlite = require('sqlite3');
var db = new sqlite.Database('myDatabase.db');
var someUserInput = 'Some given id by the user';
db.all(
'SELECT * FROM MyTable WHERE userId="' + someUserInput + '"',
function(err, rows) { /* Do something here */});
Instead of directly adding the user input, I would like to be able to prepare the statement properly, in order to avoid any malicious input from the user.
I have tried:
db.prepare('SELECT * FROM MyTable WHERE userId=?', someUserInput).sql
But that still gives me:
'SELECT * FROM MyTable WHERE userId=?'
With no replacement from the input.
Thanks!