I want to do a partial search with python sqlite3. My initial query is:
cur.execute("SELECT * FROM book WHERE title=? OR author=? OR year=? OR isbn=?", (title, author, year, isbn))
Then I tried using the LIKE keyword and string formatting to obtain partial search results for the title, like this:
cur.execute("SELECT * FROM book WHERE title LIKE ? OR author=? OR year=? OR isbn=?", ('%{}%'.format(title), author, year, isbn))
As in https://stackoverflow.com/a/20904256/13290801
This seems to do the trick for title, but now when searching on the other parameters, it's not working at all although there is no error on the terminal. What am I missing?
EDIT I tried the answer posted by @forpas, but it gives me the same results.
So my new code for my search function is:
def search(title="", author="", year="", isbn=""):
conn = sqlite3.connect('books.db')
cur = conn.cursor()
cur.execute("SELECT * FROM book WHERE title LIKE '%' || ? || '%' OR author=? OR year=? OR isbn=?", (title, author, year, isbn))
It works for title. If I search for "amst", I get the Amsterdam title:

