Search SQLite Query in Python

107 views Asked by At

I make an employee record program in python. In this program, user can make search name, duty or education and can see for example all names contains 'Jennifer'. Employee informations holds on database therefore i am using some sql queries. For example, if u want to add new employee to database, my program run this query :

def insert(self, name, duty, date, education):
    self.cur.execute("INSERT INTO worker VALUES (NULL,?,?,?,?)", (name, duty, date, education))
    self.conn.commit()
    self.view()

In the search function, name duty, date or education takes as a parameter. If user click the name and write 'jennifer', user should see employees who name or surname contain Jennifer. However, I can't do that. I write this sql query and it works:

SELECT * FROM worker WHERE name LIKE '%Jennifer%'

but i cant replace Jennifer part with the name for input. I tried like this but it is not working(dont return anything to me):

def search(self, name="", duty="", date="", education=""):
    self.cur.execute("SELECT * FROM worker WHERE name LIKE('%' || name=? || '%')", (name,))
    rows = self.cur.fetchall()
    return rows

(I am trying only name in this part but i want to make search query for all features)

0

There are 0 answers