【问题标题】:sqlite3.OperationalError: incomplete input on my codesqlite3.OperationalError:我的代码输入不完整
【发布时间】:2026-01-05 23:05:02
【问题描述】:

有人可以帮助我了解我的代码的不完整之处,无论我尝试什么,我都会不断收到 sqlite3.OperationalError:不完整的输入。我的代码是

editor = Tk()
editor.title('Edit Record')
editor.geometry('400x400')

#Creating database 
conn = sqlite3.connect('Student_info.db') 
c = conn.cursor()

record_id = delete_box.get()
#Query the database 
c.execute("SELECT * FROM Student_info WHERE oid ="+(record_id))<-----
records = c.fetchall()

sublime 所指的线是我画了一个箭头的线,如果有人能提供帮助,那就太好了!

【问题讨论】:

    标签: python sql sqlite


    【解决方案1】:

    execute() 的语法已关闭。您应该使用准备好的语句作为第一个参数,然后使用一组参数作为第二个函数参数:

    record_id = delete_box.get()
    c.execute("SELECT * FROM Student_info WHERE oid = %s", (record_id,))
    records = c.fetchall()
    

    【讨论】:

    • 非常感谢,但即使编辑了代码,它也会给我错误 sqlite3.OperationalError: near "%": syntax error
    • @Tim 您是否忘记使用%record_id 格式化到查询中,还是c.execute() 为您这样做?
    最近更新 更多