OpenWGA 7.8 - Query languages reference


table

General


This is a special query type for the "JDBC Database with enhanced access" that can be used to query single database tables. Its advantage over "sql" lies in the fact that the returned database rows are modifiable via WGAPI methods.

Syntax

To execute a table query specify the query type as "table:" plus the name of the table to query. So for querying a table "persons":

<tml:query type="table:persons"/>


You can leave the query tag empty - like in the example above - to let the query return all table rows. But you can also add a WHERE clause to the tag to let it filter out special rows. Just add the WHERE filtering clauses without the WHERE keyword itself. So to query for all rows that contain "Berlin" in a column "city":

<tml:query type="table:persons>city='Berlin'</tml:query>

Query parameters

Query type "table" supports the same query parameter syntax like type "sql" for custom JDBC databases. See there for details.

Examples

The returned rows of a table query are, like stated modifiable via WGAPI methods. The following is a small example of this:

<tml:action id="resetInterest">
var con = this.content();
con.setItemValue("interestRate", 0);
con.save();
</tml:action>

<ul>
<tml:collection>
    <tml:query db="bank" type="table:loans"></tml:query>
    <tml:foreach>
    <li><tml:item name="loanName"/> - <tml:item name="interestRate"/> <tml:button clickaction="resetInterest">Reset interest rate</tml:button></li>
    </tml:foreach>
</tml:collection>
</ul>


This example puts out trivial data about bank loans. Every loan has a column "interestRate". The button "Reset interest rate" should set the rate to 0. As it is defined inside the <tml:foreach> tag it will be executed in the context one individual loan.

The action "resetInterest" called by the button first retrieves the WGAPI content object via method content().  The it uses the method setItemValue() to update the column "interestRate" to a value of 0. Then it calls method save() to store this modification to the database.