F
F
Fedor2020-11-25 10:04:08
Python
Fedor, 2020-11-25 10:04:08

Why does not save the database?

The problem is that in one part of the code the output is 1 (example below), and in the other 0, that is, for some reason the database is not updated

con = sqlite3.connect("orders.db")
        cur = con.cursor()
        cur.execute(f"SELECT users FROM st;")
        users = cur.fetchone()[0]
        print(users)
        us = users+1
        print(us) #тут вывод 0
        cur.execute(f"UPDATE st SET users = {us};")
        conn.commit()
        cur.execute(f"select users from st")
        users1 = cur.fetchone()[0]
        print(users1) #тут вывод 1

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Fedor, 2020-11-26
@srgvac

I can say one thing
just did not save

con = sqlite3.connect("orders.db")#тут con
 cur = con.cursor()#тут тоже con
conn.commit()#а тут conn

E
Elvis, 2020-11-25
@Dr_Elvis

I suppose that here
cur.execute(f"UPDATE st SET users = {us};")
you insert a number into users, and in the database there is a string type. The commit does not work and what was displayed is displayed.
Check the types in the database and those that you contribute.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question