I am working on a function which takes an string input, and then returns the name of the column in a database which contains that string.
con =sqlite3.connect('library.db')
cur = con.cursor()
data=cur.execute('''SELECT * FROM table1''')
def search_word():
word = input("Input search word")
for column in data.description:
cur.execute('''SELECT ? FROM table1 WHERE ?=?''',(str(column[0]),str(column[0]),str(word),))
output = cur.fetchone()
print(output)
search_word()
In the above function, inputting print(column[0]) successfully prints the name of every column in the table, so I know that part of the function works. However, when I run the function with a a search word I know is in the database, every iteration produces "None" as an output. What am I doing wrong?