You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const{ format, escape }=require('sqlstring')constsearchWord='word%'// Only want to search end of like "abcword%".constsql=format(`SELECT * FROM ?? WHERE ?? LIKE ?`,['table','content',`%${escape(searchWord)}`])console.log(sql)// SELECT * FROM `table` WHERE `content` LIKE '%\'word%\''
Expected output
// SELECT * FROM tableWHEREcontentLIKE '%word\%'
Actual output
// SELECT * FROM tableWHEREcontentLIKE '%\'word%\''
Any idea?
The text was updated successfully, but these errors were encountered:
Escape function only escapes a value into a sql value. You need to escape the various characters used in LIKE if you don't want them to be special just like with REGEXP.
Expected output
// SELECT * FROM
tableWHERE
contentLIKE '%word\%'
Actual output
// SELECT * FROM
tableWHERE
contentLIKE '%\'word%\''
Any idea?
The text was updated successfully, but these errors were encountered: