0

I would like to use raw SQL command to do a query.

engine = create_engine(os.getenv("DATABASE_URL"))
db = scoped_session(sessionmaker(bind=engine))

My table name is books and title is a column in it. I have got the value of detail from a form.

detail=request.form.get("detail")
book=db.execute("SELECT title FROM books WHERE title = :detail",{"detail":detail})

What i want is to run this query with LIKE command such that I can have title as LIKE detail, that is, I want something like:

book=db.execute("SELECT title FROM books WHERE title LIKE *:detail*",{"detail":detail})

to have value of title to be comprising of characters of detail and some characters before and after denoted by * as wildcards. Could you help me to achieve this, remember I want to use raw SQL commands only.

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
dewDevil
  • 381
  • 1
  • 3
  • 12
  • (1) Use `%` instead of `*` as your wildcard character. (2) Include the wildcard characters in the parameter value, not in the command text. – Gord Thompson Jun 27 '20 at 15:31
  • Here're examples of that: https://stackoverflow.com/questions/51463912/cs50-like-operator-variable-substitution-with-expansion – Ilja Everilä Jun 27 '20 at 15:43

0 Answers0