我正在制作一個存盤特定時間的資料庫,所以我想更新其中的所有值,但是當我嘗試更新時,它給了我那個錯誤,sqlite3.OperationalError: near "?": syntax error我不知道為什么。這是我的代碼:
def db_edit(db , cr , table , new_value , title):
time = check_txt_len(new_value , 8 , "0")
tu = (table , time , time[0:2] , time[3:5] , time[6:] , title)
cr.execute("UPDATE ? SET title=? , hour=? , min=? , period=? where title=?" , tu)
db.commit()
data = db_get("*" , "times" , "fetchall" , cr)
for tu in data:
for item in tu:
if item is title:
return False
return True
這是錯誤部分:
cr.execute("UPDATE ? SET title='?' , hour='?' , min=? , period='?' where title='?'" , tu)
uj5u.com熱心網友回復:
是的, ?不能用于表名或欄位名,因為它們沒有被參考。這個函式不知道表名是不尋常的。它怎么知道欄位,而不知道表?
當您根據標題進行更新時,設定標題很愚蠢。
那個回圈試圖做什么?如果在任何記錄中找到標題,看起來您正試圖回傳 False,但您知道它必須在那里,因為您剛剛執行了 UPDATE WHERE title='title'。無論如何,“是”是錯誤的運算子。
def db_edit(db , cr , table , new_value , title):
time = check_txt_len(new_value , 8 , "0")
tu = (time[0:2] , time[3:5] , time[6:] , title)
cr.execute(f"UPDATE {table} SET hour=?, min=?, period=? WHERE title=?", tu)
return True
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/370835.html
下一篇:每組優化的最大n
