Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sqlite not updating
#1
I have a program that records score when practicing darts, then shows them in a high score table.
def addToDb(self):
        name = self.name
        total = self.runningTotal
        
        connection = sqlite3.connect('highscores.db')
        cur = connection.cursor()

        insert_statement = ''' INSERT INTO finisheshigh(playername, score) VALUES(?, ?); '''
        insert_values = (name, total)

        
        cur.execute(insert_statement, insert_values)
        print("done")
            

        connection.commit()
        cur.close()
I have this code which adds the result to the database.
And this code displays it.

        connection = sqlite3.connect('highscores.db')
        cur = connection.cursor()
        connection.commit()
        # populate rtb table
        read_query = '''SELECT * FROM rtbhigh ORDER BY score DESC'''
        cur.execute(read_query)
        items = cur.fetchall()

        tk.Label(frame1, text="Round the board").grid(row=0,column=0, columnspan=3)

        row = 1
        buttonnumber = 1 
        
        for item in items:
            fullframe = tk.Frame(frame1, highlightbackground="black", highlightthickness=1)
            fullframe.grid(row=row, column=0)
            tk.Label(fullframe, text=buttonnumber).grid(row=0, column=0)
            tk.Label(fullframe, text=item[0], width=20).grid(row=0, column=1)
            tk.Label(fullframe, text=item[1]).grid(row=0, column=2)
            row += 1 
            buttonnumber +=1

        #populate finishes table
        read_query = '''SELECT * FROM finisheshigh'''
        cur.execute(read_query)
        items = cur.fetchall()

        tk.Label(frame2, text="Finishes").grid(row=0,column=0, columnspan=3)

        row = 1
        buttonnumber = 1 

        for item in items:
            fullframe = tk.Frame(frame2, highlightbackground="black", highlightthickness=1)
            fullframe.grid(row=row, column=0)
            tk.Label(fullframe, text=buttonnumber).grid(row=0, column=0)
            tk.Label(fullframe, text=item[0], width=20).grid(row=0, column=1)
            tk.Label(fullframe, text=item[1]).grid(row=0, column=2)
            row += 1 
            buttonnumber +=1

        connection.commit()
        cur.close()
The issue I am having is the result which has just been input does not show in the displayed table, if the program is shut down then restarted it is there.
I have tried both cur.close and connection.close with no success.

Any help would be greatly appreciated.
Reply


Messages In This Thread
Sqlite not updating - by angus1964 - May-24-2023, 04:37 AM
RE: Sqlite not updating - by menator01 - May-24-2023, 06:42 PM
RE: Sqlite not updating - by angus1964 - May-24-2023, 07:04 PM
RE: Sqlite not updating - by angus1964 - May-24-2023, 06:45 PM
RE: Sqlite not updating - by menator01 - May-24-2023, 07:02 PM
RE: Sqlite not updating - by angus1964 - May-24-2023, 07:11 PM
RE: Sqlite not updating - by angus1964 - May-25-2023, 08:47 PM
RE: Sqlite not updating - by angus1964 - May-26-2023, 03:23 PM
RE: Sqlite not updating - by menator01 - May-24-2023, 07:07 PM
RE: Sqlite not updating - by Larz60+ - May-25-2023, 10:16 PM
RE: Sqlite not updating - by angus1964 - May-26-2023, 10:16 AM
RE: Sqlite not updating - by menator01 - May-27-2023, 09:05 PM
RE: Sqlite not updating - by angus1964 - May-28-2023, 10:04 AM
RE: Sqlite not updating - by angus1964 - May-30-2023, 07:36 PM
RE: Sqlite not updating - by angus1964 - May-30-2023, 07:50 PM
RE: Sqlite not updating - by menator01 - May-30-2023, 08:23 PM
RE: Sqlite not updating - by angus1964 - May-31-2023, 05:48 AM
RE: Sqlite not updating - by brighammcdanie - May-30-2023, 08:39 PM
RE: Sqlite not updating - by menator01 - May-31-2023, 06:11 AM
RE: Sqlite not updating - by angus1964 - May-31-2023, 06:37 AM
RE: Sqlite not updating - by angus1964 - Jul-07-2023, 03:18 PM
RE: Sqlite not updating - by deanhystad - Jul-07-2023, 06:26 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Updating records 1 to n on an SQLite table KevinBrown 2 2,686 Mar-30-2019, 05:02 PM
Last Post: KevinBrown

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020