A
A
Artem Rocky2018-05-17 21:43:15
Python
Artem Rocky, 2018-05-17 21:43:15

How to add telegram user id to sqlite database?

How to make it so that when you click /start, the person's id is automatically entered into the sqlite database?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nikita Shoshin, 2018-05-17
@Kirtis

connection = sqlite3.connect("PATH")
cursor = connection.cursor()
cursor.execute("INSERT OR IGNORE INTO users (id) VALUES (:id)", {"id": id})

OR IGNOREso that if the user is already registered, nothing happens (otherwise there will be an error)
All this needs to be placed in a decorator that is responsible for the /start command. It's also a good idea to write a special class for the database so you don't have to open it every time.

A
Artem Rocky, 2018-05-17
@Aspvxrocky

Nikita Shoshin , by the way, have you come across such an error by chance?
sqlite3.InterfaceError: Error binding parameter :id - probably unsupported type.

S
spaceatmoon, 2018-05-17
@spaceatmoon

SQLite for simple needs is no different than mysql if you're interested in the syntax.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question