LESSON

Refreshing SQL Data on Component

Description

Learn how to manually refresh SQL data on a component through scripting while the Polling Mode is set to Off.

Video recorded using: Ignition 7.9

Transcript

(open in window)

[00:00] Most of the examples we've seen thus far rely on a data set with a SQL binding to a polling mode turned on. While this is convenient, it's not always desirable. Imagine creating a window with multiple tables and multiple data sets, all these SQL query bindings, and all these firing around every five seconds or so. Now, when you expand that to 30 clients running, you can see that the load put on the database by pulling these queries can quickly become nontrivial. Many times we don't actually need these bindings to poll, but are using polling as an easy way to refresh our data set after we have changed data that should be reflected in a table. An easy way to accomplish this is to use the system that db.refresh scripting function to refresh specific components after you've made changes that you know are going to affect them. To see how we can accomplish this, let's go ahead and drag a table component onto our window here. Next, what I want to do is bind the data property to a SQL query, and I'm going to select star from my inventory table. Turn polling mode off. Okay. And we'll see here that I have all my data that's brought back. The next thing I want to do is add a button to our window. I'm going to add a script to this button and put it over here on the action performed. And the first thing I want to do is I'm going to run a query with the system.db.runPrepUpdate function. I'm just going to delete from inventory where id equals four. Just a simple delete query. Now, the thing that's going to refresh here is our system.db.refresh function. Now, this function takes two arguments. The first argument is the actual component which is our table component, and the second argument is the name of the property that we want to refresh on that component, and that's going to be my data property. We'll go ahead, we'll click okay. Put the designer into run time mode, and then we'll go ahead and click our button, and you'll see immediately that the line is deleted from my table without having to have the polling mode turned on. So, this an easy way to cut down those polling queries in your projects.

You are editing this transcript.

Make any corrections to improve this transcript. We'll review any changes before posting them.