SQLITE-要查看刚刚对应用程序所做的更新,必须先注销然后重新登录

问题描述 投票:1回答:1

我通常可以更新SQLITE数据库中的记录,问题是当我查看更新的记录时,它带来了旧信息,要带来更新的信息,必须退出应用程序并返回。

我需要做些什么来使应用程序自动识别所做的更改而无需离开?

[数据更新代码

conn = sqlite3.connect("datum.db") 
cursor = conn.cursor()
highestscore =  cursor.execute("""select highest_score from datum where id_score = 1""")
highestscore = cursor.fetchone()
highestscore = highestscore[0]
if self.score > highestscore:
    highestscore = self.score
atualizar = cursor.execute("""UPDATE datum SET highest_score = ?, last_score = ?;""", (highestscore,self.score,))
conn.commit()
cursor.close() 

数据显示代码

try:
    conn = sqlite3.connect("datum.db") 
    cursor = conn.cursor()
    hscore = cursor.execute("""select highest_score from datum where id_score = 1""")
    hscore = cursor.fetchone()
    hscore = hscore[0]
    cursor.close()
except:
    conn = sqlite3.connect('datum.db')
    cursor = conn.cursor()
    try:
        cursor.execute("""CREATE TABLE datum(id_score INTEGER NOT NULL, highest_score INTEGER, last_score INTEGER);""")
    except:
        pass
    cursor.execute("""INSERT INTO datum(id_score, highest_score, last_score) VALUES(1, 0, 0);""")
    conn.commit()
    hscore = cursor.execute("""select highest_score from datum where id_score = 1""")
    hscore = cursor.fetchone()
    hscore = hscore[0]
    cursor.close()
python sqlite view kivy
1个回答
0
投票
处理数据库应用程序的一种好方法是在该类中创建一个Database类(数据库的单独模块),您可以在该类中插入,更新,删除,显示方法(或任何其他所需的方法)。这样,您可以访问更新的数据。
© www.soinside.com 2019 - 2024. All rights reserved.