Не могу записать в базу данных больше 2-ух элементов
Не могу записать в базу данных больше 2-ух элементов:
import sqlite3
conn = sqlite3.connect("C:/Users/RAINGM/desktop/testdatabase.db")
cursor = conn.cursor()
battletag = input('Введите данные: ')
for i in cursor.execute(f"SELECT tag FROM tagtest1"):
battletags1 = i[0]
battletags = [battletags1]
battletags.append(battletag)
if battletags1 == 'none':
cursor.execute(f"UPDATE tagtest1 SET tag = '{battletag}'")
conn.commit()
else:
cursor.execute(f'UPDATE tagtest1 SET tag = "{battletags}"')
conn.commit()
Ошибка:
Traceback (most recent call last): File "c:/Users/RAINGM/Desktop/Untitled-1.py", line 53, in <module> cursor.execute(f'UPDATE tagtest1 SET tag = "{battletags}"') sqlite3.OperationalError: near "['asd', 'asd']": syntax error
Ответы (1 шт):
Автор решения: Victor VosMottor thanks Monica
→ Ссылка
import sqlite3
conn = sqlite3.connect("C:/Users/RAINGM/desktop/testdatabase.db")
cursor = conn.cursor()
battletag = input('Введите данные: ')
for i in cursor.execute(f"SELECT tag FROM tagtest1"):
battletags1 = i[0]
battletags = [battletags1]
battletags.append(battletag)
if battletags1 == 'none':
battletags_str = str(battletags).replace('\'', '')
cursor.execute(f"UPDATE tagtest1 SET tag = '{battletags_str}'")
conn.commit()
else:
battletags_str = str(battletags).replace('\'', '')
cursor.execute(f"UPDATE tagtest1 SET tag = '{battletags_str}'")
conn.commit()