Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python flask how can i insert a variable in LIKE sql

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

You shouldn’t have quotes around :text:

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading