
Queries in Scripting
Ignition offers a number of built-in scripting functions for you to use to query your databases. This makes it very simple to view data, create dynamic scripts that use real data, and more. You can pull individual pieces of information, return whole tables of data, or update your database directly. Depending on the type of query and the sort of results you want, you will use different functions. The following functions are the ones you will use most, and all of them can use a special placeholder (?) to allow for dynamic query building.
Scripting Function | Description |
---|
system.db.runNamedQuery() | Used to run a previously setup Named Query from within a script. |
system.db.runPrepQuery() | Used to run basic SELECT queries to fetch whole datasets. This can be used to populate tables, or to sift through the data to do your own calculations. |
system.db.runPrepUpdate() | Used to run queries that change the data in the database. Usually used on input form windows to update your database records. |
system.db.runScalarPrepQuery() | Used when you want only one value from your results. Perfect for fetching a single value like the highest ID, or first timestamp of a result set. |
Each of the different functions takes in different arguments (values) and provides slightly different options and functionality. For example, the runPrepUpdate() can return the auto-generated key from insert queries. This can be extremely helpful and eliminate the need to hit the database multiple times if you are using linked tables.
You can find examples of each of these and all the other database functions in the system.db section of the appendix.
Ignition offers Query Tags, which can run queries and return the result as a Tag value, giving all of the projects in the Gateway access to the same Database values.

Queries in Reports
You can leverage queries to access data from all database connections to create rich reports, from simple data logging to complex reports with grouped charts and datasets.

Queries in Transaction Groups
While Transaction Groups are great at storing Tag data to a Database automatically, the built-in Expression Items can execute a SQL Query within the Transaction Group.

Database Query Browser
The Database Query Browser offers an easy to use environment to run queries in for testing. Here, queries can be tested to figure out what values get returned, or data can be updated through raw queries, or the Database Query Browsers easy to use GUI editor.
