Home > Net >  Python flask how can i insert a variable in LIKE sql
Python flask how can i insert a variable in LIKE sql

Time:11-26

Im struggeling on this problem with excuting sql in my flask python app.

Im trying to excecute a like function with a variable that im recieving from my get reqs.

for example i've tried this yet :

rows = cursor.execute(f"SELECT * FROM vragen WHERE vraag LIKE ':text'",
                      {"text": '%'   query   '%'}).fetchall()

but this gives me an empty array unfortunately.

This gives me data but then im not using a variable which i need in this case.

rows = cursor.execute(f"SELECT * FROM vragen WHERE vraag LIKE '%which%'").fetchall()

Does anyone know an easy to way to solve this?

Thanks for advance

CodePudding user response:

You shouldn't have quotes around :text:

rows = cursor.execute(f"SELECT * FROM vragen WHERE vraag LIKE :text",
                      {"text": '%'   query   '%'}).fetchall()
  • Related