A struct is a collection of variables which are referenced under a same name. It provides a means to keep grouped elements which are logically related to one with another.

1 struct

Allows to create a struct.

<struct type='type'>
    <datos /> *
</struct>
Example

Creates a new struct instance previously declared struct type.

Copy
<xsql-script name='struct_sample1'>
    <body>
        <struct.declare type='point2d'>
            <field name='x' type='integer' />
            <field name='y' type='integer' />
        </struct.declare>
        
        <set name='m_point'>
            <struct type='point2d'>
                <number>10</number>
                <number>20</number>
            </struct>
        </set>
        
        <println>X=<m_point.x/></println>
        <println>Y=<m_point.y/></println>
    </body>
</xsql-script>
Example

Online declaration of an empty structure.

Copy
<xsql-script name='struct_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>
        
        <println><m_point/></println>
   </body>
</xsql-script>

A struct composed by 2 empty fields without data is defined.

Example

Null declaration of struct and set in some fields.

Copy
<xsql-script name='struct_sample3'>
    <body>
        <struct.declare type='std_test'>
            <field name='a1' type='string' />
            <field name='a2' type='string' />
            <field name='a3' type='string' />
            <field name='a4' type='string' />
            <field name='a5' type='string' />
        </struct.declare>
        
        <set name='s_test'>
            <struct type='std_test' />
        </set>
        
        <struct.set name='s_test'>
            <field name='a1'>XX</field>
            <field name='a2'>ZZ</field>
        </struct.set>
        
        <println><s_test/></println>
    </body>
</xsql-script>
Example

Declaration of struct and creation of an instance of this type. Use example in SELECT to database.

Copy
<xsql-script name='struct_sample4'>
    <body>
        <struct.declare type='my_table_column'>
            <field name='t' type='string' />
            <field name='c' type='string' />
        </struct.declare>
        
        <set name='m_column'>
            <struct type='my_table_column'>
                <string>cdiarios</string>
                <string>nomdia</string>
            </struct>
        </set>

        <set name='m_col_t'><m_column.t /></set>
        <set name='m_col_c'><m_column.c /></set>
        
        <print.sql>
            <select>
                <columns>
                    ${m_col_t}.${m_col_c} 
                </columns>
                <from table='${m_col_t}' />
            </select>
        </print.sql>
    </body>
</xsql-script>