1

I am trying to query the Database for a sub-string, I am substituting a string variable from a form for the query. It is giving me a syntax error.

This is the error:

LINE 1: SELECT * FROM books WHERE title LIKE '%'sometext'%'
[SQL: SELECT * FROM books WHERE title LIKE '%%''%(form)s''%%']
[parameters: {'form': 'some'}]

This is the query:

books = db.execute("SELECT * FROM books WHERE title LIKE '%:form%'", {"form":form.search.data}).fetchall()

If I use an actual string in the SQL query it works. It is an issue with using a variable. Any assistance would be appreciated.

Pierre
  • 460
  • 4
  • 11

1 Answers1

0

you could try using concat for avoid quote and windchar issue

books = db.execute("SELECT * 
      FROM books 
      WHERE title LIKE concat('%',:form, '%')" , 
     ........
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107