D
D
Daniel12002022-03-28 18:48:49
Python
Daniel1200, 2022-03-28 18:48:49

Why - when trying to update the data in the table, using a str format variable that is longer than one character, an error occurs?

The other day I needed to insert data into a table from a variable that has the format - string. But, I stumbled upon a problem - when using a variable whose length is more than one character,

mistake:
Traceback (most recent call last):
File "C:\Users\User\Desktop\s.py", line 23, in
cursorObj.execute('UPDATE id SET used = ? where h = 1',(a))
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 3 supplied.

I will answer possible questions in advance:
1. when filling in manually - without using variables, there are no problems.
2. all the necessary libraries are downloaded
here is mine
code (very simplified):
import sqlite3
while 1 == 1:
    d = input()
    if d == "a":
        print('загрузка данных')
        con = sqlite3.connect('Emergybot.db')
        cursorObj = con.cursor()
        cursorObj.execute('create table if not exists id(last_id INTEGER, used TEXT, h INTEGER)')
        cursorObj.execute(f"SELECT * FROM id")
        if cursorObj.fetchone() == None:
            last_id = 0
            used_id = """XYZ"""
            h = 1
            cursorObj.execute("INSERT INTO id VALUES(?, ?, ?);", (last_id, used_id, h))
        con.commit()
    if d == "s":
        con = sqlite3.connect('Emergybot.db')
        cursorObj = con.cursor()
        a = "asd"
        cursorObj.execute('UPDATE id SET used = ? where h = 1',(a))
        con.commit()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2022-03-28
@Daniel1200

(a, )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question