sqlite3.ProgrammingError:提供的绑定数量不正确。当前语句使用6,并且提供了5个

时间:2016-11-05 22:25:45

标签: sqlite

我真的不明白我做错了什么。我的表是:

conn.execute('''CREATE TABLE USERS
       (EMAIL           TEXT    NOT NULL,
       PASSWORD         TEXT    NOT NULL,
       FIRST_NAME       TEXT    NOT NULL,
       LAST_NAME        TEXT    NOT NULL,
       DATE             TEXT    NOT NULL,
       SEX              TEXT    NOT NULL);''')

当我试图插入表格时:

conn.executemany("INSERT INTO USERS VALUES (?, ?, ?, ?, ?, ?)", [email, password, first_name, last_name, date, sex])

我收到此错误:

sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 6, and there are 5 supplied.

如果我添加一个问题错误是相同的,但现在:

sqlite3.OperationalError: table USERS has 6 columns but 7 values were supplied

如果我只添加一个没有问号的逗号,则错误不同:

sqlite3.OperationalError: near ")": syntax error

变量值为:

    email=str(myapp.register_email.text())
    print email
    first_name=str(myapp.first_name.text())
    print first_name
    last_name=str(myapp.last_name.text())
    print last_name
    date=str(myapp.date.text())
    print date
    password="nht"
    print password
    sex=str(myapp.sex.currentText())
    print sex

我真的疯了,在这里找不到问题

1 个答案:

答案 0 :(得分:1)

根据Python doc的建议,executemany()方法需要一个值元组。因此,我建议您使用以下代码插入新条目:

conn.executemany("INSERT INTO USERS VALUES (?, ?, ?, ?, ?, ?)", [(email, password, first_name, last_name, date, sex)]