K
K
kodbiprog2021-05-29 19:21:05
Python
kodbiprog, 2021-05-29 19:21:05

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 ")\

Instead of the text written in tiktok_name, it does not display:
your tiktok:

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
o5a, 2021-05-30
@kodbiprog

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 ")

L
lil.fxrrx, 2021-05-29
@mxrdxfxrrx

Why are you replacing tiktok id from tiktok_name = "ihfjrwjwrjwrjewfjwefjwe" - ?, I don't understand

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question