In this recipe, we will explore the SQL plugin to work with SQL. This is a bit different from the JDBC recipe.
Obviously, we need a database. This database can be PostgreSQL, MS SQL, Oracle, or MySQL. For testing, you can use the PostgreSQL database that is implemented in the appliance (refer to the Tuning the appliance recipe in Chapter 2, Optimizing Orchestrator Configuration). Also, take a look at the There's more... section of this recipe.
We will use a Microsoft SQL 2008 R2 database in this example; however, the steps are the same for all databases. The database we will be using is called testDB
.
You will need an existing database and a user who is able to create/drop tables as well as insert/delete information, for example, the DBO role.
See the following sections.
In this section, we will connect an SQL server to Orchestrator:
We will now run a SQL statement:
INSERT INTO testtbl VALUES (2,'some lastname','some firstname');
.We will now run an SQL query:
SQL:ActiveRecord
) as an attribute.for each (result in resultRecords){ columns=(result.getFieldNames()); for each (column in columns){ System.log("Column :"+column+" content:"+result.getProperty(column)); } }
select * from testtbl
.The SQL plugin is a bit different than the JDBC connector as it uses Orchestrator objects. There are the following Orchestrator scripting classes:
SQLActiveRecord
SQLColumn
SQLDatabase
SQLDatabaseManager
SQLTable
Also extremely valuable are the Generate CRUD
workflows for a table. CRUD stands for Create, Read, Update and Delete and will create these four workflows a given table.