A
A
alex3dlol2020-06-16 13:44:57
Python
alex3dlol, 2020-06-16 13:44:57

Python Telegram Bot. How to properly change data in Sqlite3 DB?

Hello! I ran into a problem when trying to create balance changes for a telegram bot I use TelegramBotAPI (aka telebot) and Sqlite3

user = message.from_user.id
sql = "UPDATE main SET balance = ? \
WHERE user_id = ?"
val = ("balance + 15", user)
c.execute(sql, val)
conn.commit()
When working in balance, it just writes the value "balance + 15", instead of adding 15 to the existing number

Tried to do it in an "unsafe" method :

c.execute("UPDATE main SET balance = balance + 15
WHERE user_id = user_id ")
conn.commit()

In this case, the balance is recorded correctly, but it only works if you manually specify the id of a specific user

Help. kind people

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor, 2020-06-16
@alex3dlol

And if like this:

sql = "UPDATE main SET balance = balance + ? \
WHERE user_id = ?"
val = (15, user)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question