1 <while> Statements
'While' is used to create iterative statements.
<while>
<expr> !
<cond> !
</expr>
<do> !
<instructions> +
<while.exit /> ?
<while.continue /> ?
</do>
</while>
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Eexpr | |||||
Vcond | boolean | ||||
Edo | |||||
Vinstructions | code | ||||
Ewhile.exit | Causes the output of the loop. | ||||
Ewhile.continue | Jumps to the next iteration of the loop. |
The statement must be composed of a condition (<expr>) and a set of actions to be performed while that condition is met (<do>).
<xsql-script name='while_sample1'> <body> <set name='word'>word</set> <set name='i'>0</set> <set name='a'>0</set> <while> <expr> <lt> <i/> <string.length><word/></string.length> </lt> </expr> <do> <if> <expr> <eq> <string.substring> <word/> <i/> <add><i/>1</add> </string.substring> <string>a</string> </eq> </expr> <then> <set name='a'><add><a/>1</add></set> </then> </if> <set name='i'><add><i/>1</add></set> </do> </while> <println>The word <word/> contains <a/> 'a' vowel.</println> </body> </xsql-script>
The loop makes a tour of the word contained in the 'word' variable, counting the number of times the vowel 'a' appears. On the other hand, the counter variable, i, is smaller (<lt>) than the length (<string.length>) of the word which the 'while' statement is iterating. For each round, the system checks that the letter in question is equal (<eq>) to 'a', in which case the corresponding counter is increased by 1 unit: <set name='a'><add><a/>1</add></set>
2 <for> Statements
'For' is used to create another type of iterative statement.
<for
name='name'
start='start'
end='end'
end-lt='end-lt'
step='step'
>
<do> !
<action> !
<for.exit /> *
</do>
</for>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Aname | string | Name of the counter variable. | |||
Astart | integer | Starting value of the counter variable. | |||
Aend | integer | Final value of the counter variable, including the indicated value. | |||
Aend-lt | integer | Final value of the counter variable, not including the indicated value. | |||
Astep | integer | 1 | Number of units by which the counter is increased in each iteration. The default is 1. |
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Edo | |||||
Vaction | code | ||||
Efor.exit | The for.exit tag is optional, and is generally used under some condition. It causes the output of the iterative statement (exiting the loop), and execution is resumed by the statement that follows the for tag. |
This iterative statement must be used when the number of times a block of statements is executed is known.
-The end and end-lt attributes indicate the final value of the counter. The difference between the two is that end includes the indicated value, and end-lt does not. For example (increasing by 1 unit each time, as is default):
start='0' end='2' --> 3 rounds (0 1 2). start='0' end-lt='2' --> 2 rounds (0 1)
Using the sign '-' in the step attribute specifies that the counter will decrease rather than increase.
<xsql-script name='for_sample1'> <body> <println></println> <!-- i: starts at 6, ends at 0. end: while i >= 0 6 4 2 0 --> <println>Start for A start='6' end='0' step='-2'</println> <println>------------------------------------------</println> <for name='i' start='6' end='0' step='-2'> <do> <println>for A: <i/></println> </do> </for> <!-- i: starts in 6, ends in 0. end-lt: while i > 0 6 4 2 --> <println></println> <println>Start for B start='6' end-lt='0' step='-2'</println> <println>------------------------------------------</println> <for name='i' start='6' end-lt='0' step='-2'> <do> <println>for B: <i/></println> </do> </for> <!-- Here is an example situation where no loop is given because the end condition is not met: while i> = 0 Since it starts at 1, the condition is not fulfilled from the beginning, and the loop is never entered. --> <println></println> <println>Start for C start='1' end='0'</println> <println>------------------------------------------</println> <for name='i' start='1' end='0'> <do> <println>for C: <i/></println> </do> </for> <println></println> </body> </xsql-script>
3 <foreach> sentence
Cursor.
<foreach autocommit='true|false'>
<union prefix='prefix'> ?
<select prefix='prefix'> ?
<select> !
</select>
</union>
<nativesql /> ?
<in prefix='prefix'> ?
<value> !
</in>
<before> ?
<instructions> !
</before>
<before-group of='of'> *
<instructions> !
</before-group>
<after> ?
<instructions> !
</after>
<after-group of='of'> *
<instructions> !
</after-group>
<do> !
<instructions> !
<foreach.exit /> *
<foreach.continue /> *
</do>
</foreach>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Aautocommit | boolean | false | true executes a commit before the cursor, if there is an explicitly open transaction. |
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Eunion | |||||
Aprefix | string | Prefix which refers to the fields of the query. | |||
Eselect | |||||
Aprefix | string | Prefix which refers to the fields of the query. | |||
Vselect | tag_select|native | ||||
Enativesql | Iterative statements in native SQL can be written with this argument. | ||||
Ein | |||||
Aprefix | string | Prefix used to refer to the variables obtained from the argument passed to the function. For example, if a call is made to an <xsqlscript/> which returns a variable called 'canped' with the prefix 'm_', then the name of the variable is 'm_canped'. | |||
Vvalue | vtable|call|soap-sql-response | ||||
Ebefore | This tag is optional. It is used to execute instructions before starting to move the cursor. | ||||
Vinstructions | code | ||||
Ebefore-group | This tag is optional. It is used to execute instructions when the value of the variable indicated in the attribute changes of . The variable belongs to a cursor field. The instructions will be executed before continuing with the block instructions do .There may be a block before_group for each field for which you want to execute instructions when its value changes. | ||||
Aof | string | Indicates the cursor field | |||
Vinstructions | code | ||||
Eafter | This tag is optional. It is used to execute instructions after moving the cursor. | ||||
Vinstructions | code | ||||
Eafter-group | This tag is optional. It is used to execute instructions when the value of the variable indicated in the of attribute changes. The variable belongs to a cursor field. Instructions will be executed after the block of do instructions. There may be a before_group block for each field where the user wants to execute instructions when its value changes. | ||||
Aof | string | Indicates the cursor field. | |||
Vinstructions | code | ||||
Edo | |||||
Vinstructions | code | ||||
Eforeach.exit | The foreach.exit tag is optional, and is generally used under some condition. It causes the output of the iterative statement (exiting the loop), and execution is resumed by the statement that follows the foreach tag. | ||||
Eforeach.continue | This tag is optional, and is generally used under some condition. It causes the cursor to jump to the next record in the loop. |
remarks
The logs that iterate through can be obtained from:
An SQL query (native or XML syntax) that the UNION clause can contain.
Tag in with prefix (optional): Calls to
Tag in with prefix (optional): Virtual tables
Use a foreach to run the result of an SQL query.
<xsql-script name='foreach_code1'> <body> <foreach> <select prefix='clevels_'> <columns>code, name</columns> <from table='clevels' /> </select> <do> <println>CODE: <clevels_code />, NAME: <clevels_name /></println> </do> </foreach> </body> </xsql-script>
Use a foreach to run the result of an SQL query.
<xsql-script name='test_foreach_soapsqlresponse'> <body> <set name='m_soap_sql_response'> <soap.call url='http://localhost:8080/soap/servlet/rpcrouter' uri='urn:SOAPSQLServer' method='executeSQL' user='demo' password='abcdemo' > <parameters> <parameter name='database'>demo_sports1</parameter> <parameter name='sqlstmt'>SELECT * FROM cdiarios</parameter> </parameters> </soap.call> </set> <println> <m_soap_sql_response /> </println> <foreach> <in> <m_soap_sql_response /> </in> <do> <println><code /></println> </do> </foreach> </body> </xsql-script>
<xsql-script name='test_before_group'> <body> <!-- ==================================================================== --> <!-- Virtual table with requested articles, ordered by branch --> <!-- and department. --> <!-- ==================================================================== --> <vtable name='v_art_solic'> <column name="delega" type='string' /> <column name="depart" type='string' /> <column name="codart" type='string' /> <column name="varlog" type='string' /> <column name="cansol" type='decimal' /> </vtable> <vtable.insert name='v_art_solic'> <matrix> { "D01", "P01", "024099", "0", "12" }, { "D01", "P01", "024099", "0", "20" }, { "D01", "P01", "026147", "0", "10" }, { "D01", "P01", "026147", "0", "20" }, { "D01", "P01", "026147", "2", "15" }, { "D01", "P01", "026147", "2", "18" }, { "D02", "0", "024099", "0", "12" }, { "D02", "0", "024099", "0", "20" }, { "D02", "0", "024099", "0", "25" }, { "D02", "0", "024099", "0", "10" }, { "D02", "0", "026147", "0", "10" }, { "D02", "0", "026147", "3", "20" } </matrix> </vtable.insert> <!-- ======================================================================== --> <!-- Virtual table with totals by branch and article --> <!-- ======================================================================== --> <vtable name='v_tot_solic'> <column name="delega" type='string' /> <column name="codart" type='string' /> <column name="cantot" type='decimal' /> </vtable> <!-- ======================================================================== --> <!-- Sums up. When the branch and/or article changes, the accumulated --> <!-- amount is initialized to 0. --> <!-- ======================================================================== --> <foreach> <in prefix='m_'> <v_art_solic /> </in> <before-group of='m_delega'> <set name='m_cantot'>0</set> </before-group> <before-group of='m_codart'> <set name='m_cantot'>0</set> </before-group> <after-group of='m_codart'> <vtable.insert name='v_tot_solic'> <column name='delega'><m_delega /></column> <column name='codart'><m_codart /></column> <column name='cantot'><m_cantot /></column> </vtable.insert> </after-group> <do> <set name='m_cantot'><add><m_cantot /><m_cansol /></add></set> </do> </foreach> <println><v_tot_solic /></println> <!-- +------+------+------------+ |delega|codart|cantot | +------+------+------------+ |D01 |024099| 32,000000| |D01 |026147| 63,000000| |D02 |024099| 67,000000| |D02 |026147| 30,000000| +------+------+------------+ --> </body> </xsql-script>
4 <iterator> Statements
Iterator statements are used to traverse maps, arrays, lists (ArrayList, AbstractList, LinkedList, etc.), sets (AbstractSet, HashSet, LinkedHashSet, TreeSet), object arrays, or iterators.
<iterator
name='name'
type='key|entry'
index='index'
>
<in> !
<value> !
</in>
<do> !
<instructions> !
<iterator.exit /> *
<iterator.continue /> *
</do>
</iterator>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Aname | string | Name of the counter variable. | |||
Atype | string | key | key is used as default that the counter variable contains the keys, entry to contain the values. | ||
Aindex | string | Name of the variable which will contain, in each iteration, the index of the current element. |
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Ein | The input can be a map or an array . | ||||
Vvalue | list|map|set|iterator | ||||
Edo | |||||
Vinstructions | code | ||||
Eiterator.exit | This tag is optional, and is generally used under some condition. It causes the output of the iterative statement (exiting the loop), and execution is resumed by the statement that follows the iterator tag. | ||||
Eiterator.continue | This tag is optional, and is generally used under some condition. It exits the current iteration and resumes the loop for the next iteration cursor record. |
This example traverses a string array.
<xsql-script name='test_iterator'> <body> <array name = 'm_provinces'> <string>madrid</string> <string>barcelona</string> <string>granada</string> <string>sevilla</string> <string>burgos</string> <string>pontevedra</string> </array> <iterator name = 'm_provinc'> <in> <m_provinces/> </in> <do> <println><m_provinc/></println> </do> </iterator> </body> </xsql-script>