...
The examples shows a loop that repeats 10 times (i=0 until i<10) and executes the "#RUNQUERY SELECT ..." accordingly ten times. Furthermore, the counter "i" is used within the query, so that each ${i} is replaced by the current value of i from the loop.
Code Block |
---|
language | cql |
---|
theme | Eclipse |
---|
language | cql |
---|
linenumbers | true |
---|
|
#LOOP i 0 UPTO 10
#RUNQUERY
SELECT ${i} AS b, * FROM bid
#ENDLOOP |
You may also use ${i-1} or ${i+1} (only this two!). For example, this
Code Block |
---|
language | cql |
---|
theme | Eclipse |
---|
language | cql |
---|
linenumbers | true |
---|
|
#LOOP i 2 UPTO 4
#RUNQUERY
SELECT ${i-1} AS a, ${i+1} AS b, * FROM bid WHERE b>${i}
#ENDLOOP
|
is equal to
Code Block |
---|
language | cql |
---|
theme | Eclipse | language | cql |
---|
linenumbers | true |
---|
|
#RUNQUERY
SELECT 1 AS b, * FROM bid3 WHERE b>2
#RUNQUERY
SELECT 2 AS b, * FROM bid4 WHERE b>3
|
You may also use an additional offset variable. This offset variable adds a defined value to the current value of the actual loop variable. Following example uses an offset of x = 5:
Code Block |
---|
language | cql |
---|
theme | Eclipse | language | cql |
---|
linenumbers | true |
---|
|
#RUNQUERY
#LOOP i 2 UPTO 5 WITH x 5
SELECT ${x} AS b, * FROM bid
#ENDLOOP |
This is equal to:
Code Block |
---|
language | cql |
---|
theme | Eclipse | language | cql |
---|
linenumbers | true |
---|
|
#RUNQUERY
SELECT 7 AS b, * FROM bid
SELECT 8 AS b, * FROM bid
SELECT 9 AS b, * FROM bid
|
#FOREACH_IN
You can also define a foreach loop, e.g., as follows:
Code Block |
---|
language | cql |
---|
theme | Eclipse |
---|
linenumbers | true |
---|
|
#LOOP x FOREACH_IN 1,2,...,9,10,20,...,60,90,120
/// Some content
#ENDLOOP
|
#IFDEF/#IFNDEF
With #IFDEF it is possible to check whether a variable exists and was set by #DEFINE or not. This is useful, for example, to run certain queries corresponding to the current setting. Use #IFNDEF for case where to check if a variable has no value
...
The example defines a variable called latencyOn and uses the #IFDEF command to use either StandardLatency for the transformation configuration, if latencyOn is set or Standard if it is not set. Obviously, this example uses allways the <then-command>-part (since latencyOn is set), so you may switch to another transformation config by simply commenting the #DEFINE command out so that the <else-commands> are used.
Code Block |
---|
language | javascript |
---|
theme | Eclipse |
---|
language | javascript |
---|
linenumbers | true |
---|
|
#DEFINE latencyOn
....
#IFDEF latencyOn
#TRANSCFG StandardLatency
#ELSE
#TRANSCFG Standard
#ENDIF |
...
Code Block |
---|
#IFSRCNDEF basestream
#INCLUDE ${WORKSPACEPROJECT/}Source.qry
#ENDIF |
#IFQDEF/#IFQNDEF
Similar to #IFDEF but checking if a query with the given name is registered in the executor (see command QNAME) . This can be helpful to define queries only if they are not already defined
Code Block |
---|
#IFQNDEF myQuery
#QNAME myQuery
#RUNQUERY
<query text>
#ENDIF |
#IF
Similar to #IFDEF and #IFSRCDEF but checking an arbitrary expression. This can be helpful to execute a block only if the expression evaluates to true.
Code Block |
---|
#IF toInteger(CPU) > 1
#RUNQUERY
...
#ENDIF
...
#DEFINE a_string FOO
#IF a_string == "FOO"
...
#ENDIF |
#LOOP radius FOREACH_IN 5000,10000