python - sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 74 supplied -
def insert(array): connection=sqlite3.connect('images.db') cursor=connection.cursor() cnt=0 while cnt != len(array): img = array[cnt] print(array[cnt]) cursor.execute('insert images values(?)', (img)) cnt+= 1 connection.commit() connection.close()
i cannot figure out why giving me error, actual string trying insert 74 chars long, it's: "/gifs/epic-fail-photos-there-i-fixed-it-aww-man-the-tire-pressures-low.gif"
i've tried str(array[cnt]) before inserting it, same issue happening, database has 1 column, text value.
i've been @ hours , cannot figure out going on.
you need pass in sequence, forgot comma make parameters tuple:
cursor.execute('insert images values(?)', (img,))
without comma, (img)
grouped expression, not tuple, , img
string treated input sequence. if string 74 characters long, python sees 74 separate bind values, each 1 character long.
>>> len(img) 74 >>> len((img,)) 1
if find easier read, can use list literal:
cursor.execute('insert images values(?)', [img])
Comments
Post a Comment