M
M
mihailos2020-11-23 13:53:39
Python
mihailos, 2020-11-23 13:53:39

Why is the database not populated?

There is this code:

import sqlite3 as sq

conn = sq.connect("main.db", check_same_thread=False) 
cur = conn.cursor()
cur.execute("""CREATE TABLE IF NOT EXISTS users( 
    username TEXT, 
    id_tele TEXT,
    user_id INTEGER PRIMARY KEY
)""")

@bot.message_handler(commands=['start'])
def welc(message):
    idUser = message.from_user.id
    userName = message.from_user.first_name
    bot.send_message(message.chat.id, "Что хотите узнать?")
    cur.execute("INSERT INTO users(username, id_tele) VALUES(:name, :id)", {'name': userName, 'id': idUser})
    cur.close()

cur.close() was added, because there were errors, but not with it.
For some reason, the database is not filled

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Karbivnichy, 2020-11-23
@mihailos

After cur.execute... you need to add conn.commit()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question