S
S
samperirrrrr2021-05-21 20:24:22
Python
samperirrrrr, 2021-05-21 20:24:22

The function does not work as it should, what should I do?

The thing is, the function doesn't work properly in my bot.

def starvation_system():
    db = sqlite3.connect("base.db") # подключение базы данных.
    sql = db.cursor()
    while True:
        for sqlse in sql.execute(f"SELECT * FROM users"):
            sql.execute(f"SELECT * FROM users WHERE userid = '{sqlse[1]}'")
            user_info = sql.fetchone()
            sql.execute(f"UPDATE users SET golod = '{user_info[12] - int(10)}' WHERE userid = '{sqlse[1]}'")
            db.commit()
        time.sleep(5)

and his problem is that he minus only one (the very first) user has a value, but he must have all

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
o5a, 2021-05-22
@o5a

def starvation_system():
    db = sqlite3.connect("base.db") # подключение базы данных.
    sql = db.cursor()
    sql.execute("UPDATE users SET golod = golod - 10")
    db.commit()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question