H
H
HexUserHex2020-04-19 15:51:46
Python
HexUserHex, 2020-04-19 15:51:46

Python, error while working with Sqlite ( Incorrect number of bindings supplied...)?

Good afternoon,
tell me where I made a mistake and what is wrong with my request?

cursor.execute("INSERT INTO table_name (abcd) VALUES(?)", (data))


#!/usr/bin/env python3
import sqlite3

def insert(conn, data):
    cursor=conn.cursor()
    cursor.execute("INSERT INTO table_name (abcd) VALUES(?)", (data))

    conn.commit()
    


def main():
    data = 'input data'

    conn = sqlite3.connect("./test.db")
    cursor = conn.cursor()

    cursor.execute("CREATE TABLE IF NOT EXISTS table_name (abcd TEXT)")
 

    insert(conn, data)

    conn.commit()
    conn.close()


if __name__ == "__main__":
    main()


mistake:

Traceback (most recent call last):
File "./test.py", line 27, in
main()
File "./test.py", line 21, in main
insert(conn, data)
File "./test. py", line 6, in insert
cursor.execute("INSERT INTO table_name (abcd) VALUES(?)", (data))
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 10 supplied.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bbkmzzzz, 2020-04-19
@HexUserHex

execute takes a tuple as parameters . A comma is needed after data

cursor.execute("INSERT INTO table_name (abcd) VALUES(?)", (data,))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question