Finding an item in the tuples stored in a database with having "only part of the items name" and showing that in a gui app

Viewed 27

I've made a search feature in my GUI app to look up for items in my database by entering the name of the item so that it shows the tuple in a listbox. It only works when i enter the name of the item completely. As an example if the item is the string "microphone", it can only be found if i type the entire string. I'm trying to make it in such way that the item can also be found by entering only part of its name. Like with just typing "micro" it should show all the contents that has "micro" in it.

I have executed my SQLite statement in a function called "find" in my backend.py module:

...
    cur_obj.execute("SELECT * from store WHERE item=? OR enter_date=? OR release_date=? OR serial=?",
                    (item, enter_date, release_date, serial))
    rows = cur_obj.fetchall()
    conn.close()
    return rows

I have tried to define a search function in my store.py module:

def search():
    search_data = backend.find(
        item.get(), enter_date.get(), release_date.get(), serial.get())
    if len(search_data) != 0:
        for row in search_data:
            listing.insert(END, row)
    clear()

but it only works when i enter the entire string.

I looked for a solution on docs.python.org but there where no specific information on this issue. I will appreciate any ideas that can help me on this. I'm new in python world so if you know a documentation or any source that i can take a look at to learn the concept please share the link, it can be very helpful. Thank you!

0 Answers
Related