I have a Db from where I have to display all the columns which match the substring of the column given by user.
The following code works:
c.execute("select *from Transactions where Description like '%sh%' ") conn.commit() print(c.fetchall()) conn.close()
But when I try to run this code it returns me an empty list:
def search(col,val): conn = sqlite3.connect('test.db') c = conn.cursor() c.execute("Select *from Transactions where ? Like ? ",(col,'%'+val+'%')) print(c.fetchall()) search('description',"sh")
Also the result will always be a blank list even if the col name is wrong. as opposed the usual error which says column not found.