我正在嘗試構建一個小型私人應用程式來更好地組織我們的研討會。我有很多零件在編號的盒子里。所有資訊都進入一個 sqlite.db。影像是單獨存盤的——只有影像路徑存盤在資料庫中。現在我正在嘗試使用分頁查詢資料庫。但是我認為這行代碼有一個錯誤:
limit_search=('SELECT * from KTRmini_table WHERE discription LIKE ?, (search_term,) LIMIT ') str(offset) ',' str(limit)
如果有人能給我提示要改變什么,那將是非常友好的。謝謝你。
那是代碼的相關部分。
def find_search_term_and_total_number_of_matches_if_any(self, search_term):
search_term = self.search_entry.get()
search_term = ("%" search_term "%")
conn=sqlite3.connect("KTRmini.db")
c = conn.cursor()
c.execute("SELECT count(*) FROM KTRmini_table WHERE discription LIKE ?", (search_term,))
total_number_of_matches=c.fetchone()[0]
print("Found " str(total_number_of_matches) " Matches in Database")
limit = 5;
class Matches_window(tk.Toplevel):
def __init__(self, parent):
super().__init__(parent)
self.title('KTR-Matches')
self.configure(background='#587a8f')
self.geometry("1280x720")
self.iconbitmap("icon.ico")
Startpage.withdraw(self)
matches_window = Matches_window(self)
matches_window.grab_set()
def paged_matches(offset):
limit_search=('SELECT * from KTRmini_table WHERE discription LIKE ?, (search_term,) LIMIT ') str(offset) ',' str(limit)
r_set=c.execute(limit_search)
i=0
for each_match in r_set:
for number_of_database_columns in range(len(each_match)):
e = Entry(Matches_window, width=10, fg='blue', font=('Arial', 16))
e.grid(row=i, column=j)
e.insert(END, each_match[j])
b = Button(text= "Button", height=1, font=('Arial', 10))
b.grid(row=i, column=j 1)
i=i 1
paged_matches(0) # initial offset of 0
這是錯誤訊息:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files (x86)\Thonny\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:\Users\Marcel\Documents\MARCEL\PYTHON_PROJECTS\gui\KTR_mini\KTRmini_220215_028 Pagination.py", line 93, in find_search_term_and_total_number_of_matches_if_any
paged_matches(0) # initial offset of 0
File "C:\Users\Marcel\Documents\MARCEL\PYTHON_PROJECTS\gui\KTR_mini\KTRmini_220215_028 Pagination.py", line 81, in paged_matches
r_set=c.execute(limit_search)
sqlite3.OperationalError: near ",": syntax error
uj5u.com熱心網友回復:
的語法execute()是execute(SQL_string, *args)whereSQL_string是 SQL 陳述句并且*args是可選引數。
將引數search_term放在 SQL 陳述句中是不正確的。
正確的語法是:
limit_search = 'SELECT * FROM KTRmini_table WHERE discription LIKE ? LIMIT ? OFFSET ?'
r_set = c.execute(limit_search, (search_term, limit, offset))
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/425921.html
上一篇:self.login_button=tk.Button(self,command=lambda:master.show_frame())AttributeError:'Frame'
