I'm trying to obtain rows from 3 different tables if the column 'description' in table 1 contain certain substring.
this code is working correctly and bring me the desired results:
sql = "SELECT * FROM NonMandatoryObject
JOIN Object ON Object.M_id = NonMandatoryObject.NM_id
JOIN Pictures ON Pictures.PICS_id = NonMandatoryObject.NM_id
WHERE description like '%TheSubStringIWantToSearch%' "
db.all(sql, (err, rows) => {
if (err) console.log('failure')
else {
res.send(rows)
console.log('success')
}
})
the problem is that the format of the program is to contain variables in distinct array and when I put '?' instead of variable name and provide this name the search crashes.
sql = "SELECT * FROM NonMandatoryObject
JOIN Object ON Object.M_id = NonMandatoryObject.NM_id
JOIN Pictures ON Pictures.PICS_id = NonMandatoryObject.NM_id
WHERE description like '%?%' "
arr = ['TheSubStringIWantToSearch']
db.all(sql, arr, (err, rows) => {
if (err) console.log('failure')
else {
res.send(rows)
console.log('success')
}
})
what is the proper way to insert the variable name into the sql query?
Thanks.