Answer the question
In order to leave comments, you need to log in
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,
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question