0

my only problem is that i made a program which gets all the data from the sql database, but when i am changing for example a value or a name of something on my table , the new "update" i made on the table is not showing , it still shows me the previous data. So i need to know , how can i automatically update the shown data of the program when i am changing something.

This is what i made as a command for the button of "update sql"

def update_infos_whitemat(self):
        update_whitemat_name = aoracandlestudiodb.cursor()

        getname = self.name_whitemat_entry.get()
        if getname != '':
            updatename = "UPDATE aoracandlestudiodb.items SET _name= '%s' WHERE iditems='1';"%getname
            update_whitemat_name.execute(updatename)
            aoracandlestudiodb.commit()
        else:
            pass
tadman
  • 208,517
  • 23
  • 234
  • 262
  • 2
    PSA: **DO NOT** use string formatting for SQL. **ALWAYS** use placeholder values or proper escaping. In this case it's a trivial fix, just leave the format specifier and let `execute("...", (getname,))` do the work for you. – tadman Apr 18 '23 at 16:27
  • When you say that the update is not showing, do you mean in the database window? Have you tried the refresh button? – Ben Apr 18 '23 at 19:24
  • @Ben no , i actually mean that , when i am writing something on the entry and pressing the "update" button. On the SQL Workbench , i can see the new entry i just added , but the updated data is not showing on program, i have to close the window and reopen it so i can see the the entry data i did. – Pavlos Katsioulis Apr 18 '23 at 21:58
  • @tadman can you show me an example , cause it's my very first time i am doing like this. – Pavlos Katsioulis Apr 18 '23 at 22:00
  • [See this answer](https://stackoverflow.com/questions/902408/how-to-use-variables-in-sql-statement-in-python). – tadman Apr 18 '23 at 22:18
  • Thanks, Pavlos. So the issue is on the SQL Workbench and not actually when running the Python code above? Can you show a screenshot of what you're seeing? – Ben Apr 19 '23 at 15:15
  • @Ben Here's a link from the screenshoot https://prnt.sc/SGV1g1PbI2-N . When i actually wanna change a name of an item. The update button does that. But the new name is not showing on the left for example: If i change the name from the box:"Name" from "white mat" into "pink mat" on the left which shows all the items i got in the database, it's not getting updated , it still gonna show "white mat" and i have to restart the program so the new name will display there. – Pavlos Katsioulis Apr 19 '23 at 18:16
  • Hi, Pavlos. I meant a screenshot from Pycharm. This appears to be a drawing of your UI. Is that actually the problem? Is your program's user interface not updating after you update the data in the DB? – Ben Apr 19 '23 at 20:25
  • @Ben Yeah that's exactly the problem , you couldn't be more accurate "user interface not updating after you update the data in the DB" – Pavlos Katsioulis Apr 19 '23 at 21:30
  • Ahh, then this is a bigger question. Are you presenting your results to a web browser through a web framework like Flask or Django, or are you writing to your local PC screen with print statements? – Ben Apr 19 '23 at 21:48
  • @Ben It's on my local PC with print statements – Pavlos Katsioulis Apr 19 '23 at 21:56
  • Are you rerunning the code that retrieves the data fed to the print statements after you update the database? Are you then rerunning the print statements? – Ben Apr 20 '23 at 13:51
  • If I am understanding 100% what I wrote , I am connecting to the database from the start of the program and then I set different print statements on every different button. If I want to see the new values , I do close the window of my program and rerunning it. – Pavlos Katsioulis Apr 21 '23 at 15:50
  • So, copy those print statements right after you update the database. I think that will solve your problem. – Ben Apr 21 '23 at 19:15

0 Answers0