-1

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?

elias
  • 1
  • 2
  • I'm not sure if I understand you correctly. SELECT returns rows, not columns. What exactly do you try to SELECT? Can you give a concrete example with a Table and what exactly you want to get from it? – AracKnight Oct 08 '22 at 09:36
  • See the linked duplicates for how to do this correctly and securely. – snakecharmerb Oct 08 '22 at 10:18

1 Answers1

-1

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()
chrslg
  • 9,023
  • 5
  • 17
  • 31