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.
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.
In XSQL, the declaration of a function is included within the tag XSQL-script and the body of the function within the tag body.
<xsql-script> <body> <println>Hello world</println> </body> </xsql-script>
Arguments are within tag args. An argument is visible in a function through its own tag name.
<xsql-script> <args> <arg name='p_name' /> </args> <body> <println>Hello world <p_name /></println> </body> </xsql-script>
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.
<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>
The same function can include other functions.
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:
<xsql-script> <body> <println>MD5:<call name='f_md5'>A text</call></println> </body> </xsql-script>
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
REST, the output is redirected to memory streams to be returned as an execution result.
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.
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.
<xsql-script> <body> <while> <expr> <true /> </expr> <do> <println>This produces a lot of messages to stdout</println> </do> </while> </body> </xsql-script>