Answer the question
In order to leave comments, you need to log in
How to check for the existence of rows in a table in sqlite?
def init_user_db(con, users):
cursorObj = con.cursor()
for x in users:
limits_values = (x, 0)
cursorObj.execute('INSERT INTO limits(id, count) VALUES(?, ?)', limits_values)
con.commit()
def sql_counts_checker(con, message):
cursorObj = con.cursor()
cursorObj.execute(f'SELECT count FROM limits WHERE id = {message.chat.id}')
rows = cursorObj.fetchall()
print(rows)
count = rows[0][0]
con.commit()
return count
init_user_db
1 time, I get 1 value [(2,)]
, but if I call this function a few more times, then the output will already be [(2,), (0,), (0,), (0,), (0,), (0,), (0,)]
, despite the fact that there is already there [(2,)]
, I need if there is a value, it is nothing more there did not bring
Answer the question
In order to leave comments, you need to log in
UPSERT , this is when an insert attempt is made, and if such an entry already exists, then it is either updated or the old value is stored.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question