G
G
Gimir2018-05-04 11:30:36
PostgreSQL
Gimir, 2018-05-04 11:30:36

How to add variable to SQL query with "WHERE something LIKE" in Python?

Good day!
I wanted to quickly implement book search in Flask, but I can't add a variable to the expression:

@app.route("/book-<string:book>")
def book(book):
    oneBook = db.execute("SELECT * FROM books WHERE title LIKE '%:book%' OR isbn LIKE '%:book%' OR author LIKE '%:book%'",
    {"book": book}).fetchall()

Please explain how this can be done.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question