In XSQL, when an XML file is processed it evaluates its validity and creates a DOM structure. This DOM structure should contain an xSQL script type root node.

 

1 Access to DBStudio Tool

To run examples and become comfortable with the language, the user can use the Axional DBStudio tool.

  • Connect to operating system and select the DBStudio tool.
  • Select a database.

 

2 Main Function Body (Script)

In XSQL, the declaration of a function is included within the tag XSQL-script and the body of the function within the tag body.

Copy
<xsql-script>
    <body>
        <println>Hello world</println>
    </body>
</xsql-script>
Hello world
 

3 Arguments

Arguments are within tag args. An argument is visible in a function through its own tag name.

Copy
<xsql-script>
    <args>
        <arg name='p_name' />
    </args>
    <body>
        <println>Hello world <p_name /></println>
    </body>
</xsql-script>
 

4 Functions

Frequently, for organization and code structure reasons, the content of code can be split up into different subroutines. These can be nested inside the same function, but they must be declared before using.

Copy
<xsql-script>
    <body>
        <function name='f_md5'>
            <args>
                <arg name='p_text' />
            </args>
            <body>
                <return><crypt.digest.md5><p_text /></crypt.digest.md5></return>
            </body>
        </function>
        
        <println>MD5:<f_md5>A text</f_md5></println>
    </body>
</xsql-script>
MD5:352AEC79F1EE5D5DE48EF7B0F14AC4A2

The same function can include other functions.

 

5 Calls to External Scripts

The application contains different scripts that can be used globally by different programs.

  • If files are being used as a program base, script code is declared in a document with a specific name.
  • If dictionaries are being used as a program base, a script entry called (wic_xsql_scripts) will be created.

The tag <call name='script' > is used in the same cases, as the loader which resolves the need to load an XML file with the indicated name or by accessing a wic_xsql_scripts entry.

In order to call the function when we have an f_md5.xml file or equivalent in the database, the following applies:

Copy
<xsql-script>
    <body>
        <println>MD5:<call name='f_md5'>A text</call></println>
    </body>
</xsql-script>
MD5:352AEC79F1EE5D5DE48EF7B0F14AC4A2
   

6 Script Output

Scripts generate standard (stdout) outputs and (stderr) errors to the device predetermined by the person initiating.

  • For scripts initiated from WEB Application, the output is addressed to the server log.
  • For scripts initiated from DBStudio services, SOAP or REST, the output is redirected to memory streams to be returned as an execution result.

    Service scripts

    In this last case, the streams are limited to 1MB, so if the user attempts to issue output above this limit, the program will be interrupted. This measure is a form of protection against badly designed programs or loops causing memory usage that would compromise the system.

 

6.1 Example from DBStudio

If the following script is executed from DBStudio utility, it will be stopped by the interpreter for memory abuse in output streams, producing an exception similar to the one shown in the example.

Copy
<xsql-script>
    <body>
        <while>
            <expr>
                <true />
            </expr>
            <do>
                <println>This produces a lot of messages to stdout</println>
            </do>
        </while>
    </body>
</xsql-script>
Trace: 
<STACKTRACE>
error : java.lang.RuntimeException: exceeded content-length limit of 1048576 bytes
server : 192.168.10.14 (web1)
calltree : <embed>
function : <embed>
date : Thu May 25 07:53:19 CEST 2017
jobid : 301
user : pcc
dbms : demo_rdmaint2
dict : 
tag : println
line : 15
code : 
<do>
<println>this is a long message to stdout</println>
</do>

cause : 
deister.webstudio.core.xsql.script.XSQLScriptException: java.lang.RuntimeException: exceeded content-length limit of 1048576 bytes