Defines a struct.

1 struct.declare

Allows to create a struct.

<struct.declare type='type'>
    <field
        name='name'
        type='type'
    /> *
</struct.declare>

Exceptions

attribute 'name' required

The field name has not been specified.

attribute 'type' required

The data type of the field has not been specified.

attribute 'type' required

The name of the struct has not been specified.

bad arguments for struct [...]

The arguments has not been indicated correctly.

struct [...] already defined

The same struct has been declared at least 2 times.

Example

Define a struct of 2 fields.

Copy
<xsql-script name='struct_declare_sample1'>
    <body>
        <struct.declare type='point2d'>
            <field name='x' type='double' />
            <field name='y' type='double' />
        </struct.declare>
    </body>
</xsql-script>

A struct called 'point2d' and composed by 2 fiels is declared: 'x' of double type and 'y' of the same type. After the execution, the struct has been created but any variable has been declared yet.

Example

Defines and iniciates a struct of 2 fields (declare a variable).

Copy
<xsql-script name='struct_declare_sample2'>
   <body>
       <struct.declare type='point3d'>
           <field name='x' type='integer' />
           <field name='y' type='integer' />
           <field name='z' type='integer' />
       </struct.declare>
       <set name='m_point'>
           <struct type='point3d'>
               <number>2</number>
               <number>4</number>
               <number>6</number>
           </struct>
       </set>
       <println><m_point/></println>
   </body>

</xsql-script>

A struct called 'point3d' and composed by 3 fields is defined. Then, a variable called 'm_point' and of struct type is declared, being this the structure previously defined.

The result by console would be the following:

x=2,y=4,z=6

Example

Automatic declaratiom of a strcut.

Copy
<xsql-script name='struct_declare_sample2'>
    <body>
        <set name='m_point'>
    <struct>
        <struct.declare type='interval'>
            <field name='x' type='double' />
            <field name='y' type='double' />
        </struct.declare>
    </struct>
        </set>
    </body>
</xsql-script>

And later, to add value you can do:

Copy
<set name='m_point.x'>10</set>
    <set name='m_point.y'>20</set>
Example

It is possible to create a struct in base to the output of a select, without requering the declaration of the struct.

Copy
<!-- ====
   CREATE TABLE stock_warehouse
     (
       warehouse       char(4)  not null,
       itemcode        char(16) not null,
       locator         char(10) not null,
       stock           decimal(11,3) not null,
       reserved        decimal(11,3) not null

       , PRIMARY KEY(warehouse, itemcode) CONSTRAINT p_stock_warehouse
     );

   INSERT INTO stock_warehouse VALUES('L001', 'Z000101', 'K001', 24,  0);
   INSERT INTO stock_warehouse VALUES('L001', 'Z000102', 'K011', 33,  2);
   INSERT INTO stock_warehouse VALUES('L001', 'Z000103', 'K012', 40, 12);
    ==== -->

<xsql-script name='struct_select_sample1'>


   <body>
       <select struct='s_stock'>
           <columns>*</columns>
           <from table='stock_warehouse' />
           <where>
               warehouse = 'L001' AND
               itemcode  = 'Z000103'
           </where>
       </select>

       <println><s_stock /></println>
   </body>

</xsql-script>

The print on screen is the following:

struct.s_stock {

Copy
s_stock.warehouse (1 - CHAR java.lang.String) = L001
s_stock.itemcode (1 - CHAR java.lang.String) = Z000103
s_stock.locator (1 - CHAR java.lang.String) = K012
s_stock.stock (3 - DECIMAL java.math.BigDecimal) = 40.000
s_stock.reserved (3 - DECIMAL java.math.BigDecimal) = 12.000

}