Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Using sqlite3, if my query is

SELECT * FROM table WHERE title LIKE '%x%'

It will match strings that contain x. I want to make x a bindable parameter, like:

SELECT * FROM table WHERE title LIKE '%x?%'

However, this does not work since the '' form a string literal. Is there some way of escaping the ? within the literal? I understand that I could build the bindable parameter to contain the % and then use

SELECT * FROM table WHERE title LIKE ?

but this moves the responsibility into my code in terms of handling SQL injections rather than the bind interface. Is there a nicer solution for this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
371 views
Welcome To Ask or Share your Answers For Others

1 Answer

SELECT * FROM table WHERE title LIKE '%' || ? || '%';

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...