Problem getting SQL query to search multiple columns

60 views Asked by At

I need my SQL query to search multiple columns, this is what I have so far:

cur.execute("SELECT name, unit, phone1, phone2 FROM rdata WHERE lower(unit) LIKE lower(?) OR REPLACE(lower(name), ' ', '') LIKE REPLACE(lower(?), ' ', '')", [z.get(),])

I've read as much documentation as I can but it still isn't working.

The error I get is:

sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 2, and there are 1 supplied.

1

There are 1 answers

0
FragUPlenty On

Ok I figured it out thanks to your help, I added searching by phone numbers and did this instead.

cur.execute('''SELECT name, unit, phone1, phone2 FROM rdata WHERE (lower(unit) LIKE lower(?))
                OR (REPLACE(lower(name), ' ', '') LIKE REPLACE(lower(?), ' ', ''))
                OR REPLACE(phone1, '-', '') LIKE REPLACE(?, '-', '')
                OR REPLACE(phone2, '-', '') LIKE REPLACE(?, '-', '')''',(z.get(), z.get(), z.get(), z.get()))