<data>

Set a variable to a table value containing the data from executing a query.

Description

<data> sets [VARIABLE] directly to a table value containing the data which results from executing [QUERYVALUE].

This operation is for small result sets that can be practically materialized into memory as a whole, especially if they will be indexed into extensively in subsequent block code.

Syntax

<data name="[VARIABLE]" query="[QUERYVALUE]"/>

This is equivalent to the following syntax using the <set> tag:

<set variable="{@queryvalue._data}"/>

In order to define a queryvalue which is the required argument of either of these methods, the following syntax may be used:

<query name="queryvalue">
    <base table="[BASE_TABLE]"/>
    [MACRO_LANGUAGE_OPERATIONS]
</query>

The <data> tag has _rows, _cols, and _column properties. <query> may be indexed to return a scalar either as @queryvalue.column.row or @queryvalue.row.column, or it may be partially indexed to return a package with @queryvalue.row or a list with @queryvalue.column. @queryvalue._rows returns the number of rows and @queryvalue._cols returns a list of column names. @queryvalue._column.[COLUMN] returns a package of metadata for the specified column.

Alternate Syntax

This syntax is the extended form of <data>.

<data name="[VARIABLE]">
    [QUERY]
</data>

Attributes

name
The destination where the query value is stored.
query
The query to execute, which results in the table of data to be assigned to name. (This attribute is optional if using the alternate syntax above.)

Example

This example illustrates how to build a data object from a queryvalue which is previously defined. The resulting object is then passed to the <table/> operation. Note that the query has already been computed when it is passed to <table/>.

<block>
  <query name="queryvalue">
    <base table="pub.demo.retail.item"/>
    <sel value="transid=532"/>
  </query>
  <data name="mydata" query="{@queryvalue}"/>
  <table name="foo" data="{@mydata}"/>
</block>
Example of <data> tag based off of a queryvalue, then used as the basis for a <table>

Alternate Syntax Example

This example illustrates how to enclose a query between an opening and closing <data> tag.

<block>
  <data name="uploads">
    <base table="pub.demo.retail.item"/>
    <sel value="transid=532"/>
  </data>
  <willbe name="test" value="{@uploads.1}"/>
</block>
Data - Alternate Example Image

Example: Using <data> to display query column and row data

In the following example, col_lst contains @sales_data._cols, or a list of column names in the query result, and total _rows contains @sales_data._rows, or the number of rows in the query result.

<data name="sales_data">
<base table="pub.demo.retail.item"/>
<sel value="i_()<11"/>
<colord cols="transid,store,sales"/>
</data>

<willbe name="col_lst" value="{@sales_data._cols}"/>
<willbe name="total_rows" value="{@sales_data._rows}"/>
<colord hide="c1"/>