0

Code

I have this function:

#Refresh MySQL data to Treeview
    def refresh(self):
        self.table.delete(*self.table.get_children())

        cursor = mydb.cursor()
        cursor.execute("select * from requested order by done")
        for row in cursor:
            self.table.insert('','end', values = (row[8], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[9], row[10], row[12]))

If I insert a record or update one - using workbench. When I press refresh in Tkinter, it does not show any new or amended data. Just stays as it is.

But - If I quit Tkinter app - re-open it - click refresh it will show new amended data.

If the tkinter app is running - If I try to run the following query: truncate table using workbench - MySQL will not complete the query the action until I close the tkinter app

What it should do

When I activate the function refresh - it should remove all the current data in treeview and update it with existing values within MySQL.

Quesiton

How can I achieve this?

10
  • Have you verfied your .execute(... yields new or even any data? Commented Dec 11, 2019 at 16:18
  • @stovfl not sure what you mean. But here is an additional information - If the tkinter app is running - If I try to truncate from workbench - it will not do anything until I close the tkinter app Commented Dec 11, 2019 at 16:20
  • First step, add print('in refresh') inside def refresh(...) to verify it get called at "I press refresh". Commented Dec 11, 2019 at 16:23
  • 1
    Got it, sounds like a concurent access locking? Commented Dec 11, 2019 at 16:34
  • 1
    You probably have an issue with MySQL transaction isolation level Commented Dec 11, 2019 at 16:59

1 Answer 1

1

From @brunodesthuilliers link in comments MySQL transaction isolation level has helped me find what was wrong!

By running this query in MySQL Workbench:

SET GLOBAL TRANSACTION ISOLATION LEVEL READ COMMITTED;

Has allowed me to update records from MySQL and run this function below - without a problem!

#Refresh MySQL data to Treeview
    def refresh(self):
        self.table.delete(*self.table.get_children())

        cursor = mydb.cursor()
        cursor.execute("select * from requested order by done")
        for row in cursor:
            self.table.insert('','end', values = (row[8], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[9], row[10], row[12]))
Sign up to request clarification or add additional context in comments.

2 Comments

You probably want to set the transaction isolation level in your own code (cf this post) when opening the db connection, so you're sure you always get it right.
That would make sense!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.