conn = sqlite3.connect('db.db', check_same_thread=False)
cursor = conn.cursor()
def db_db_val(user_id: int, user_name: str, username: str):
cursor.execute('INSERT INTO users (user_id, user_name, username) VALUES (?, ?, ?)',(user_id, user_name, username))
conn.commit()
@bot.message_handler(commands=['db'])
def test(message):
# try:
bot.send_message(message.chat.id, 'test')
if message.from_user.id in cursor.execute('SELECT user_id FROM users'):
bot.send_message(message.chat.id, 'upd')
cursor.execute(f'UPDATE users SET user_id = {message.from_user.id} WHERE user_id = {message.from_user.id}')
cursor.execute(sql)
conn.commit()
else:
bot.send_message(message.chat.id,'add')
us_id = message.from_user.id
us_name = message.from_user.first_name
username = message.from_user.username
db_db_val(user_id=us_id, user_name=us_name, username=username)
# except:
# bot.send_message(message.chat.id,'123')
в бд добавляет а update не работает, не понимаю в чем проблема, помогити
ошибка: sqlite3.IntegrityError: UNIQUE constraint failed: users.user_id