2

So I've been looking around but I can't seem to find answer to a seemingly simple and probably commonly asked question. In SQLite, I have a query that I want to pass via user defined search text.

search = xChatMessageSplit[2]

c.execute("SELECT * FROM captured WHERE Nick=? AND Name LIKE '%search%'",(xChatNick,search))

Obviously the syntax or whatever is incorrect since I'm getting errors, but I want to basically allow users to define a search term for string, "search." How would I go about doing this? I tried using REGEXP but I can't seem to figure out how to define the function so I figured I'd just go with LIKE since it's already implemented into SQLite3

1 Answer 1

6

You need to use ? to show where the parameter's value will be used.

c.execute("""SELECT * FROM captured
             WHERE Nick=?
             AND Name LIKE ('%' || ? || '%')""", (xChatNick,search))
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much, I've been trying do this all day long

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.