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

Searching by keyword in sqlite3 and python

I am trying to search in my db by a keyword in sqlite3. But I am not able to do this. After creating the connection and cursor I use this line to try and get the columns I am looking for:
curs.execute(f"""SELECT * FROM {table_name} WHERE column1 LIKE {key_word}""").fetchall().
But when doing this I get the error:
sqlite3.OperationalError: no such column: test3.
Where test3 is the keyword I used here. I don’t understand this error since I want to search the column: "column1".
Can somebody please help me with this?

>Solution :

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

Not clear what you are trying to do. In particular your usage of LIKE with a simple keyword.
But from a syntax point of view, you are missing some quotes (and probably some %, but that is up to you) around "test3".

curs.execute(f"""SELECT * FROM {table_name} WHERE column1 LIKE '{key_word}'""").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