P
P
Pavel2019-05-21 22:56:07
Python
Pavel, 2019-05-21 22:56:07

How to compare a variable with a value in the database?

There is a bot in the cart. I want the bot if a person has already written, then do not save his chat_id, but save the others in a new line. I don't know how to compare them with each other. Tried with different data types. It either does nothing under if
chat_id = str(message.chat.id)
cursor.execute("select * from Table_1 where Chat_id = "+chat_id+"")
row = cursor.fetchall()
print(row) # prints []
if row == "[]":
cursor.execute("insert into Table_1 values ​​('"+chat_id+"')")
print("Add")
conn.commit()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
h0w4rd, 2019-05-21
@h0w4rd

It is better though about data types esteem. It's too early for you to write programs longer than five lines. I can't recommend anything else.

V
Vyacheslav Barsukov, 2019-05-21
@slavabars

You compare a line with an array
Quote marks from a condition try to remove.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question