Create the Transaction Group
Now that we have a recipe table in the database that is populated with some records, we can create the Transaction Group that will load a recipe from the table into our Tags. We will be using the recipes table that we put together previously, but if you already had a table, you can use that here instead.
- Create a new Standard Transaction Group.
- We have four columns in our database table, so we will need four Tags to use in the Transaction Group: an integer, string, and two floats for the id, name, and setpoints respectively. Add the four Tags to the Transaction Group.
- Set the Table Name to 'recipes', the table that we created earlier.
- We then need to ensure that our Tags will be receiving the proper values from the database. Set the Target Names for each of the Tags: the string to 'recipe_name', the floats to 'setpoint1' and 'setpoint2', and the integer to 'Read Only'. We don't need to set the integer to the id column, because we will not pull the the id from the database, but rather use the id as a trigger and in the where clause.
- Now we can finish setting up the rest of the Transaction Group. Set the Update mode to DB to OPC.
- Set the Table Action to Update/Select using Key/Value Pairs with the Column set to id, and the Value set to the Integer Tag you are using.
- Set the Update Rate to 1 second. We want to query the values out of the database as soon as we ask for them, so we need the group to update quickly. However, we don't want the group to actually query the database every second, so we will need to set up the trigger.
- Go to the Trigger tab, and select Execute this group on a trigger. Trigger on the item the int Tag that is being used for the id. Specify the Trigger condition as Active on value change.
- Finally, Enable the Transaction Group and save the project to get it started. The Transaction Group will now pull the recipe out of the database where the id matches the value of the int Tag. The trigger also prevents it from running all the time, instead running only when the int Tag value changes.
- To test it out, simply change the value of id Tag to an id of one of the recipes in the recipes table.