What I need is an inverse of the search function, which is select column_name from table_name where column_name = ? where ? is the term the user is searching for (a string like "%This%").
It needs to get the row number in the sqlite server from the column_name's content. I think it is possible since in this database all rows are completely unique so there's no chance of conflict.
If not, I would like to see an alternative way for indexing the pages in a way that makes it possible to achieve what I'm trying to do
You're looking for search function to select table_name.
I'm not sure whether what I wrote in my script is what you want.
Snippet:
import sqlite3
import tkinter as tk
from tkinter import Listbox, messagebox
def get_row_index(search_term):
conn = sqlite3.connect('your_database.db') cursor = conn.cursor()
cursor.execute("SELECT rowid FROM table_name WHERE column_name LIKE ?", (search_term,))
result = cursor.fetchone()
conn.close()
if result:
return result[0]
else:
return None
def display_selected_item(event):
selected_index = listbox.curselection()
if selected_index:
search_term = listbox.get(selected_index)
row_index = get_row_index(f"%{search_term}%")
if row_index is not None:
fetch_data(row_index)
else:
messagebox.showinfo("Info", "No matching entry found.")
def fetch_data(row_index):
conn = sqlite3.connect('your_database.db')
cursor = conn.cursor()
cursor.execute("SELECT * FROM table_name WHERE rowid = ?", (row_index,))
row_data = cursor.fetchone()
conn.close()
if row_data:
print(row_data)
# Tkinter GUI setup
root = tk.Tk()
listbox = Listbox(root)
listbox.pack()
# Example items in the ListBox (replace with your search results)
listbox.insert(tk.END, "Item 1")
listbox.insert(tk.END, "Item 2")
listbox.insert(tk.END, "Item 3")
listbox.bind('<<ListboxSelect>>', display_selected_item)
root.mainloop()