Answer the question
In order to leave comments, you need to log in
How to protect a table from creating duplicates?
With this function I enter data into a table
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(?, ?) ON CONFLICT DO NOTHING', 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
several times, then in the output ( print(rows)
) I will get duplicates , [(2,), (0,), (0,), (0,), (0,), (0,), (0,)]
although I indicated ON CONFLICT DO NOTHING
why duplicates are created anyway? How to fix it (with code examples please)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question