Description

Learn how to call Stored Procedures (or Functions) through Transaction Groups, by mapping data in to the SP Input Parameters and out using either the SP Return value or Output Parameters.

Video recorded using: Ignition 7.9

Transcript

(open in window)

[00:00] In this example, we're going to create a stored procedure group that will interact with the stored procedure in our restore value, and retrieve back the number of rows stored and a counter of how many times we've called the procedure. First of course, we have to start by defining our stored procedure. A stored procedure is essentially a type of function in the database, and it can have various parameters that are mapped as either input, output, or both. First we have to define our stored procedure in the database. For the purposes of our example, we'll create a new procedure that's defined as follows. We're going to call our procedure, "Safe Insert", because stored procedures are often used to provide extra security by validating data before inserting it into a database. In this procedure, we'll have three parameters, an input value, an output that we'll call row count, and an in-out parameter called counter. Generally speaking, all databases support these features. Parameters can come into the procedure, that each can go out, or a parameter can do both. Our stored procedure will insert into a table that we've created, and then I'll select the row count from that table into our out parameter. Just for good measure, we'll increment this counter parameter by one. Now that the procedure is created, we can go back into Ignition and create a stored procedure group. We'll select our procedure from the drop down list, which should now be visible, and now, we need to create items that will map to those fields. For input value, we'll just select a ramp tag, and drag it in. The target name refers to in or in-out parameters, and in this case if we select the drop down, we can see the parameters here and select our value input. For the other values, we'll use some simple writeable tags such as writeable integer one, we'll map this to our row count output parameter. First we'll select our output parameter, row count, and next, because we're not using this as an input, and in fact we can't because it's defined as only an output, we'll set the target name to read only. For the in-out parameter, we'll map both the target name and the output to the same parameter, which is the counter. Now with the group configured, we're ready to be in running in. As soon as we enable it, we see that the value begins writing, our row count is being written back, and our counter is being incremented. We can see the effect of our counter by resetting it and writing a zero to the tag. Of course if we reset our counter, it won't matter as that is a pure output value. This is a simple example, but shows how to map to all of the different types of parameters in a stored procedure group. Additionally, we can choose to map the timestamp of the quality code to other parameters. Expression items can also target input parameters, and although we didn't illustrate it in this example, items can also be mapped to the return value of a procedure if the database supports it. So for example in my SQL, stored procedures can not return values, but functions can, so the exact mapping will depend on the definition of the procedure and what the database supports.

You are editing this transcript.

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