我正在尝试从表中删除记录,但是出现“错误的绑定提供错误”

时间:2018-10-22 10:46:15

标签: python sqlite

这是我的代码:

def delWorker():
    deleteWorker = input('Please type in the surname of the worker you would like to delete. ')
    c.execute("DELETE FROM employees WHERE lastName = (?)",
              (deleteWorker))
    conn.commit()

我收到'incorrect bindings supplied error'的错误消息

1 个答案:

答案 0 :(得分:2)

您想要

c.execute("DELETE FROM employees WHERE lastName = (?)", (deleteWorker,)) 

=>注意deleteWorker之后的逗号,这就是创建tuple的原因-括号仅用于消除歧义,因此没有逗号,Python看到的是:

c.execute("DELETE FROM employees WHERE lastName = (?)", deleteWorker) 

因此,当cursor.execute()期望使用tuplelist时,您实际上是在传递字符串。