Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

...

...

...

...

...

...

...

...

...

...

...

...

...


Section


Column

Your SQL queries are defined in configuration.xml. The database connector looks for this file in

  • Standalone bundle - <db-home>\database\database-connector-(DBC version number)\config.
  • frevvo-tomcat bundle - The location you specified in <frevvo-home>\tomcat\conf\frevvo-config.properties via the frevvo.connectors.database.configuration property.

Info


Expand
titleClick here for troubleshooting tips

Insert excerpt
Testing the Connector
Testing the Connector
nopaneltrue




Column
width240px

On this page 

Table of Contents
maxLevel1


...

Code Block
languagehtml/xml
<dbconnector>
    <queryset name="BIRT">
        <query name="allProducts" autocreate="true">
            <retrieve>
                <!--maps to HTTP GET -->
                <statement> SELECT productCode, productName from Products order by productName </statement>
            </retrieve>
        </query>
        <query name="orderDetailsByOrder" autocreate="true">
            <retrieve>
                <!--maps to HTTP GET -->
                <statement> SELECT p.productName as product, o.quantityOrdered as quantity, o.priceEach as price,
                    p.productDescription as description, p.MSRP FROM OrderDetails o, Products p WHERE
                    o.productCode=p.productCode and o.orderNumber={onum} ORDER by o.orderLineNumber </statement>
            </retrieve>
        </query>
        <query name="productDetails" autocreate="true">
            <retrieve>
                <!--maps to HTTP GET -->
                <statement> SELECT * from Products order by productName </statement>
            </retrieve>
            <create>
                <statement>INSERT into Products (productCode,productName,productLine,productScale,productVendor,productDescription,quantityInStock,buyPrice,MSRP)
                   VALUES ('{productCode}','{productName}','{productLine}','{productScale}','{productVendor}','{productDescription}',{quantityInStock},{buyPrice},{MSRP})</statement>
            </create>
        </query>      
</dbconnector>

 


The configuration.xml contains all the SQL statements (create, retrieve, update, delete) you need to integrate with your forms. This file uses XML syntax. The key elements are:

...

If you are using the MySQL database, there is a special syntax to insert a conditional null in an insert statement. For Example, let's say your form/flow workflow has an optional date field in a form that is designed to insert a row into the database. The insert will fail because the database connector inserts an empty string where MySQL expects NULL.

...

  1. A Doc URI - this is the simplest way but the Doc URI is only executed when a form is submitted or a flow workflow has completed it’s final step. When the user submits the form or completes the flowworkflow, the URI will be executed with the POST method selected from the dropdown. The database connector will execute the Insert operation identified by the URI.

    Code Block
    http://localhost:8082/database/BIRT/productDetails


  2. A  business rule to pass the data to the database connector post using URL query parameters.  When the user clicks on the Trigger control, this rule will run and the database connector will execute the Insert operation identified by the URL in the productDetails query in the configuration.xml file..

    Code Block
    languagejs
    if (trigger.clicked) {
      var PostURL = 'http://localhost:8082/database/BIRT/productDetails?productCode=' + productCode.value + '&productName=' + productName.value + '&productLine=' + productLine.value + '&productScale=' + productScale.value + '&productVendor=' + productVendor.value + '&productDescription=' + productDescription.value + '&quantityInStock=' + quantityInStock.value + '&buyPrice=' + buyPrice.value + '&MSRP=' + MSRP.value;
      http.post(PostURL);
    } 


  3. A  business rule to create JSON to post/put in the http request. This method is preferred over method 2 because there is a limit to the length of the URL string which will limit the number of form fields you can pass to the Database Connector.

    Code Block
    languagejs
    /*member MSRP, buyPrice, productCode, productDescription, productLine, productName, productScale, productVendor, quantityInStock*/
    
    if (trigger.clicked) {
      var jp = {
        productCode: productCode.value,
        productName: productName.value,
        productLine: productLine.value,
        productScale: productScale.value,
        productVendor: productVendor.value,
        productDescription: productDescription.value,
        quantityInStock: quantityInStock.value,
        buyPrice: buyPrice.value,
        MSRP: MSRP.value,
      };
      http.post('http://localhost:8082/database/BIRT/productDetails', jp);
    } 

    Let’s analyze this rule:

    • The first line of the rule is the member directive required by the Live Forms rule validator
    • Line 2 is a conditional statement to specify that the rule runs when the Trigger control is clicked
    • var jp – defines the JSON payload variable
    • The next 9 lines define the JSON payload – specify the form field values that will be written to the columns in the products table.
    • The last line specifies the http.post operation to the database connector using the JSON payload. When the user clicks on the Trigger control, the database connector will execute the Insert operation identified by the URL in the productDetails query in the configuration.xml file..

...

  • Create a stored procedure to update/insert the values into the database table
  • Call this stored procedure in the <retrieve> tag of your configuration.xml query
  • Use an http.get statement in your business rule to call this query. The stored procedure will execute and update/insert data into your table.

Here is an example of a mySql stored procedure.

...

Code Block
eval ('x=' + http.get('http://localhost:8082/database/BIRT/getOrderNumber'));
onum.value = x.resultSet[0].onum;



Excerpt
hiddentrue

Unique Sequential Id

This example uses a stored procedure, a table in your database, a database connector query and a business rule to generate a unique sequential number when a form loads. This number can populate a ticket or invoice number field in your form.

Step 1 - Create a table in your database (SQL Server):

Code Block
CREATE TABLE dbo.TBLUniqueID
(
UniqueID int IDENTITY(10000,1) PRIMARY KEY,
formuid varchar (255) NOT NULL
)

Step 2 - Create a Stored Procedure (SQL Server):

Code Block
CREATE PROCEDURE dbo.getid
@formid varchar (255)

AS
SET NOCOUNT ON;
INSERT INTO [dbo].[TBLUniqueID] ([formuid]) VALUES (@formid);

SELECT * from [dbo].[TBLUniqueID] WHERE formuid = '@formid';

Step 3 - Add the query to your configuration.xml file

Code Block
<query name="insertformid" autocreate="true">
        <retrieve>
            <statement>EXEC dbo.getid @formid = '{formuid}'</statement>
        </retrieve>

Step 4 - Add this rule to your form

Code Block
/*member, UniqueID, resultSet*/
var x;
var formid;

formid = _data.getParameter('form.id');

if (form.load) {
  formuid.value = formid;
  
  if (formid.length > 0) {
    http.get('http://<your server>:<port>/database/CONTROL4/insertformid?formuid=' + formid);
    eval ("x=" + http.get('http://<your server>:<port>/database/CONTROL4/getformid?formuid=' + formid + '&_mediaType=json'));
    ID.value = x.resultSet[0].UniqueID;
  } 




SQL Server

Here is an example with the syntax required for a SQL server stored procedure:

...

Behind the scenes, the connector actually compares the items in the database with what is submitted in the form. That comparison criteria is based on a key that you define with the attribute deleteKey (required). The deleteKey value is normally the name of the primary key in the table that contains the repeat items.

Dates and Timestamps

Date, Time and DateTime formats are managed automatically by the connector.  You do not need the attributes that define the formats in your querysets. The defaults now match what  sends to the DBConnector and should cover most cases. If you define a date, time or timestamp column in your database, the database connector will know the format of those dates in order to properly parse them. Below is an example of the attribute in the queryset element that is no longer needed.. For instance:

...

  1. Add the enabled= attribute with a value of false to the <querySet/> or individual <query> elements in the configuration.xml file to completely disable it. The first example disables the queryset named BIRT and the second example disables the allCustomer query.

    Code Block
    titleThis example disables the querySet named BIRT
    <dbconnector>
      <queryset name="BIRT" enabled="false" ...>


    Code Block
    languagesql
    titleThis example disables the querynamed allCustomers
    <queryset name="BIRT">
            <query name="allCustomers" autocreate="true" enabled="false" >
                <retrieve>
                    <!-- maps to HTTP GET -->
                    <statement> SELECT customerNumber,customerName from Customers order by customerName </statement>
                </retrieve>
            </query>


  2. The same can be done by adding the enabled property with a value of false as shown below to the dbconnector.properties in the standalone or tomcat bundles.  

    Code Block
    dbconnector.queryset@<queryset name>.enabled=false

    This property disables all querysets. Add it to the dbconnector.properties(standalone bundle) or frevvo-config.properties (tomcat bundle).

    Code Block
    dbconnector.queryset.enabled=false


...

Code Block
<query name="customers"> 
    <retrieve>
        <statement> 
          SELECT * FROM customers WHERE emailAddr='%{domain}%'
        </statement> 
    </retrieve>
</query>

...