--- title: "Refreshing a SQL Query" --- # Refreshing a SQL Query > ```python title="Pseudocode - Refreshing a Table after an Edit" > doWork() > > system.db.runPrepUpdate("INSERT INTO table") > > system.db.refresh(component, "propertyName") > ``` ## Refreshing a Query The SQL query that populates a property on a component will refresh its data periodically if the [Polling Mode](ignition-modules\vision\binding-types-in-vision\binding-types-in-vision.md#polling-options) is set to either Relative or Absolute. However, there are times when you want the data to query the database once when the window is opened, and then retain explicit control over each subsequent refresh. The Table data can be required using [system.db.refresh](appendix\scripting-functions\system-db\system-db-refresh.md). There are two main ways of doing this: either placing the script on a button, or at the end of some code. ### Refresh After Edits If edits are being made to the Table data, or additional rows are being added, it can be a good idea to call the system.db.refresh() function after manipulating data. This way, the data in the Table will automatically refresh with the newly entered data, saving the user the hassle of clicking a refresh button. ```python title="Pseudocode - Refreshing a Table after an Edit" doWork() system.db.runPrepUpdate("INSERT INTO table") system.db.refresh(component, "propertyName") ``` ### Refresh on a Button We can use a Button component with a script on it to refresh the component with the query binding on it. Typically the button is placed close by the query bound component, and will say something like "Refresh Data". The script is actually fairly simple, and can be placed on the **actionPerformed** event of the Button. 1. Drag a **Button** component onto a window that has a Power Table or Table component querying a Database table. 1. Change the Button's Text property to say "Refresh." 2. On the Power Table component, open the **data** property binding and set the polling mode to **off**. 3. Right click on the Button and select **Scripting**. 1. Select the **actionPerformed** Event Handler and navigate to the Script Editor tab. 2. Add in this script, which will force the Table's data property to refresh. ```python title="Python - Refreshing the Database when the Button is Pressed" # Will force the Power Table's Data property to run the query again. system.db.refresh(event.source.parent.getComponent('Power Table'), "data") ``` 4. Try it out by adding new data to the Database table and then clicking the Refresh Button. ## Refreshing a Query in Perspective The [system.db.refresh()](appendix\scripting-functions\system-db\system-db-refresh.md) function does not work in Perspective. However, an additional component method has been added to handle the more general task of refreshing a binding. The method is called refreshBinding(), and can be called on any Perspective component: ``` self.refreshBinding("props.data") ``` The function takes a string as a parameter, the path to the property to be refreshed. More info on the refreshBinding() function can be found at [Perspective Component Methods](ignition-modules\perspective\scripting-in-perspective\perspective-component-methods.md).