You can configure a Compute, Filter, or Database node to select data from database columns and include it in an output message. The following example assumes that you have a database table called USERTABLE with two char(6) data type columns (or equivalent), called Column1 and Column2. The table contains two rows:
Column1 | Column2 | |
---|---|---|
Row 1 | value1 | value2 |
Row 2 | value3 | value4 |
Configure the Compute, Filter, or Database node to identify the database in which you have defined the table. For example, if you’re using the default database (specified on the "data source" property of the node), right-click the node, select Open ESQL, and code the following ESQL statements in the module for this node:
SET OutputRoot = InputRoot; DELETE FIELD OutputRoot.*[<]; SET OutputRoot.XML.Test.Result[] = (SELECT T.Column1, T.Column2 FROM Database.USERTABLE AS T);
This produces the following output message:
<Test> <Result> <Column1>value1</Column1> <Column2>value2</Column2> </Result> <Result> <Column1>value3</Column1> <Column2>value4</Column2> </Result> </Test>
<Test> <Result> <Column1></Column1> <Column2></Column2> </Result> <Result> <Column1></Column1> <Column2></Column2> </Result> </Test>
The exact structure of the XML is not important, but the enclosing tag must be <Test> to match the reference in the ESQL. If it is not, the ESQL statements result in top-level enclosing tags being formed, which is not valid XML.
If you want to create an output message that includes all the columns of all the rows that meet a particular condition, use the SELECT statement with a WHERE clause:
-- Declare and initialize a variable to hold the -- test vaue (in this case the surname Smith) DECLARE CurrentCustomer STRING 'Smith'; -- Loop through table records to extract matching information SET OutputRoot.XML.Invoice[] = (SELECT R FROM Database.USERTABLE AS R WHERE R.Customer.LastName = CurrentCustomer );
The message fields are created in the same order as the columns appear in the table.
If you are familiar with SQL in a database environment, you might expect to code SELECT *. This is not accepted by the broker because you must start all references to columns with a correlation name. This avoids ambiguities with declared variables. Also, if you code SELECT I.*, this is accepted by the broker but the * is interpreted as the first child element, not all elements, as you might expect from other database SQL.
If the database system is case sensitive, you must use an alternative approach. This approach is also necessary if you want to change the name of the generated field to something different:
SET OutputRoot = InputRoot; SET OutputRoot.XML.Test.Result[] = (SELECT T.Column1 AS Column1, T.Column2 AS Column2 FROM Database.USERTABLE AS T);
This example produces the same message as the example above. Ensure that references to the database columns (in this example, T.Column1 and T.Column2) are specified in the correct case to match the database definitions exactly. If you do not do so, for example if you specify T.COLUMN1, the broker generates a runtime error. Note the use of Column1 and Column2 in the SELECT statement. You can use any values here, they do not have to match the names of the columns that you have defined in the database as they do in this example.
Notices |
Trademarks |
Downloads |
Library |
Support |
Feedback
![]() ![]() |
ak05810_ |