The tag execute-procedure allows to perform the call to a procedure compiled and stored in the database. A procedure can have input and output arguments. A producedure does not return any value but it can modify output arguments. The value of the possible output arguments are established in the procedure and are recupered and accessible in XSQL-Script through its name.

1 Cache the PreparedStatement

The execution of a SQL procedure from XSQL_Script is performed using unPreparedStatement, is a Java object which allows to perform the execution of a stored procedure (and other many operations) from the driver JDBC. The tag execute-procedure allows through the attribute prepare-cache (true|false by default true) determines if you should cache it or not the PreparedStatement. By default this PreparedStatement is cached and can be reusable in sucessive calls to the same procedure and only you just have to set the values for the input and output arguments, optimizing the response time because this object is not rebuilt. The PreparedStatement is not cached when:

  • The procedure has not arguments.
  • The prepare cache has been globally disabled.
  • The prepare cache for this call through this attribute has been disabled.

2 Cache a call to a procedure

The tag execute-procedure allows to cache a call to a precedure. This implies that the value of the output arguments, established by the procedure during the execution, are cached and the following calls to this procedure for the same input arguments will obtain the sames values in the output arguments (the cached values). It has the sense that it is considered invariant the procedure inside of the execution block. It should be used when the procedure is considered invariant. The following call to the procedure is performed with cache of result.

Copy
<execute-procedure name='myproc' cache='true'>
    <in>
        <today />
        <arg1 />
    </in>
    <out>
        <var name='a' />
        <var name='b' type='integer' />
        <var name='c' type='decimal' />
        <var name='e' type='date' />
    </out>
</execute-procedure>

If you perform the call with cache of results and the procedure does not have output arguments, an exception is produced:

Copy
unable to cache non returning procedure calls

Execute a compiled procedure SQL in the database. A procedure can have input and output arguments. The value of the possibles output arguments are established in the procedure and are recovered and accessibles in XSQL-Script through its name.

<execute-function
    name='name'
    cache='cache'
    prepared-cache='true|false'
>
    <in> *
        <argument_in /> *
    </in>
    <out> *
        <var
            name='name'
            type='string|boolean|smallint|integer|bigint|float|double|decimal|date|time|timestamp|blob'
        /> *
    </out>
</execute-function>

Exceptions

unsupported type for out: ...

The value established for a output argument is of a type not supported by the system.

unable to cache non returning procedure calls

If the call was performed with results cache and the procedure does not have output arguments.

SQLException ...

Excepciones provoked during the execution of the procedure.

Example

Performs the call to the procedure myproc passing him the current date and an entry argument of the XSQL-Script, and it establishes the value for 4 output arguments which are recuperated and are accessibles through the name.

Copy
<xsql-script name='script_test_proc'>
    <args>
        <arg name='arg1' />
    </args>
    <body>
        <execute-procedure name='myproc'>
            <in>
                <today />
                <arg1 />
            </in>
            <out>
                <var name='a' />
                <var name='b' type='integer' />
                <var name='c' type='decimal' />
                <var name='e' type='date' />
            </out>
        </execute-procedure>
        <println>Value established in the procedure for 'a': <a /></println>
    </body>
</xsql-script>