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

后端 未结 2 552
既然无缘
既然无缘 2020-11-22 06:52
def insert(array):
    connection=sqlite3.connect(\'images.db\')
    cursor=connection.cursor()
    cnt=0
    while cnt != len(array):
            img = array[cnt]
          


        
2条回答
  •  不知归路
    2020-11-22 07:37

    You need to pass in a sequence, but you forgot the comma to make your parameters a tuple:

    cursor.execute('INSERT INTO images VALUES(?)', (img,))
    

    Without the comma, (img) is just a grouped expression, not a tuple, and thus the img string is treated as the input sequence. If that string is 74 characters long, then Python sees that as 74 separate bind values, each one character long.

    >>> len(img)
    74
    >>> len((img,))
    1
    

    If you find it easier to read, you can also use a list literal:

    cursor.execute('INSERT INTO images VALUES(?)', [img])
    

提交回复
热议问题