I would like to allow users to query a sql database. The database is here
So the user will be able to enter the queries they want:
csr_city= input("Enter a city >>").lower().strip().replace(' ','')
csr_type = input("Enter a type >>").lower().strip()
and then the query will execute:
cur = conn.cursor()
cur.execute('SELECT * FROM crime_scene_report WHERE city=? AND type=? ', (csr_city,csr_type))
rows = cur.fetchall()
rows
If the user enters both variables like city='SQL City'
and type='murder'
it works as it finds both values in the same row, but if the user leaves one empty, ex type, then it returns a blank table as both conditions do not exist on one single row.
What I would like to do is for SELECT to ignore the variable if it is empty. I guess I could do it with if statements but that would create a mess?? Is there a better way?
I tried How to ignore the condition that user did not pass in SQLITE?, but didnt work for me, still getting empty tables.