K
K
kodbiprog2021-06-10 19:01:43
Python
kodbiprog, 2021-06-10 19:01:43

Trouble with Telebot Python Sqlite3?

I want to make sure that a new one is added exactly the same to the previous Login + Name entry, but on a different line. When I write /add and write for example "hello" or "fhwefuiwefgiw 322 fsde" (it doesn't matter, only the first word of the sentence is selected), then the first word is stored in the database - 0.
Code:
def support_reg(message):
word = str( message.text)
name_for_table = (word.split()[0])
db = sqlite3.connect('db_for_freelance.db')
sql = db.cursor()

sql.execute("""CREATE TABLE IF NOT EXISTS users (
login TEXT,
name TEXT,
cash INT,
comment TEXT
)""")
db.commit()
sql.execute(f'UPDATE users SET name = name + \n? WHERE login = ?', (name_for_table, message.from_user.id))
db.commit()
check_name = sql.execute(f"SELECT name from users WHERE login = '{message.from_user.id}'").fetchone()[0]
print(check_name)
bot.send_message(message.chat.id, f"Support nickname: {check_name}")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
o5a, 2021-06-11
@o5a

Because text strings don't add up like numbers.

sql.execute("UPDATE users SET name = name || '\n' || ? WHERE login = ?", (name_for_table, message.from_user.id))

And why is this addition on a new line needed?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question