Answer the question
In order to leave comments, you need to log in
Bug in sqlite3 python?
The code:
elif message.text == ' Информация о профиле':
db = sqlite3.connect('bot.db')
sql = db.cursor()
sql.execute("""CREATE TABLE IF NOT EXISTS users (
login TEXT,
password TEXT,
tiktok TEXT,
cash INT
)""")
db.commit()
tiktok_name = "ihfjrwjwrjwrjewfjwefjwe"
bot.send_message(message.chat.id, " Имя: {0.first_name}". format ( message. from_user , bot. get_me ( ) ))
bot.send_message(message.chat.id, f" Ваш логин: {message.from_user.id}")
sql.execute(f'UPDATE users SET tiktok = ? WHERE login = ?', (tiktok_name, message.from_user.id))
db.commit()
tik = sql.execute(f"SELECT tiktok from users WHERE login = '{message.from_user.id}'")
bot.send_message(message.chat.id, f"ваш тикток: {tik}")
balance = sql.execute(f"SELECT cash from users WHERE login = '{message.from_user.id}'").fetchone()[0]
bot.send_message(message.chat.id, f" Ваш баланс: {balance} RUB ")\
Answer the question
In order to leave comments, you need to log in
fetchone() is not used for tik, so the cursor itself will be written to it, not its data. But even in this case, he had to write something like text <sqlite3.Cursor ...
and not just an empty string.
Better to do this piece like this:
...
user_info = sql.execute(f"SELECT tiktok, cash from users WHERE login = '{message.from_user.id}'").fetchone()
if user_info:
tik, balance = user_info
bot.send_message(message.chat.id, f"ваш тикток: {tik}")
bot.send_message(message.chat.id, f" Ваш баланс: {balance} RUB ")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question