1 grid.result.hasData

Release 2017.3

Tag available since version 2017.3.

Returns a boolean to indicate if last select executed on the grid contains data.

<grid.result.hasData>
    <resultSet /> !
</grid.result.hasData>
It is necessary to check if the grid has data before starts to go forward on the resultset. If you try to show data from an empty grid an exception occurs
Copy
XSQLScriptException[java.sql.SQLException: resultset is closed.]
Example
Copy
<xsql-script>
    <body>
        <connection name='sysmaster1'>
            <set name='rs'>
                <!-- Run a multi database query, returning a memory result set. -->
                <!-- Each db has it's pool configuration timeout but can be owerride via timeout !=0 -->

                <select.grid name='grid_demo' timeout='30'>
                    <columns>tabname, nrows, npused</columns>
                    <from table='systables' />
                    <where>tabname LIKE 'capuntes%'</where>
                </select.grid>
            </set>
        </connection>

        <if>
            <expr><grid.result.hasData><rs/></grid.result.hasData></expr>
            <then>
                <println>... The grid contains data:</println>
                <println>
                    <rs/>
                </println>
            </then>
            <else>
                <println>... The grid is empty.</println>
            </else>
        </if>
        
    </body>
</xsql-script>
... The grid contains data:
+--------+-----------+----------+--------------+----------+
|tabname |nrows      |npused    |grid_node     |grid_error|
|varchar |float      |float     |char          |char      |
|visible |visible    |visible   |visible       |visible   |
+--------+-----------+----------+--------------+----------+
|capuntes|   7887,000|  1604,000|demo_sports   |          |
|capuntes| 442028,000| 89265,000|demo_industria|          |
|capuntes|4557441,000|955229,000|demo_cons     |          |
+--------+-----------+----------+--------------+----------+
Example
Copy
<xsql-script>
    <body>
        <connection name='sysmaster1'>
            <set name='rs'>
                <!-- Run a multi database query, returning a memory result set. -->
                <!-- Each db has it's pool configuration timeout but can be owerride via timeout !=0 -->

                <select.grid name='grid_demo' timeout='30'>
                    <columns>tabname, nrows, npused</columns>
                    <from table='non_existent_table' />
                    <where>tabname LIKE 'capuntes%'</where>
                </select.grid>
            </set>
        </connection>

        <if>
            <expr><grid.result.hasData><rs/></grid.result.hasData></expr>
            <then>
                <println>... The grid contains data:</println>
                <println>
                    <rs/>
                </println>
            </then>
            <else>
                <println>... The grid is empty.</println>
            </else>
        </if>
        
    </body>
</xsql-script>
... The grid is empty.