问题
I am using React Native and am querying a SQLite database.
I wish to perform a like query, specifying the search term as a parameter.
The below works fine with the ? notation.
SELECT * from People WHERE Name = ?
This does not work or any similar variation I've tried:
SELECT * from People WHERE Name LIKE '%?%'
Anyone know how to do this properly please? Please no interpolations or suggestions open to SQL injection.
回答1:
You can do string concatenation in SQLite:
SELECT * from People WHERE Name LIKE '%' || ? || '%'
Another option is to concatenate the percent marks with the parameter in your javascript code before passing it to the query, so you can then do:
SELECT * from People WHERE Name LIKE ?
来源:https://stackoverflow.com/questions/59686415/how-to-do-a-like-query-in-sqlite-in-javascript-whilst-passing-in-the-search-te