Overview
The standard SQL Data Transformation used in a DIM Project is an Insert SQL transaction. SQL Update transactions are also supported for cases when a company needs to update existing information in their SQL Database. This feature is only available by editing the Project (.XML) file directly with a Text Editor.
In order to add a SQL Update Data Transformation, an entire block of code is added to the Project file to execute a SQL statement. If the Project already has a SQL Insert Data Transformation, the SQL Update code can be just added to that block. If not, the SQL Connection Information needs to be added as well. If a User adds a SQL Update Data Transformation to a Project that has no pre-existing SQL in it, it is recommended to create a new SQL Insert Data Transform using the Project Manager first to verify the Database connection. When the Project file is edited, the original Insert Statement can be removed.
The Block shown below is a basic SQL Update including SQL Connection Information:
- <sql provider="OleDb" connectionString="provider=sqloledb; data source=(local); initial catalog=Test; user id=demo; password=test" transaction="true">
- <execCommand>
- <commandText>update f2b.bar set delta=? where gamma=3</commandText>
- <parameter>{Page1@BatchId}</parameter>
- </execCommand>
- </sql>
The <sql> block is the SQL Connection Information section. The <execCommand> block is the SQL Update text. The <parameter> block is the actual value of the Parameter from the Project’s Form. The ‘?’ represents each Parameter in the block and are evaluated in order. Parameters do have the option to use a “name” attribute for use in the Update command, but most Transactions will not use this format.
Using Conditions
SQL Updates can use conditions and only requires the “condition” attribute to be set.
In the sample below, the SQL Update will only run if a value is entered in the {Page1BatchId} Region in the Form.
- <execCommand condition="{Page1@BatchId}">
- <commandText>update f2b.bar set delta=? where gamma=3</commandText>
- <parameter>{Page1@BatchId}</parameter>
- </execCommand>
1. Open the .xml Project File (typically located at C:\Program Files\F2B Data Integration Module\Jobs) with a Text Editor.
2. Find the <rfiSvc> block (the SQL Update will be added below this block).
3. Add the following block:
- <sql provider="OleDb" connectionString="provider=sqloledb; data source=(local); initial catalog=Test; user id=demo; password=test" transaction="true">
- <execCommand>
- <commandText>update f2b.bar set delta=? where gamma=3</commandText>
- <parameter>{Page1@BatchId}</parameter>
- </execCommand>
- </sql>
4. Save the Project File.
5. Exit the Text Editor.
6. Open the Data Integration Module Administrator.
7. Start (or Restart) the Service to now Process Jobs with the SQL Update in place.
When a SQL Update is processed in a Job, additional entries will be shown in the Logs. However, the Logs only show that the SQL statement was executed; it does not show if the Transaction was successful. Here is a sample of what a SQL Update would look like in the Logs:
09/16 11:35:41.92 AM (tid:16156) Info : Executing sql command
09/16 11:35:42.06 AM (tid:16156) Info : Command affected 1 row(s)
Transaction Option
The transaction option can only be changed directly in the Project file and has a True or False value. This transaction option was created to allow the SQL Transactions in the Project to be linked in a single Transaction block that will roll back if any errors occur. The default value is set to True to link all Transactions into a single block.
- True (default) - If there are processing errors in SQL Statements after a block has been executed, any transaction set to True IS rolled back in the database.
- False - If there are processing errors in SQL Statements after a block has been executed, any transaction set to False is NOT rolled back in the database.
Note: If there are any processing errors for the Job prior to the SQL Statement being run, no transaction will even occur.