Followed the help at...
Watched several Inductive university videos and another presentation from a webinar on youtube.
I am happy with my transaction groups thus far for getting and putting recipes into MySQL.
However I'd like the ability to delete a record from DB via from a vision client. But the scripting escapes me. And it does not look like another transaction group will do it.
Googling is not good with signal to noise.
So I asked ChatGPT....
Using a button control within an Igntion vision client, how would one execute a MySQL query to delete a record from a database with teh button is clicked?
To execute a MySQL query to delete a record from a database when a button is clicked in Ignition Vision, you can follow these steps:
- Create a new button component in the Ignition Vision window by dragging and dropping a Button component from the component palette onto the design canvas.
- Double-click the button to open the Button Property Editor.
- Under the Actions section, click the "Configure Events" button next to the "MouseClicked" event.
- In the Event Script Editor, write the following code:
# Import the system.db module from system.db import runPrepUpdate # Define the SQL query to delete the record from the database sql = "DELETE FROM my_table WHERE id = ?" # Define the values to substitute into the query (in this case, the ID of the record to delete) params = [my_record_id] # Execute the query using the runPrepUpdate function runPrepUpdate(sql, params, "my_database")
Note: You will need to replace
my_databasewith the appropriate values for your specific use case.
- Save the script and close the Event Script Editor.
- Save the changes to the Button component and close the Button Property Editor.
Now, when the button is clicked in the Ignition Vision client, it will execute the specified MySQL query to delete the record from the database.
And so I did all that, (well mostly) and it worked.
Is that the proper thing to do?
Seems like it could have been simpler - but I could not find a 'simple' means.